Hi guys,
right now I'm having a small issue, the issue might be small, but it's blocking my development , which is about depth mapping:
Screenshot:
As you can see, there are some problems...
The shader(This shader is not optimized in any way as that is not my current goal, depth mapping occurs in this statement: "if (state == 5 || state == 2)" ):
cbuffer ConstantObjectBuffer : register (b0)
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
float state;
float _instance;
float _alphamap;
float _diffusealpha;
};
struct VOut
{
float4 position : SV_POSITION;
float4 normal : NORMAL;
float2 texcoord : TEXCOORD;
float4 depthPosition : TEXTURE0;
};
Texture2D t_alphamap;
Texture2D t_dffalpha;
SamplerState ss;
VOut VShader(float4 position : POSITION, float4 normal : NORMAL, float2 texcoord : TEXCOORD, float3 instancePosition : INSTANCEPOS)
{
VOut output;
if (_instance == 1)
{
position.x += instancePosition.x;
position.y += instancePosition.y;
position.z += instancePosition.z;
}
position.w = 1.0f;
output.texcoord = texcoord;
// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);
output.normal = normal;
output.depthPosition = output.position;
return output;
}
float4 PShader(VOut input) : SV_TARGET
{
float4 color = float4(1,1,1,1);
if (state == 5 || state == 2)
{
float depthValue;
depthValue = input.depthPosition.z / 25.0f;
color = float4(depthValue, depthValue, depthValue, 1.0f);
}
else if (state == 6)
{
float3 viewSpaceNormalizedNormals = input.normal; //0.5 * normalize (input.normal) + 0.5
color = float4(viewSpaceNormalizedNormals, 1);
}
if (_alphamap == 1)
{
color.a *= t_alphamap.Sample(ss, input.texcoord).a;
}
if (_diffusealpha == 1)
{
color.a *= t_dffalpha.Sample(ss, input.texcoord).a;
}
return color;
}
Now what on earth did I do wrong?