• Create Account

## Sampling a texture in a domain shader [Cg]

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #12square  Members

Posted 30 May 2013 - 10:28 AM

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.

### #2MJP  Moderators

Posted 30 May 2013 - 12:49 PM

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.

### #32square  Members

Posted 31 May 2013 - 03:40 PM

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.

### #42square  Members

Posted 03 June 2013 - 03:56 PM

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, 03 June 2013 - 04:03 PM.

### #5marcClintDion  Members

Posted 04 June 2013 - 01:09 PM

Have you confirmed that 'texUV' is a float2.

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

### #6marcClintDion  Members

Posted 04 June 2013 - 01:31 PM

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, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.

### #72square  Members

Posted 17 June 2013 - 12:53 PM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.