- calculate the normal view matrix at a higher level.

This commit is contained in:
Christoph Oelckers 2018-06-20 13:49:06 +02:00
parent 7f5272c23f
commit eb277cc101
4 changed files with 30 additions and 15 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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)
{

View file

@ -0,0 +1,15 @@
#pragma once
#include "r_data/matrix.h"
struct HWViewpointUniforms
{
VSMatrix mProjectionMatrix;
VSMatrix mViewMatrix;
VSMatrix mNormalViewMatrix;
void CalcDependencies()
{
mNormalViewMatrix.computeNormalMatrix(mViewMatrix);
}
};