Original Post
Hi I'm doing some investigation into vertex texture fetching and I have an issue I don't seem to be able to solve. I have created a 512x512 vertex texture using this: I then lock it and fill it with data from a bitmap I've loaded. I won't post that code for brevity, but when I inspect the (float*) pBits, I see what I'd expect. For my simple demo, I have a 512x512 texture with one white pixel in each corner, so my pBits for the vertex texture looks like: imageData[0] = 255, imageData[1] -> [510] = 0, imageData[511] = 255, and so on. In my shader, I set up the sampler like this: and I'm using it in the vertex shader like this (after setting g_displacementMap to my vertex texture in the code): I know Position.x and Position.z are correct as the grid renders correctly. Every height I get back from the tex2Dlod function is 255. The reason I know Position.x and Position.z (my vertex shader inputs) are correct is because I can do this: ..which gives me a flat grid but with the height of grid point (vertex) 4,4 at zero and the rest at 255. Any ideas? I feel like I've tried everything. Edit: I'm using Dx9.0c Thanks
D3DXCreateTexture(<myDevice>, 512, 512, 1, D3DUSAGE_DYNAMIC, D3DFMT_R32F, D3DPOOL_DEFAULT, &m_vertexTexture);
sampler DisplacementMap =
sampler_state
{
Texture = <g_displacementMap>;
MipFilter = POINT;
MinFilter = POINT;
MagFilter = NONE;
};
float height = tex2Dlod(DisplacementMap, float4(Position.x, Position.z, 0.0f, 0.0f)).x;
if (Position.x == 4 && Position.z == 4)
height = 0.0f;