I’ve been bending Cass’s ear about this but anyone else care to help an old man (me) out?
OK, I’m doing shadow mapping in Cg using Vertex and Fragment progs. I’ve replaced the bit TexGen does in mapping the vertex eye position back into it’s light space projected position.
The following works:
In the VP I output into texcoord0 the vertex position => model matrix => Light View => Projection (NO DIVIDE BY W) :
float4 pm = mul(Model, IN.Position);
OUT.HPosition = mul(ViewProj, pm);
float4 tt = mul(LightView,pm);
OUT.TC0 = mul(Proj,tt);
In the FP I’m getting passed interpolated xyzw in TC0 so I do this:
float2 tt = IN.TC0.xy / IN.TC0.w; // Divide by W gives me a range -1 to 1
tt.xy = tt.xy * 128 + 128; // Scale for Texture rectangle
OUT.col.x = f1texRECT(tex0, tt.xy); // TEST just display projected shadow buffer
So, I’m not doing ANY scaling or divides by w in the VP. I do them in the FP. It works. It’s slow.
NOW I try and move the /w out of the FP into the VP
…
tt = mul(Proj,tt);
tt.xy = tt.xy / tt.w;
OUT.TC0 = tt;
Doesn’t work - shadows are way out on the ground plane.
So, Instead, try and move scaling from FP into VP - doesn’t work.
So, instead try not doing the /w but calling f1texRECYproj(tex0, tt.xyz) :
float3 tt = IN.TC0.xyw ; // NO Divide by
tt.xy = tt.xy * 128 + 128; // Scale for Texture rectangle
OUT.col.x = f1texRECTproj(tex0, tt.xyz); // TEST just display projected shadow buffer
Doesnt work
I know I’m just missing something.
There must be a way to do it so that the FP only has to execute :
OUT.col.x = f1texRECTproj(tex0, tt.xyz);
because the incomming tex coords have been scaled in the VP.
Help!
Rob
[This message has been edited by pocketmoon (edited 09-27-2002).]