• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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.

5 replies to this topic

### #1montify  Members

Posted 20 November 2012 - 03:28 PM

Hello

Anyone can tell me how i get the Heightmap from VertexShader?
Note: I normalize the Cube to get a Sphere (Planet)

float4x4 World;
float4x4 View;
float4x4 Projection;
float4 color;
float seaLevel;
texture myTexture;
float maxHeight = 128;
float height;

sampler2D mySampler = sampler_state
{
Texture = <myTexture>;
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
};

{
float4 Position : POSITION0;
};

{
float4 Position : POSITION0;
};
{
float4 worldPosition = mul(input.Position, World);
float height = tex2Dlod(mySampler, float4(12,32,0 ,0));
worldPosition.z += height;
worldPosition = float4(normalize(worldPosition.xyz) * seaLevel, 1);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);
return output;
}

{
return color;
}
technique Technique1
{
pass Pass1
{

}
}


This is all i have, but the the result is nothing :/

best regards, alex

### #2Seabolt  Members

Posted 20 November 2012 - 03:48 PM

I haven't used tex2Dlod(), but from the MSDN page, it looks like x and y in your texcoord should be a standard UV texcoord, so most likely 0..1 normalized. And since your addressing is set to CLAMP, it will just grab the edges which may be flat? Try playing with those a bit.

Also I'd use PIX and see if the texture is actually bound and, more importantly, has valid data in it.

Good luck!
Perception is when one imagination clashes with another

### #3montify  Members

Posted 21 November 2012 - 04:10 AM

Hello

float4x4 World;
float4x4 View;
float4x4 Projection;
float axis;

float4 color;
float seaLevel;
float height;
texture myTexture;

sampler2D mySampler = sampler_state
{
Texture = <myTexture>;
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
};

{
float4 Position : POSITION0;
float4 uv : TEXCOORD0;
};

{
float4 Position : POSITION0;
float4 uv : TEXCOORD0;
};

{
float4 worldPosition = mul(input.Position, World);
float axis;
float2 planetUV;

//---------------AXIS--------------
if(axis == 0) //left
{
planetUV = (worldPosition.zy + 1) * 0.5;
planetUV.y = 1 - planetUV.y;
}
else if(axis == 1) //right
{
planetUV = (worldPosition.zy + 1) * 0.5;
planetUV = 1 - ((worldPosition.zy + 1) * 0.5);
}
else if(axis == 2) //top
{
planetUV = (worldPosition.zy + 1) * 0.5;
planetUV = (worldPosition.xz + 1) * 0.5;
}
else if(axis == 3) //bottom
{
planetUV = (worldPosition.xz + 1) * 0.5;
planetUV.y = 1 - planetUV.y;
}
else if(axis == 4) //front
{
planetUV = (worldPosition.xy + 1) * 0.5;
planetUV.y = 1 - planetUV.y;
}
else if(axis == 5) //back
planetUV = (worldPosition.zy + 1) * 0.5;
planetUV = 1 - (worldPosition.xy + 1) * 0.5;
//---------------AXIS END--------------

float3 heightCol = tex2Dlod( mySampler, float4(input.uv.xy, 0, 0) );

worldPosition= mul(float4(input.Position.x, 0, input.Position.z, 1) *seaLevel, World);
worldPosition.y = heightCol * planetUV.y;
worldPosition = float4(normalize(worldPosition.xyz) * seaLevel, 1);

float4 viewPosition = mul(worldPosition, View);

output.Position = mul(viewPosition, Projection);
output.uv = input.uv;

return output;
}

{
return color;
}

technique Technique1
{
pass Pass1
{

}
}


But here is my new Error:
The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing

Anyone can tell me what i'm doing wrong?

Edited by montify, 21 November 2012 - 04:38 AM.

### #4Nik02  Members

Posted 21 November 2012 - 07:36 AM

The symbol "TextureCoordinate0" is not in the code you posted. Are you sure that this shader actually gets compiled and set as the active shader? Furthermore, are you sure that you want to use float4 for the uv coordinate input and output? The logic in the code suggests that you only make use of the xy part (which fits in a float2), and even without trying to compile the code I can guess that this would cause compilation errors as well.

The actual error is just as it says on the tin: the vertex declaration (which you establish in the host program, and which describes your vertex buffer format to the hardware) has to contain all the elements that the vertex shader expects to find in the input streams.

The error can be caused by the fact that an another shader is bound instead of the one you expect to be bound; this, in turn, can indirectly be caused by a failure to compile and set the expected shader.

Niko Suni

### #5phil_t  Members

Posted 22 November 2012 - 03:20 AM

Sounds like this is XNA, which has pretty good error checking. TextureCoordinate0 is just referring to the TEXCOORD0 semantic.

So the problem is that the vertices you're drawing with your effect do not contain TEXCOORD0. What is the vertex format you're using? What does your draw call look like?

### #6xexuxjy  Members

Posted 22 November 2012 - 08:04 AM

Sounds like your vertex declaration is probably only using something like a Vector2 , which if you've got a regular grid should really be all you need along with a texelwidth to calculate the uv for the heightmap?
I've got a sample terrain object doing a shader heightmap at :