]> git.tdb.fi Git - libs/gl.git/commitdiff
Add inverse view and projection matrices to camera transform uniforms
authorMikko Rasa <tdb@tdb.fi>
Sat, 8 May 2021 15:09:31 +0000 (18:09 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 May 2021 07:53:57 +0000 (10:53 +0300)
builtin_data/_sky_backdrop.glsl
shaderlib/msp_interface.glsl
source/render/camera.cpp

index 420f0ed5ff1ce268a7a2a2480d0b87e558047a1b..fa28663c65282b573950c4d4249a208a8fe5c49b 100644 (file)
@@ -7,10 +7,9 @@ uniform sampler2D distant;
 void main()
 {
        gl_Position = vec4(vertex.xy, 1.0, 1.0);
-       mat4 inv_projection = inverse(clip_eye_matrix);
-       out vec4 view_dir = inv_projection*vec4(vertex.xy, -1.0, 1.0);
+       out vec4 view_dir = eye_clip_matrix*vec4(vertex.xy, -1.0, 1.0);
        view_dir /= view_dir.w;
-       view_dir = inverse(eye_world_matrix)*vec4(view_dir.xyz, 0.0);
+       view_dir = world_eye_matrix*vec4(view_dir.xyz, 0.0);
 }
 
 #pragma MSP stage(fragment)
index e35b984845cf318fc0ec70b9b18042719ab6f12e..959f9ba55b31742662bbd088c4a11c80df5165fd 100644 (file)
@@ -11,10 +11,12 @@ struct ClipPlane
 
 uniform mat4 world_obj_matrix;
 uniform mat3 world_obj_normal_matrix;
-uniform Transform
+uniform CameraTransform
 {
        mat4 eye_world_matrix;
+       mat4 world_eye_matrix;
        mat4 clip_eye_matrix;
+       mat4 eye_clip_matrix;
 };
 
 uniform Lighting
index 9b8b0c778d0c5fc68f784efaee4c74b886801ddb..8b966464fd14d2ed42eb478d4b025f95bc1fbcfa 100644 (file)
@@ -133,6 +133,7 @@ void Camera::update_projection_matrix()
        proj_matrix = Matrix::rotation(rotate, Vector3(0, 0, 1))*proj_matrix;
 
        shdata.uniform("clip_eye_matrix", proj_matrix);
+       shdata.uniform("eye_clip_matrix", invert(proj_matrix));
 }
 
 void Camera::update_object_matrix()
@@ -146,6 +147,7 @@ void Camera::update_object_matrix()
        matrix = Matrix::from_columns(columns);
        view_matrix = invert(matrix);
 
+       shdata.uniform("world_eye_matrix", matrix);
        shdata.uniform("eye_world_matrix", view_matrix);
 }