diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 9a57719827..69ada9f306 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -308,7 +308,10 @@ void FRenderState::ApplyMatrices() { if (GLRenderer->mShaderManager != NULL) { - GLRenderer->mShaderManager->ApplyMatrices(&mProjectionMatrix, &mViewMatrix, mPassType); + VSMatrix norm; + norm.computeNormalMatrix(mViewMatrix); + + GLRenderer->mShaderManager->ApplyMatrices(&mProjectionMatrix, &mViewMatrix, &norm, mPassType); } } diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 5293187fdc..3641b88019 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -539,10 +539,10 @@ FShader *FShaderManager::Get(unsigned int eff, bool alphateston, EPassType passT return nullptr; } -void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view, EPassType passType) +void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm, EPassType passType) { if (passType < mPassShaders.Size()) - mPassShaders[passType]->ApplyMatrices(proj, view); + mPassShaders[passType]->ApplyMatrices(proj, view, norm); if (mActiveShader) mActiveShader->Bind(); @@ -687,28 +687,25 @@ FShader *FShaderCollection::BindEffect(int effect) //========================================================================== EXTERN_CVAR(Int, gl_fuzztype) -void FShaderCollection::ApplyMatrices(VSMatrix *proj, VSMatrix *view) +void FShaderCollection::ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm) { - VSMatrix norm; - norm.computeNormalMatrix(*view); - for (int i = 0; i < SHADER_NoTexture; i++) { - mMaterialShaders[i]->ApplyMatrices(proj, view, &norm); - mMaterialShadersNAT[i]->ApplyMatrices(proj, view, &norm); + mMaterialShaders[i]->ApplyMatrices(proj, view, norm); + mMaterialShadersNAT[i]->ApplyMatrices(proj, view, norm); } - mMaterialShaders[SHADER_NoTexture]->ApplyMatrices(proj, view, &norm); + mMaterialShaders[SHADER_NoTexture]->ApplyMatrices(proj, view, norm); if (gl_fuzztype != 0) { - mMaterialShaders[SHADER_NoTexture + gl_fuzztype]->ApplyMatrices(proj, view, &norm); + mMaterialShaders[SHADER_NoTexture + gl_fuzztype]->ApplyMatrices(proj, view, norm); } for (unsigned i = FIRST_USER_SHADER; i < mMaterialShaders.Size(); i++) { - mMaterialShaders[i]->ApplyMatrices(proj, view, &norm); + mMaterialShaders[i]->ApplyMatrices(proj, view, norm); } for (int i = 0; i < MAX_EFFECTS; i++) { - mEffectShaders[i]->ApplyMatrices(proj, view, &norm); + mEffectShaders[i]->ApplyMatrices(proj, view, norm); } } diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 6307fce8fb..a3ca7eb7c4 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -326,7 +326,7 @@ public: FShader *BindEffect(int effect, EPassType passType); FShader *Get(unsigned int eff, bool alphateston, EPassType passType); - void ApplyMatrices(VSMatrix *proj, VSMatrix *view, EPassType passType); + void ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm, EPassType passType); private: FShader *mActiveShader = nullptr; @@ -348,7 +348,7 @@ public: FShader *Compile(const char *ShaderName, const char *ShaderPath, const char *LightModePath, const char *shaderdefines, bool usediscard, EPassType passType); int Find(const char *mame); FShader *BindEffect(int effect); - void ApplyMatrices(VSMatrix *proj, VSMatrix *view); + void ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm); FShader *Get(unsigned int eff, bool alphateston) { diff --git a/src/hwrenderer/scene/hw_viewpointuniforms.h b/src/hwrenderer/scene/hw_viewpointuniforms.h new file mode 100644 index 0000000000..5d0a888b83 --- /dev/null +++ b/src/hwrenderer/scene/hw_viewpointuniforms.h @@ -0,0 +1,15 @@ +#pragma once + +#include "r_data/matrix.h" + +struct HWViewpointUniforms +{ + VSMatrix mProjectionMatrix; + VSMatrix mViewMatrix; + VSMatrix mNormalViewMatrix; + + void CalcDependencies() + { + mNormalViewMatrix.computeNormalMatrix(mViewMatrix); + } +};