Jump to content
  • Advertisement
Sign in to follow this  
2square

DX11 Sampling a texture in a domain shader [Cg]

This topic is 1831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
 
This question pertains specifically to using NVidia Cg with DX11.
 
I'm trying to write a simple terrain tesselation shader that tesselates a quad patch and applies a heightmap in the domain shader for vertex displacent. I'm passing in the heightmap as a 2D texture and using the following line to sample the texture.
 
pos.z = tex2D(heightmapTexture, texUV).r;

 

But this doesn't compile and I get the following error.

 

error C1115: unable to find compatible overloaded function "Sample(sampler2D, float2)"
Is this the correct syntax for sampling a texture in the domain shader, or is this not currently supported?
 
Thanks.

Share this post


Link to post
Share on other sites
Advertisement

I don't really know Cg, but if tex2D is equivalent to what it was in older HLSL then you can't use it anything except for a pixel shader. This is because it uses screen-space gradients to automatically select the mip level, and gradients can only be computed in a pixel shader. Try using tex2Dlod, or whatever the Cg equivalent is for a function that lets you manually specify the mip level.

Share this post


Link to post
Share on other sites

This is because it uses screen-space gradients to automatically select the mip level, and gradients can only be computed in a pixel shader. Try using tex2Dlod

 

Interesting. I knew you couldn't use tex2D in all the stages but didn't know the reason why. I believe I already tried tex2Dlod, but I'll give it another shot. 

 

Thanks for replying.

Share this post


Link to post
Share on other sites

Hmm.. at first I thought that using tex2Dlod worked, but now I get this compile error instead.

 

error C1115: unable to find compatible overloaded function "SampleLevel(sampler2D, float2, float)"
Edited by 2square

Share this post


Link to post
Share on other sites

It seems that for tex2Dlod, you'd have to use float4 for 'texUV' //=================================================================== sampler2D samp; float4 tex2Dlod(sampler2D samp, float4 s)// s.w selects the mipmap level //=================================================================== http://http.developer.nvidia.com/Cg/tex2Dlod.html //=================================================================== And it says at the bottom that your GPU must support the vp40 profile. If you have a decent video card this should not be a problem. I suspect a lot of laptops might not support this.

Share this post


Link to post
Share on other sites

Yes, I did use a float2 when using tex2D and a float4 when using tex2Dlod. My graphics card is a AMD 7970. I also tried it on a GTX 480. Still no luck. 

 

Sorry for the delayed response, I was away for sometime.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!