DX11 - Terrain Tessellation repeating

Started by
20 comments, last by Migi0027 10 years, 8 months ago

This is the output in Pix with the geometry shader:

2u6e0ep.png

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement

The texture visualization:

r7q2kx.png

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Well, that white grid was confusing from the start. There should be no white at all, so I assume this is a different draw call (and shader). I don't see that grid in PIX either.

For the tesselated one: I miss the red color. And the displacement should go in one direction only (normal is always the same). How does the PreVS tab look ?

Whoops! That white grid is a whole other thing, just ignore that... biggrin.png

PreVS tab:

2gtuhb6.png

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Looks fine.

Hmmm, if I try to compile that shader using an effect I get A LOT of warnings about missing output values. The compilation even fails since there are these inconsistencies between shader stages (e.g. your domain shader outputs DOut, your pixelshader wants VOut).

I'm surprised that something gets drawn at all. Don't you get any warnings from the debug layer ?

Anyway, remove those compiler warnings and make sure the input-output signatures match.

What warnings do you get when you compile it?

I think the signatures are better now:


cbuffer ConstantObjectBuffer : register (b0)
{
	matrix worldMatrix;
};

cbuffer ConstantFrameBuffer : register (b1)
{
	matrix viewMatrix;
	matrix projectionMatrix;

	float3 eyepos;
	float cppad;

	float4 lightvec;
	float4 lightcol;

	float FogStart;
	float FogEnd;
	float2 __space;

	float3 FogColor;
	float shadows;

	float SpecularIntensity;
	float3 pad3;
	float4 SpecularColor;
}


//***************************************************//
//                 VERTEX SHADER                     //
//***************************************************//

struct VOut
{
    float4 position : POSITION;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;

	float tessAmount : TSSAM;
	
	float3 NormalW : NORMWORLD;
	float3 normal : NORM;
	float4 depthPosition : TEXTURE0;
};

struct GlobalIn
{
	float4 position : POSITION;
	float4 normal : NORMAL;
	float2 texcoord : TEXCOORD;
};

Texture2D t_map : register(t0);
SamplerState ss;

VOut VShader(GlobalIn input)
{
    VOut output;

    input.position.w = 1.0f;
	output.texcoord = input.texcoord;

	// Calculate the position of the vertex against the world, view, and projection matrices.
    /*output.position = mul(input.position, worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);*/

	output.position = mul(input.position, viewMatrix);

	// Get Tesselation amount
	output.tessAmount = (1.0f / output.position.z) * 6.0f;

	output.position = input.position;

    output.NormalW = mul(float4(input.normal.xyz,0), mul(worldMatrix, viewMatrix));

	// Store the position value in a second input value for depth value calculations.
	output.depthPosition.xyz = mul(float4(input.position.xyz,1), mul(worldMatrix, viewMatrix)).xyz;

	// Per Vertex lighting
	float4 norm = normalize(input.normal);
	output.access = saturate(dot(norm, lightvec));

	output.normal = input.normal;
	
    return output;
}

//***************************************************//
//                 HULL SHADER                       //
//***************************************************//

struct HOutput
{
    float edges[3] : SV_TessFactor;
    float inside : SV_InsideTessFactor;
};

HOutput ColorPatchConstantFunction(InputPatch<VOut, 3> inputPatch, uint patchId : SV_PrimitiveID)
{    
    HOutput output;

	float tA = inputPatch[0].tessAmount;
	tA = 36.0f;

    // Set the tessellation factors for the three edges of the triangle.
    output.edges[0] = tA;
    output.edges[1] = tA;
    output.edges[2] = tA;

    // Set the tessellation factor for tessallating inside the triangle.
    output.inside = tA;

    return output;
}

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("ColorPatchConstantFunction")]

VOut HShader(InputPatch<VOut, 3> patch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)
{
    VOut output;

    // Set the x for this control point as the output x.
    output.position = patch[pointId].position;

    output.texcoord = patch[pointId].texcoord;
    output.access = patch[pointId].access;
    output.NormalW = patch[pointId].NormalW;
    output.normal = patch[pointId].normal;
    output.depthPosition = patch[pointId].depthPosition;

    return output;
}

