From 463746f62d9b48f9fbbba3b2fcf7354067873e94 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 20 Jun 2019 01:55:27 +0300 Subject: [PATCH] Expose world-to-eye matrix in Renderer's standard shdata --- shaderlib/msp_interface.glsl | 1 + source/renderer.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/shaderlib/msp_interface.glsl b/shaderlib/msp_interface.glsl index e606edf9..fda84de9 100644 --- a/shaderlib/msp_interface.glsl +++ b/shaderlib/msp_interface.glsl @@ -22,6 +22,7 @@ uniform mat4 eye_obj_matrix; uniform mat3 eye_obj_normal_matrix; uniform Transform { + mat4 eye_world_matrix; mat4 projection_matrix; }; diff --git a/source/renderer.cpp b/source/renderer.cpp index c213f0a9..e59949a3 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -35,7 +35,10 @@ Renderer::Renderer(const Camera *c): if(c) set_camera(*c); else + { standard_shdata.uniform("projection_matrix", Matrix()); + standard_shdata.uniform("eye_world_matrix", Matrix()); + } } Renderer::~Renderer() @@ -54,6 +57,7 @@ void Renderer::set_camera(const Camera &c) { state->camera = &c; standard_shdata.uniform("projection_matrix", state->camera->get_projection_matrix()); + standard_shdata.uniform("eye_world_matrix", state->camera->get_view_matrix()); changed |= STANDARD_SHDATA|LEGACY_PROJECTION; set_matrix(state->camera->get_view_matrix()); } @@ -179,9 +183,15 @@ void Renderer::pop_state() if(camera_changed) { if(state->camera) + { standard_shdata.uniform("projection_matrix", state->camera->get_projection_matrix()); + standard_shdata.uniform("eye_world_matrix", state->camera->get_view_matrix()); + } else + { standard_shdata.uniform("projection_matrix", Matrix()); + standard_shdata.uniform("eye_world_matrix", Matrix()); + } changed |= STANDARD_SHDATA|LEGACY_PROJECTION; } /* This actually should compare the relevant matrices rather than check for -- 2.43.0