Sampling a texture in a domain shader [Cg]

Started by
5 comments, last by 2square 10 years, 10 months ago
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.
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.

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.

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)"

Have you confirmed that 'texUV' is a float2.

Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, 3 because you know that the testing of your faith produces perseverance. 4 Let perseverance finish its work so that you may be mature and complete, not lacking anything.

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.

Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, 3 because you know that the testing of your faith produces perseverance. 4 Let perseverance finish its work so that you may be mature and complete, not lacking anything.

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.

This topic is closed to new replies.

Advertisement