Wrong vertex displacement direction

Started by
5 comments, last by ja0335 10 years, 9 months ago

Hi

I am implementing displacement over a tessellated surface, but the result is strange because the position of the vectors is tending to go up. Is that normal? i think the new position must follow the normal map.

THis is my code:

float offset = g_DisplacementTxt.SampleLevel(g_samLinear, Out.texCoord, 0).x;

float4 txtNormal = g_NormalTxt.SampleLevel( g_samLinear, Out.texCoord, 0 ) * 2 -1;

position = position + (txtNormal * offset);

WrongDisplacement+direction.png

Juan Camilo Acosta Arango

Bogotá, Colombia

Advertisement

The vertices should be displaced in the normal direction.

Are you transforming the normal to world-space?

I am only sampling the normal texture and then 2 * -1 to get the world normal

float4 txtNormal = g_NormalTxt.SampleLevel( g_samLinear, Out.texCoord, 0 ) * 2 -1;

Juan Camilo Acosta Arango

Bogotá, Colombia

Tiago is asking if your normal map contains world-space normals, since typically they contain tangent-space normals that have to be transformed to world-space before you can use them.

Yes, when i made the map i set it to be world space normals

Juan Camilo Acosta Arango

Bogotá, Colombia

Yes, when i made the map i set it to be world space normals

Don't you mean object space normals?

If they're indeed object space normals, and position is in world space you have to transform the normals to world space using the world space matrix.

I have found another clue, i duplicated the geometry and place in positions different from the origin and these is the result i get....

wrong+disp.png

I think is some one related to the vertex position space but not sure.

Juan Camilo Acosta Arango

Bogotá, Colombia

This topic is closed to new replies.

Advertisement