Hi all,
I've found out that I'm doing some projected lighting/texture calculations in the PS, which I should/can also do in the VS, so I've tried to redo it. But somehow the outcome is incorrect (visually). Any idea what I'm overlooking?
Old approach:
//VS
[unroll]
for(uint v=0;v<gPerScene.NrProjSpotLights;v++) vout.ViewPos[v] = GetViewPos(v, float4(vout.PosW, 1.0f));
// PS
for(uint ps=0;ps<gPerObject.NrProjSpotLightsAff;++ps)
{
uint lightId = gPerObject.ProjSpotLightsAff[ps/4][ps%4];
uint texIndex = gPerScene.LightSources[lightId].LengthOrProjTexIndex;
projColor = gLightMap.Sample(gTexSampler, float3(GetProjectedUV(pin.ViewPos[gPerScene.LightSources[lightId].ProjMVPIndex], true), texIndex)).rgb;
CalcSpotLightProj(gPerScene.LightSources[lightId], pin.PosW, toEye, lightSetup, projColor.rgb);
}
New approach:
// VS
[unroll]
for(uint ps=0;ps<gPerObject.NrProjSpotLightsAff;++ps)
{
uint lightId = gPerObject.ProjSpotLightsAff[ps/4][ps%4];
float4 tViewPos = GetViewPos(ps, float4(vout.PosW, 1.0f));
vout.ProjPos[ps] = GetProjectedUV(tViewPos, true);
}
// PS
for(uint ps=0;ps<gPerObject.NrProjSpotLightsAff;++ps)
{
uint lightId = gPerObject.ProjSpotLightsAff[ps/4][ps%4];
uint texIndex = gPerScene.LightSources[lightId].LengthOrProjTexIndex;
float3 projColor = gLightMap.Sample(gTexSampler, float3(pin.ProjPos[ps], texIndex)).rgb;
CalcSpotLightProj(gPerScene.LightSources[lightId], pin.PosW, toEye, lightSetup, projColor.rgb);
}