From 94cd8d5c51d824e7a723a187c38771a8da05b4c0 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 5 Sep 2014 23:41:12 +0200 Subject: [PATCH] Avoid some useless computation in some vert shaders --- data/shaders/header.txt | 2 ++ data/shaders/instanced_grass.vert | 2 +- data/shaders/instanced_object_pass.vert | 2 +- data/shaders/utils/getworldmatrix.vert | 2 +- src/graphics/render.cpp | 11 ++++++----- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/data/shaders/header.txt b/data/shaders/header.txt index ec5c45115..98e73f6a9 100644 --- a/data/shaders/header.txt +++ b/data/shaders/header.txt @@ -3,6 +3,7 @@ uniform mat4 ViewMatrix; uniform mat4 ProjectionMatrix; uniform mat4 InverseViewMatrix; uniform mat4 InverseProjectionMatrix; +uniform mat4 ProjectionViewMatrix; uniform vec2 screen; #else layout (std140) uniform MatrixesData @@ -11,6 +12,7 @@ layout (std140) uniform MatrixesData mat4 ProjectionMatrix; mat4 InverseViewMatrix; mat4 InverseProjectionMatrix; + mat4 ProjectionViewMatrix; mat4 ShadowViewProjMatrixes[4]; vec2 screen; }; diff --git a/data/shaders/instanced_grass.vert b/data/shaders/instanced_grass.vert index b65a08d1f..5a9d11769 100644 --- a/data/shaders/instanced_grass.vert +++ b/data/shaders/instanced_grass.vert @@ -37,7 +37,7 @@ void main() { mat4 ModelMatrix = getWorldMatrix(Origin + windDir * Color.r, Orientation, Scale); mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin + windDir * Color.r, Orientation, Scale) * InverseViewMatrix); - gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.); + gl_Position = ProjectionViewMatrix * ModelMatrix * vec4(Position, 1.); nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz; uv = Texcoord; #ifdef GL_ARB_bindless_texture diff --git a/data/shaders/instanced_object_pass.vert b/data/shaders/instanced_object_pass.vert index eb8a9e018..ab0fce5b2 100644 --- a/data/shaders/instanced_object_pass.vert +++ b/data/shaders/instanced_object_pass.vert @@ -44,7 +44,7 @@ void main(void) { mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale); mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * InverseViewMatrix); - gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.); + gl_Position = ProjectionViewMatrix * ModelMatrix * vec4(Position, 1.); nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz; tangent = (TransposeInverseModelView * vec4(Tangent, 1.)).xyz; bitangent = (TransposeInverseModelView * vec4(Bitangent, 1.)).xyz; diff --git a/data/shaders/utils/getworldmatrix.vert b/data/shaders/utils/getworldmatrix.vert index 3bff563f4..c5883ae35 100644 --- a/data/shaders/utils/getworldmatrix.vert +++ b/data/shaders/utils/getworldmatrix.vert @@ -45,6 +45,6 @@ mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale) { mat4 result = transpose(getMatrixFromRotation(rotation)); // FIXME: it's wrong but the fourth column is not used - result[3].xyz -= translation; + // result[3].xyz -= translation; return getScaleMatrix(1. / scale) * result; } \ No newline at end of file diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 336302a8a..ee510d776 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -597,11 +597,12 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz }; - float tmp[16 * 8 + 2]; + float tmp[16 * 9 + 2]; memcpy(tmp, irr_driver->getViewMatrix().pointer(), 16 * sizeof(float)); memcpy(&tmp[16], irr_driver->getProjMatrix().pointer(), 16 * sizeof(float)); memcpy(&tmp[32], irr_driver->getInvViewMatrix().pointer(), 16 * sizeof(float)); memcpy(&tmp[48], irr_driver->getInvProjMatrix().pointer(), 16 * sizeof(float)); + memcpy(&tmp[64], irr_driver->getProjViewMatrix().pointer(), 16 * sizeof(float)); const core::matrix4 &SunCamViewMatrix = m_suncam->getViewMatrix(); for (unsigned i = 0; i < 4; i++) @@ -723,13 +724,13 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz size_t size = irr_driver->getShadowViewProj().size(); for (unsigned i = 0; i < size; i++) - memcpy(&tmp[16 * i + 64], irr_driver->getShadowViewProj()[i].pointer(), 16 * sizeof(float)); + memcpy(&tmp[16 * i + 80], irr_driver->getShadowViewProj()[i].pointer(), 16 * sizeof(float)); } - tmp[128] = float(width); - tmp[129] = float(height); + tmp[144] = float(width); + tmp[145] = float(height); glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO); - glBufferSubData(GL_UNIFORM_BUFFER, 0, (16 * 8 + 2) * sizeof(float), tmp); + glBufferSubData(GL_UNIFORM_BUFFER, 0, (16 * 9 + 2) * sizeof(float), tmp); }