2023-01-12 15:00:14 -05:00
|
|
|
uniform mat4 gbufferProjection;
|
|
|
|
uniform mat4 gbufferProjectionInverse;
|
|
|
|
uniform mat4 gbufferPreviousProjection;
|
|
|
|
uniform mat4 gbufferModelViewInverse;
|
|
|
|
uniform mat4 gbufferModelView;
|
|
|
|
uniform mat4 shadowModelView;
|
|
|
|
uniform mat4 shadowProjection;
|
|
|
|
|
|
|
|
uniform vec3 cameraPosition;
|
|
|
|
|
2024-05-18 22:58:30 -04:00
|
|
|
// #define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
|
|
|
// #define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
2023-01-12 15:00:14 -05:00
|
|
|
|
|
|
|
vec3 toClipSpace3(vec3 viewSpacePosition) {
|
|
|
|
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 toScreenSpace(vec3 p) {
|
|
|
|
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
|
|
|
|
vec3 p3 = p * 2. - 1.;
|
|
|
|
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
|
|
|
|
return fragposition.xyz / fragposition.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 toScreenSpaceVector(vec3 p) {
|
|
|
|
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
|
|
|
|
vec3 p3 = p * 2. - 1.;
|
|
|
|
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
|
|
|
|
return normalize(fragposition.xyz);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 toWorldSpace(vec3 p3){
|
|
|
|
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
|
|
|
return p3;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 toWorldSpaceCamera(vec3 p3){
|
|
|
|
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
|
|
|
return p3 + cameraPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 toShadowSpace(vec3 p3){
|
|
|
|
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
|
|
|
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
|
|
|
|
return p3;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 toShadowSpaceProjected(vec3 p3){
|
|
|
|
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
|
|
|
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
|
|
|
|
p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz;
|
|
|
|
|
|
|
|
return p3;
|
2024-02-05 16:04:37 -05:00
|
|
|
}
|