Permalink
Browse files

Use a precomputed invmatrix in gi.frag

(General) matrix inversion is costly, it's better if it's done a single
time on cpu. Improve performance.
  • Loading branch information...
1 parent cb161a2 commit 71969acd228393dfbe6dc4798e0faeef9b045041 Vincent Lejeune committed Jun 20, 2014
Showing with 11 additions and 5 deletions.
  1. +2 −1 data/shaders/gi.frag
  2. +3 −1 src/graphics/post_processing.cpp
  3. +4 −1 src/graphics/shaders.cpp
  4. +2 −2 src/graphics/shaders.hpp
View
@@ -12,6 +12,7 @@ uniform sampler3D SHB;
uniform float R_wcs = 10.;
uniform vec3 extents;
uniform mat4 RHMatrix;
+uniform mat4 InvRHMatrix;
layout (std140) uniform MatrixesData
{
@@ -55,7 +56,7 @@ void main()
if (depth==1.0) discard;
vec4 pos_screen_space = getPosFromUVDepth(vec3(uv, depth), InverseProjectionMatrix);
- vec4 tmp = (inverse(RHMatrix) * InverseViewMatrix * pos_screen_space);
+ vec4 tmp = (InvRHMatrix * InverseViewMatrix * pos_screen_space);
vec3 pos = tmp.xyz / tmp.w;
vec3 normal_screen_space = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
vec3 normal = (transpose(ViewMatrix) * vec4(normal_screen_space, 0.)).xyz;
@@ -244,6 +244,8 @@ void PostProcessing::renderDiffuseEnvMap(const float *bSHCoeff, const float *gSH
void PostProcessing::renderGI(const core::matrix4 &RHMatrix, const core::vector3df &rh_extend, GLuint shr, GLuint shg, GLuint shb)
{
+ core::matrix4 InvRHMatrix;
+ RHMatrix.getInverse(InvRHMatrix);
glDisable(GL_DEPTH_TEST);
glUseProgram(FullScreenShader::GlobalIlluminationReconstructionShader::Program);
glBindVertexArray(FullScreenShader::GlobalIlluminationReconstructionShader::vao);
@@ -267,7 +269,7 @@ void PostProcessing::renderGI(const core::matrix4 &RHMatrix, const core::vector3
}
setTexture(3, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST);
setTexture(4, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
- FullScreenShader::GlobalIlluminationReconstructionShader::setUniforms(RHMatrix, rh_extend, 3, 4, 0, 1, 2);
+ FullScreenShader::GlobalIlluminationReconstructionShader::setUniforms(RHMatrix, InvRHMatrix, rh_extend, 3, 4, 0, 1, 2);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
View
@@ -2400,6 +2400,7 @@ namespace FullScreenShader
GLuint GlobalIlluminationReconstructionShader::uniform_SHB;
GLuint GlobalIlluminationReconstructionShader::uniform_extents;
GLuint GlobalIlluminationReconstructionShader::uniform_RHMatrix;
+ GLuint GlobalIlluminationReconstructionShader::uniform_InvRHMatrix;
GLuint GlobalIlluminationReconstructionShader::vao;
void GlobalIlluminationReconstructionShader::init()
@@ -2415,15 +2416,17 @@ namespace FullScreenShader
uniform_SHG = glGetUniformLocation(Program, "SHG");
uniform_SHB = glGetUniformLocation(Program, "SHB");
uniform_RHMatrix = glGetUniformLocation(Program, "RHMatrix");
+ uniform_InvRHMatrix = glGetUniformLocation(Program, "InvRHMatrix");
uniform_extents = glGetUniformLocation(Program, "extents");
vao = createFullScreenVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
- void GlobalIlluminationReconstructionShader::setUniforms(const core::matrix4 &RHMatrix, const core::vector3df &extents, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_SHR, unsigned TU_SHG, unsigned TU_SHB)
+ void GlobalIlluminationReconstructionShader::setUniforms(const core::matrix4 &RHMatrix, const core::matrix4 &InvRHMatrix, const core::vector3df &extents, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_SHR, unsigned TU_SHG, unsigned TU_SHB)
{
glUniformMatrix4fv(uniform_RHMatrix, 1, GL_FALSE, RHMatrix.pointer());
+ glUniformMatrix4fv(uniform_InvRHMatrix, 1, GL_FALSE, InvRHMatrix.pointer());
glUniform1i(uniform_ntex, TU_ntex);
glUniform1i(uniform_dtex, TU_dtex);
glUniform1i(uniform_SHR, TU_SHR);
View
@@ -624,11 +624,11 @@ class GlobalIlluminationReconstructionShader
{
public:
static GLuint Program;
- static GLuint uniform_ntex, uniform_dtex, uniform_extents, uniform_SHR, uniform_SHG, uniform_SHB, uniform_RHMatrix;
+ static GLuint uniform_ntex, uniform_dtex, uniform_extents, uniform_SHR, uniform_SHG, uniform_SHB, uniform_RHMatrix, uniform_InvRHMatrix;
static GLuint vao;
static void init();
- static void setUniforms(const core::matrix4 &RHMatrix, const core::vector3df &extents, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_SHR, unsigned TU_SHG, unsigned TU_SHB);
+ static void setUniforms(const core::matrix4 &RHMatrix, const core::matrix4 &InvRHMatrix, const core::vector3df &extents, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_SHR, unsigned TU_SHG, unsigned TU_SHB);
};
class Gaussian17TapHShader

0 comments on commit 71969ac

Please sign in to comment.