난 그림자 매핑으로 뒤죽박죽을 시작했다. 나는 사용 된 알고리즘을 이해한다. 문제는 내가 HLSL 코드에서 어수선한 곳인지 알아낼 수 없다는 것입니다. 여기에 있습니다 :그림자 매핑 아티팩트
//These change
float4x4 worldViewProj;
float4x4 world;
texture tex;
//These remain constant
float4x4 lightSpace;
float4x4 lightViewProj;
float4x4 textureBias;
texture shadowMap;
sampler TexS = sampler_state
{
Texture = <tex>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler TexShadow = sampler_state
{
Texture = <shadowMap>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
};
struct A2V
{
float3 posL : POSITION0;
float2 texCo : TEXCOORD0;
};
struct OutputVS
{
float4 posH : POSITION0;
float2 texCo : TEXCOORD0;
float4 posW : TEXCOORD2;
};
//Vertex Shader Depth Pass
OutputVS DepthVS(A2V IN)
{
OutputVS OUT = (OutputVS)0;
//Get screen coordinates in light space for texture map
OUT.posH = mul(float4(IN.posL, 1.f), lightViewProj);
//Get the depth by performing a perspective divide on the projected coordinates
OUT.posW.x = OUT.posH.z/OUT.posH.w;
return OUT;
}
//Pixel shader depth Pass
float4 DepthPS(OutputVS IN) : COLOR
{
//Texture only uses red channel, just store it there
return float4(IN.posW.x, 0, 0, 1);
}
//VertexShader Draw Pass
OutputVS DrawVS(A2V IN)
{
OutputVS OUT = (OutputVS)0;
//Get the screen coordinates for this pixel
OUT.posH = mul(float4(IN.posL, 1.f), worldViewProj);
//Send texture coordinates through
OUT.texCo = IN.texCo;
//Pass its world coordinates through
OUT.posW = mul(float4(IN.posL, 1.f), world);
return OUT;
}
//PixelShader Draw Pass
float4 DrawPS(OutputVS IN) : COLOR
{
//Get the pixels screen position in light space
float4 texCoord = mul(IN.posW, lightViewProj);
//Perform perspective divide to normalize coordinates [-1,1]
//texCoord.x = texCoord.x/texCoord.w;
//texCoord.y = texCoord.y/texCoord.w;
//Multiply by texture bias to bring in range 0-1
texCoord = mul(texCoord, textureBias);
//Get corresponding depth value
float prevDepth = tex2D(TexShadow, texCoord.xy);
//Check if it is in shadow
float4 posLight = mul(IN.posW, lightViewProj);
float currDepth = posLight.z/posLight.w;
if (currDepth >= prevDepth)
return float4(0.f, 0.f, 0.f, 1.f);
else
return tex2D(TexS, IN.texCo);
}
//Effect info
technique ShadowMap
{
pass p0
{
vertexShader = compile vs_2_0 DepthVS();
pixelShader = compile ps_2_0 DepthPS();
}
pass p1
{
vertexShader = compile vs_2_0 DrawVS();
pixelShader = compile ps_2_0 DrawPS();
}
}
모든 매트릭스가 정확하고 깊이 맵이 올바르게 그려져 있는지 확인했습니다. 이 코드를 처리하는 모든 C++을 다시 작성하고 더 깔끔하게 만들었으며 여전히 동일한 문제가 발생했습니다. 나는 현재 그 그림자를 블렌딩하지 않고, 정확히 그릴 수있을 때까지 평면을 검은 색으로 그립니다. 방향 표시등이므로 직각 투영을 사용합니다. 나는 URL을 이미지를 삽입 할 수있는 충분한 명성 포인트를 해달라고하지만 현재 위치 : 깊이지도 - http://i.imgur.com/T2nITid.png 프로그램 출력 - http://i.imgur.com/ae3U3N0.png
어떤 도움이나 통찰력이 크게 학교 프로젝트의로 감상 할 수있다. 감사합니다
당신은 내가 실제 그림자를 가지고 있다는 것을 알 수 있습니다. 나는 또한 그 모든 다른 goop도 가지고 있으며 그것이 어디에서 오는 것인지 확실하지 않습니다. – user3355098