0
\$\begingroup\$

Dears, I was trying to implement the terrain tutorial in Introduction to game programming by frank luna. I succeeded to implement it using the effect file. When I try to separate the Vertex, hull, domain and pixel shaders, i got a very strange behavior in the terrain textures. After debugging I got that the problem is in calculating the UV texture coordinates in the domain shader. Here is how I calculate the UV coordinates.

[domain("quad")]    
DomainOut main(PatchTess patchTess,
float2 uv : SV_DomainLocation,
const OutputPatch<HullOut, 4> quad)
{
DomainOut dout;

// Bilinear interpolation.
dout.PosW = lerp(
    lerp(quad[0].PosW, quad[1].PosW, uv.x),
    lerp(quad[2].PosW, quad[3].PosW, uv.x),
    uv.y);

dout.Tex = lerp(
    lerp(quad[0].Tex, quad[1].Tex, uv.x),
    lerp(quad[2].Tex, quad[3].Tex, uv.x),
    uv.y);

// Tile layer textures over terrain.
dout.TiledTex = dout.Tex * 50.0f;

dout.TiledTex = dout.Tex*50.0f;

// Displacement mapping
dout.PosW.y = gHeightMap.SampleLevel(samHeightmap, dout.Tex, 0).r;

// NOTE: We tried computing the normal in the shader using finite difference, 
// but the vertices move continuously with fractional_even which creates
// noticable light shimmering artifacts as the normal changes.  Therefore,
// we moved the calculation to the pixel shader.  

// Project to homogeneous clip space.
dout.PosH = mul(float4(dout.PosW, 1.0f), gViewProj);

return dout;
}

I am using quads for the domain shader. After debugging using graphics analyzer, I got that in the domain shader the data is different from effect file from the domain shader I implemented altough the same code is used in both files.

What can be the problem?

This is the image of my implementation

This is the original image

Thanks in advance.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.