uv计算

lightmap

shadowmap

heightmap

它们有一个自己的camera 对应cameraMatrix

float3 TransfromToTextureCoord(float4 PositionWS, float4x4 CameraMatirx, float CameraOrthographicSize)
{
float3 heightUV;
float4 posVS = mul(CameraMatirx, PositionWS);
heightUV.x = posVS.x / CameraOrthographicSize;
heightUV.y = posVS.y / CameraOrthographicSize;
heightUV.z = posVS.z;
heightUV.x = clamp((1 + heightUV.x) * 0.5, 0.0, 1.0);
heightUV.y = clamp((heightUV.y + 1) * 0.5, 0.0, 1.0);
return heightUV;
}

采样这张map的uv

worldspace中那个posWS---viewSpace(生成时的camera的matrix)出现在那张rt里的位置映射到0-1

原文地址:https://www.cnblogs.com/minggoddess/p/8882755.html