• Advertisement
Sign in to follow this  

heightmap sample in vertex shader

This topic is 757 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

It's strange. I have 

 

 
vout.PosW.y = gHeightMap.SampleLevel( samHeightmap, float3(x,z,0.0f), 0 ).r;

height map is 4096x4096 grayscale image.

What numbers should be in x,z-range?

I try with 

PosW.x/4096

PosW.z/4096

 

when posw <4096 and posw>0  I always get same result, posw is random number. I tried test with vertexID and InstanceID, no matter what I write to  x,z I always have same result.  I tried with other textures but without any effect.

Edited by widmowyfox

Share this post


Link to post
Share on other sites
Advertisement

They should be in the range [0, 1].

 

Be sure you're sampling from the center of the texel (especially important for unfiltered texture reads like in a vertex shader). If you're sampling from the border between pixels, you may get any of the 4 neighboring values (not exactly "random", but it might look like it).

 

What does your grayscale image look like?

What does your rendered grid look like?

Edited by phil_t

Share this post


Link to post
Share on other sites

But when i do this for exemple:

vout.PosW.y = gHeightMap.SampleLevel( samHeightmap, float3(vin.InstanceId/100,vin.InstanceId/100,0.0f), 0 ).r;

I still have same result, it is impossible coz  InstanceId. Any suggestions?

 

Edit:

 

I do this

if(vin.VertexId==1)
vout.PosW.y = gHeightMap.SampleLevel( samHeightmap, float3(0.2f,0.2f,0.0f), 0 ).r;
else if(vin.VertexId==2)

vout.PosW.y = gHeightMap.SampleLevel( samHeightmap, float3(0.7f,0.7f,0.0f), 0 ).r;

Same result on VertexId 1 and 2, always 0 at output

Edited by widmowyfox

Share this post


Link to post
Share on other sites

Here's a snippet of a shader I used for something, it calculates UV=(0,0)-(1,1) based on SV_VertexID, and the amount of vertices it expects is cDimensionsI.x * cDimensionsI.y (cDimensionsF is the same values, expressed as floats):

Note the % and /, and the casting to floats etc.:

// Input declaration
struct VS_INPUT
{
	uint VertexID : SV_VertexID;
};

// Const buffer
cbuffer GlobalData : register(b0)
{
	uint4 cDimensionsI;
        float4 cDimensionsF;
};

// In main shader:

float2 uv = float2(float(In.VertexID % cDimensionsI.x) / cDimensionsF.x, float(In.VertexID / cDimensionsI.x) / cDimensionsF.y);

Share this post


Link to post
Share on other sites

Sounds like your texture isn't correctly loaded or bound, and your SampleLevel always returns 0.

0 is the default that will be returned if no texture is available to read from.

If you run your game from Visual Studio with the debugger and create your device with D3D11_CREATE_DEVICE_DEBUG you should get debug output in the Output window in Visual Studio if that is the case.

Share this post


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

  • Advertisement