//***************************************************//
//                 DOMAIN SHADER                     //
//***************************************************//

struct DOut
{
    float4 position : SV_Position;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;
	
	float3 NormalW : NORMWORLD;
	float4 depthPosition : TEXTURE0;
};

[domain("tri")]

DOut DShader(HOutput input, float3 uvwCoord : SV_DomainLocation, const OutputPatch<VOut, 3> patch)
{
    DOut output;

	float3 vertexPosition;
    float2 texCoords;
    float3 normal;
    float4 worldPosition;

	vertexPosition = uvwCoord.x * patch[0].position + uvwCoord.y * patch[1].position + uvwCoord.z * patch[2].position;

    texCoords = uvwCoord.x * patch[0].texcoord + uvwCoord.y * patch[1].texcoord + uvwCoord.z * patch[2].texcoord;

    normal =  uvwCoord.x * float3(0, 1, 0) + uvwCoord.y * float3(0, 1, 0) + uvwCoord.z * float3(0, 1, 0);
    normal = normalize(normal);

    float vHeight = t_map.SampleLevel(ss, texCoords, 0);
    vertexPosition += float3(0, 1, 0) * (vHeight * 2.0f);

    output.position = mul(float4(vertexPosition, 1.0f), worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    output.texcoord = texCoords;

    output.NormalW = mul(normal,(float3x3)worldMatrix);
    output.NormalW = normalize(output.NormalW);

    return output;
}

//***************************************************//
//                 PIXEL SHADER                      //
//***************************************************//

[maxvertexcount(3)]   // produce a maximum of 3 output vertices
void GShader( triangle DOut input[3], inout TriangleStream<DOut> triStream )
{
  DOut psInput;
  
  for( uint i = 0; i < 3; i++ )
  {
    psInput.position = input[i].position;
    psInput.texcoord = input[i].texcoord;
    psInput.access = input[i].access;
    psInput.NormalW = input[i].NormalW;
    psInput.depthPosition = input[i].depthPosition;

    triStream.Append(psInput);
  }

  triStream.RestartStrip();
}

//***************************************************//
//                 PIXEL SHADER                      //
//***************************************************//

struct POut
{
	float4 Diffuse  : SV_Target0;
	float4 Depth    : SV_Target1;
	float4 Normals  : SV_Target2;
	float4 Lighting : SV_Target3;
};

POut PShader(DOut input)
{
	POut output;

	// Depth
	output.Depth = float4(input.depthPosition.xyz, 1.0f);

	// Normals
	output.Normals = float4(normalize(input.NormalW), 1);

	output.Diffuse = float4(t_map.Sample(ss, input.texcoord).rgb, 1);
	output.Lighting = float4(lightcol.rgb * input.access, 1.0f);

	output.Lighting = float4(1, 1, 1, 1);

	return output;
}

The only warning I get are the: implicit truncation of vector type

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Whoops, enabled debug creation flag, got various errors, fixed them all but one:


D3D11: ERROR: ID3D11DeviceContext::DrawIndexed: Vertex Shader - Hull Shader linkage error: Stages are incompatible with each other. Semantic 'TEXTURE' is always read by the downstream shader, but never written by the upstream shader (even though the semantic is present in its output signature). [ EXECUTION ERROR #347: DEVICE_SHADER_LINKAGE_NEVERWRITTEN_ALWAYSREADS ]

Shader:


cbuffer ConstantObjectBuffer : register (b0)
{
	matrix worldMatrix;
};

cbuffer ConstantFrameBuffer : register (b1)
{
	matrix viewMatrix;
	matrix projectionMatrix;

	float3 eyepos;
	float cppad;

	float4 lightvec;
	float4 lightcol;

	float FogStart;
	float FogEnd;
	float2 __space;

	float3 FogColor;
	float shadows;

	float SpecularIntensity;
	float3 pad3;
	float4 SpecularColor;
}


//***************************************************//
//                 VERTEX SHADER                     //
//***************************************************//

struct VOut
{
    float4 position : POSITION;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;

	float tessAmount : TSSAM;
	
	float3 NormalW : NORMWORLD;
	float3 normal : NORM;
	float4 depthPosition : TEXTURE0;
};

struct GlobalIn
{
	float4 position : POSITION;
	float4 normal : NORMAL;
	float2 texcoord : TEXCOORD;
};

Texture2D t_map : register(t0);
SamplerState ss;

VOut VShader(GlobalIn input)
{
    VOut output;

    input.position.w = 1.0f;
	output.texcoord = input.texcoord;

	// Calculate the position of the vertex against the world, view, and projection matrices.
    /*output.position = mul(input.position, worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);*/

	output.position = mul(input.position, viewMatrix);

	// Get Tesselation amount
	output.tessAmount = (1.0f / output.position.z) * 6.0f;

	output.position = input.position;

    output.NormalW = mul(float4(input.normal.xyz,0), mul(worldMatrix, viewMatrix));

	// Store the position value in a second input value for depth value calculations.
	output.depthPosition.xyz = mul(float4(input.position.xyz,1), mul(worldMatrix, viewMatrix)).xyz;

	// Per Vertex lighting
	float4 norm = normalize(input.normal);
	output.access = saturate(dot(norm, lightvec));

	output.normal = input.normal;
	
    return output;
}

//***************************************************//
//                 HULL SHADER                       //
//***************************************************//

struct HOutput
{
    float edges[3] : SV_TessFactor;
    float inside : SV_InsideTessFactor;
};

HOutput ColorPatchConstantFunction(InputPatch<VOut, 3> inputPatch, uint patchId : SV_PrimitiveID)
{    
    HOutput output;

	float tA = inputPatch[0].tessAmount;
	tA = 36.0f;

    // Set the tessellation factors for the three edges of the triangle.
    output.edges[0] = tA;
    output.edges[1] = tA;
    output.edges[2] = tA;

    // Set the tessellation factor for tessallating inside the triangle.
    output.inside = tA;

    return output;
}

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("ColorPatchConstantFunction")]

VOut HShader(InputPatch<VOut, 3> patch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)
{
    VOut output;

    // Set the x for this control point as the output x.
    output.position =      patch[pointId].position;
    output.texcoord =      patch[pointId].texcoord;
    output.depthPosition = patch[pointId].depthPosition;
    output.access =        patch[pointId].access;
    output.tessAmount =    patch[pointId].tessAmount;
    output.NormalW =       patch[pointId].NormalW;
    output.normal =        patch[pointId].normal;

    return output;
}

//***************************************************//
//                 DOMAIN SHADER                     //
//***************************************************//

struct DOut
{
    float4 position : SV_Position;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;

	float tessAmount : TSSAM;
	
	float3 NormalW : NORMWORLD;
	float4 depthPosition : TEXTURE0;
};

[domain("tri")]

DOut DShader(HOutput input, float3 uvwCoord : SV_DomainLocation, const OutputPatch<VOut, 3> patch)
{
    DOut output;

	float3 vertexPosition;
    float2 texCoords;
    float3 normal;
    float4 worldPosition;

	output.access = patch[0].access;
	output.texcoord = patch[0].texcoord;
	output.depthPosition = patch[0].depthPosition;

	vertexPosition = uvwCoord.x * patch[0].position + uvwCoord.y * patch[1].position + uvwCoord.z * patch[2].position;

    texCoords = uvwCoord.x * patch[0].texcoord + uvwCoord.y * patch[1].texcoord + uvwCoord.z * patch[2].texcoord;

    normal =  uvwCoord.x * float3(0, 1, 0) + uvwCoord.y * float3(0, 1, 0) + uvwCoord.z * float3(0, 1, 0);
    normal = normalize(normal);

    float vHeight = t_map.SampleLevel(ss, texCoords, 0);
    vertexPosition += float3(0, 1, 0) * (vHeight * 2.0f);

    output.position = mul(float4(vertexPosition, 1.0f), worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    output.texcoord = texCoords;

    output.NormalW = mul(normal,(float3x3)worldMatrix);
    output.NormalW = normalize(output.NormalW);

	output.tessAmount = patch[0].tessAmount;

    return output;
}

//***************************************************//
//                 PIXEL SHADER                      //
//***************************************************//

[maxvertexcount(3)]   // produce a maximum of 3 output vertices
void GShader( triangle DOut input[3], inout TriangleStream<DOut> triStream )
{
  DOut psInput;
  
  for( uint i = 0; i < 3; i++ )
  {
    psInput.position = input[i].position;
    psInput.texcoord = input[i].texcoord;
    psInput.access = input[i].access;
    psInput.access = input[i].access;
    psInput.NormalW = input[i].NormalW;
    psInput.depthPosition = input[i].depthPosition;
    psInput.tessAmount = input[i].tessAmount;

    triStream.Append(psInput);
  }

  triStream.RestartStrip();
}

//***************************************************//
//                 PIXEL SHADER                      //
//***************************************************//

struct POut
{
	float4 Diffuse  : SV_Target0;
	float4 Depth    : SV_Target1;
	float4 Normals  : SV_Target2;
	float4 Lighting : SV_Target3;
};

POut PShader(DOut input)
{
	POut output;

	// Depth
	output.Depth = float4(input.depthPosition.xyz, 1.0f);

	// Normals
	output.Normals = float4(normalize(input.NormalW), 1);

	output.Diffuse = float4(t_map.Sample(ss, input.texcoord).rgb, 1);
	output.Lighting = float4(lightcol.rgb * input.access, 1.0f);

	output.Lighting = float4(1, 1, 1, 1);

	return output;
}

Which I can't seem to solve :(

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

You should get warnings (apart from the truncation) even if you compile the shaders in isolation, at least I do:

migi.fx(52,6): warning X3578: Output value 'VShader' is not completely initialized

The linkage error also tells you which one is the culprit (semantic TEXTURE), i.e. VOut.depthPosition (you don't write to w, only to xyz).

I think you should find the other ones, since your shader actually works when corrected wink.png

5d9b57269064730.jpg

(I used a different scale and higher tesselation, though)

Cheers.

Huh, I still don't get that sad.png

... Still thinking what could be wrong.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

The shader, if I forgot something:


cbuffer ConstantObjectBuffer : register (b0)
{
	matrix worldMatrix;
};

cbuffer ConstantFrameBuffer : register (b1)
{
	matrix viewMatrix;
	matrix projectionMatrix;

	float3 eyepos;
	float cppad;

	float4 lightvec;
	float4 lightcol;

	float FogStart;
	float FogEnd;
	float2 __space;

	float3 FogColor;
	float shadows;

	float SpecularIntensity;
	float3 pad3;
	float4 SpecularColor;
}


//***************************************************//
//                 VERTEX SHADER                     //
//***************************************************//

struct VOut
{
    float4 position : POSITION;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;

	float tessAmount : TSSAM;
	
	float3 NormalW : NORMWORLD;
	float3 normal : NORM;
	float4 depthPosition : TEXTURE0;
};

struct GlobalIn
{
	float4 position : POSITION;
	float4 normal : NORMAL;
	float2 texcoord : TEXCOORD;
};

Texture2D t_map : register(t0);
SamplerState ss;

VOut VShader(GlobalIn input)
{
    VOut output;

    input.position.w = 1.0f;
	output.texcoord = input.texcoord;

	// Calculate the position of the vertex against the world, view, and projection matrices.
    /*output.position = mul(input.position, worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);*/

	output.position = mul(input.position, viewMatrix);

	// Get Tesselation amount
	output.tessAmount = (1.0f / output.position.z) * 6.0f;

	output.position = input.position;

    output.NormalW = mul(float4(input.normal.xyz,0), mul(worldMatrix, viewMatrix));

	// Store the position value in a second input value for depth value calculations.
	output.depthPosition.xyz = mul(float4(input.position.xyz,1), mul(worldMatrix, viewMatrix)).xyz;
	output.depthPosition.w = 1.0f;

	// Per Vertex lighting
	float4 norm = normalize(input.normal);
	output.access = saturate(dot(norm, lightvec));

	output.normal = input.normal;
	
    return output;
}

//***************************************************//
//                 HULL SHADER                       //
//***************************************************//

struct HOutput
{
    float edges[3] : SV_TessFactor;
    float inside : SV_InsideTessFactor;
};

HOutput ColorPatchConstantFunction(InputPatch<VOut, 3> inputPatch, uint patchId : SV_PrimitiveID)
{    
    HOutput output;

	float tA = inputPatch[0].tessAmount;
	tA = 36.0f;

    // Set the tessellation factors for the three edges of the triangle.
    output.edges[0] = tA;
    output.edges[1] = tA;
    output.edges[2] = tA;

    // Set the tessellation factor for tessallating inside the triangle.
    output.inside = tA;

    return output;
}

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("ColorPatchConstantFunction")]

VOut HShader(InputPatch<VOut, 3> patch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)
{
    VOut output;

    // Set the x for this control point as the output x.
    output.position =      patch[pointId].position;
    output.texcoord =      patch[pointId].texcoord;
    output.depthPosition = patch[pointId].depthPosition;
    output.access =        patch[pointId].access;
    output.tessAmount =    patch[pointId].tessAmount;
    output.NormalW =       patch[pointId].NormalW;
    output.normal =        patch[pointId].normal;

    return output;
}

//***************************************************//
//                 DOMAIN SHADER                     //
//***************************************************//

struct DOut
{
    float4 position : SV_Position;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;

	float tessAmount : TSSAM;
	
	float3 NormalW : NORMWORLD;
	float4 depthPosition : TEXTURE0;
};

[domain("tri")]

DOut DShader(HOutput input, float3 uvwCoord : SV_DomainLocation, const OutputPatch<VOut, 3> patch)
{
    DOut output;

	float3 vertexPosition;
    float2 texCoords;
    float3 normal;
    float4 worldPosition;

	output.access = patch[0].access;
	output.texcoord = patch[0].texcoord;
	output.depthPosition = patch[0].depthPosition;

	vertexPosition = uvwCoord.x * patch[0].position + uvwCoord.y * patch[1].position + uvwCoord.z * patch[2].position;

    texCoords = uvwCoord.x * patch[0].texcoord + uvwCoord.y * patch[1].texcoord + uvwCoord.z * patch[2].texcoord;

    normal =  uvwCoord.x * float3(0, 1, 0) + uvwCoord.y * float3(0, 1, 0) + uvwCoord.z * float3(0, 1, 0);
    normal = normalize(normal);

    float vHeight = t_map.SampleLevel(ss, texCoords, 0);
    vertexPosition += float3(0, 1, 0) * (vHeight * 2.0f);

    output.position = mul(float4(vertexPosition, 1.0f), worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    output.texcoord = texCoords;

    output.NormalW = mul(normal,(float3x3)worldMatrix);
    output.NormalW = normalize(output.NormalW);

	output.tessAmount = patch[0].tessAmount;

    return output;
}

//***************************************************//
//                 PIXEL SHADER                      //
//***************************************************//

[maxvertexcount(3)]   // produce a maximum of 3 output vertices
void GShader( triangle DOut input[3], inout TriangleStream<DOut> triStream )
{
  DOut psInput;
  
  for( uint i = 0; i < 3; i++ )
  {
    psInput.position = input[i].position;
    psInput.texcoord = input[i].texcoord;
    psInput.access = input[i].access;
    psInput.access = input[i].access;
    psInput.NormalW = input[i].NormalW;
    psInput.depthPosition = input[i].depthPosition;
    psInput.tessAmount = input[i].tessAmount;

    triStream.Append(psInput);
  }

  triStream.RestartStrip();
}

//***************************************************//
//                 PIXEL SHADER                      //
//***************************************************//

struct POut
{
	float4 Diffuse  : SV_Target0;
	float4 Depth    : SV_Target1;
	float4 Normals  : SV_Target2;
	float4 Lighting : SV_Target3;
};

POut PShader(DOut input)
{
	POut output;

	// Depth
	output.Depth = float4(input.depthPosition.xyz, 1.0f);

	// Normals
	output.Normals = float4(normalize(input.NormalW), 1);

	output.Diffuse = float4(t_map.Sample(ss, input.texcoord).rgb, 1);
	output.Lighting = float4(lightcol.rgb * input.access, 1.0f);

	output.Lighting = float4(1, 1, 1, 1);

	return output;
}

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

This topic is closed to new replies.

Advertisement