我创建了Projector:
Matrix.CreateLookAt(position,direction,Vector3.Up); Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45),1,1,2);
我传递给这些矩阵的着色器乘法(在着色器中称为View),然后在着色器中我做:
float4 proj(float3 Position)
{
float4 texCoord = mul(float4(Position, 1.0), View);
texCoord.x = ( (texCoord.x / texCoord.w)/2) + 0.5;
texCoord.y = (-(texCoord.y / texCoord.w)/2) + 0.5;
return tex2D(shape, texCoord.xy);
}
纹理的uvw是Clamped。我在deffered阴影的光阶段使用它。得到的图像(红色箭头是正确的方向): image
我该怎么做才能让它朝正确的方向前进?
解决: 问题是反投影简直解决了:
float4 proj(float3 Position)
{
float4 texCoord = mul(float4(Position, 1.0), View);
if(texCoord.z < 0)
return 0;
texCoord.x = ( (texCoord.x / texCoord.w)/2) + 0.5;
texCoord.y = (-(texCoord.y / texCoord.w)/2) + 0.5;
return tex2D(shape, texCoord.xy);
}
答案 0 :(得分:0)
问题在于反投影,只需解决:
float4 proj(float3 Position)
{
float4 texCoord = mul(float4(Position, 1.0), View);
if(texCoord.z < 0)
return 0;
texCoord.x = ( (texCoord.x / texCoord.w)/2) + 0.5;
texCoord.y = (-(texCoord.y / texCoord.w)/2) + 0.5;
return tex2D(shape, texCoord.xy);
}