So basically i store 6 shadowmap mvp matrices ( each representing a different view direction (FRONT,BACK,LEFT,RIGHT,BOTTOM,TOP))
I basically use the formula like this:(model *view) *projection and pass this to shader
However i end up with these matrices
-1 0 0 135.957 0 1 0 -255.867 0 0 -1 331.663 0 0 0 1
1 0 0 -135.957 0 1 0 -255.867 0 0 1 -331.663 0 0 0 1
0 0 -1 331.663 0 1 0 -255.867 1 0 0 -135.957 0 0 0 1
0 0 1 -331.663 0 1 0 -255.867 -1 0 0 135.957 0 0 0 1
-1 0 0 135.957 0 0 -1 331.663 0 -1 0 255.867 0 0 0 1
-1 0 0 135.957 0 0 1 -331.663 0 1 0 -255.867 0 0 0 1
So i have 0 0 0 1 at last row everytime
Having this code in fragment shader
shadowvclip.x = -dp43(SMVP[i*4 + 0], vertex_pos);
shadowvclip.y = dp43(SMVP[i*4 + 1], vertex_pos);
shadowvclip.z = dp43(SMVP[i*4 + 2], vertex_pos);
shadowvclip.w = dp43(SMVP[i*4 + 3], vertex_pos);
svc = shadowvclip.xyz / shadowvclip.w;
svc = svc * 0.5 + 0.5;
It happens to w to be always 1 no matter what thus i always get value beyound 0..1
rendering shadow compare useless.
float dp43(vec4 matrow, vec3 p)
{
return ( (matrow.x*p.x) + (matrow.y*p.y) + (matrow.z*p.z) + matrow.w );
}
But however when i use the samr techinque to render a 3d scene ( its not related to shadowmapping - i just render the scene everythings renders where it should be i mean)
Imagine i pass one of these shadow mvp matrices to a different vertex shader
precision highp float;
attribute vec3 Vpos;
uniform vec4 MVP1;
uniform vec4 MVP2;
uniform vec4 MVP3;
uniform vec4 MVP4;
vec4 vertexClip;
float dp43(vec4 matrow, vec3 p)
{
return ( (matrow.x*p.x) + (matrow.y*p.y) + (matrow.z*p.z) + matrow.w );
}
void main()
{
vertexClip.x = -dp43(MVP1, Vpos);
vertexClip.y = dp43(MVP2, Vpos);
vertexClip.z = dp43(MVP3, Vpos);
vertexClip.w = dp43(MVP4, Vpos);
gl_Position = vertexClip;
}
GPU somehow magically converts that vertexClip.w to something usefull however it stays last row is 0 0 0 1 all the time…
and dont bother with vclip.x = -dp43()
It just changes wicked view of opengl to something usefull
So how is that in vertex shader gpu somehow manages to do perspective division with this w component and i get ndc coords, but whenever i try to manually calculate it, it doesnt?