Followers 0

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

## 6 posts in this topic

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.
0

##### Share on other sites

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.

2

##### 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.

0

##### 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
0

##### Share on other sites

Have you confirmed that 'texUV' is a float2.

1

##### 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.

1

##### 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.

0

## Create an account

Register a new account

Followers 0

• ### Similar Content

• By YixunLiu
Hi,
I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
Anybody know a fast method to calculate the intersected boundary of these two geometries?

Thanks.

YL

• By hiya83
Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
Thanks!

• Hi Guys,
I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
Any advice would be greatly appreciated

• bool InitDirect3D::Init() { if (!D3DApp::Init()) { return false; } //Additional Initialization //Disable Alt+Enter Fullscreen Toggle shortkey IDXGIFactory* factory; CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory)); factory->MakeWindowAssociation(mhWindow, DXGI_MWA_NO_WINDOW_CHANGES); factory->Release(); return true; }
As stated on the title and displayed on the code above, regardless of it Alt+Enter still takes effect...
I recall something from the book during the swapChain creation, where in order to create it one has to use the same factory used to create the ID3D11Device, therefore I tested and indeed using that same factory indeed it work.
How is that one particular factory related to my window and how come the MakeWindowAssociation won't take effect with a newly created factory?
Also what's even the point of being able to create this Factories if they won't work,?(except from that one associated with the ID3D11Device)
• By ProfL
Can anyone recommend a wrapper for Direct3D 11 that is similarly simple to use as SFML? I don't need all the image formats etc. BUT I want a simple way to open a window, allocate a texture, buffer, shader.

• 12
• 28
• 14
• 11
• 34