mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-23 11:51:26 +00:00
Optimise dyn lights a bit
This commit is contained in:
parent
40135c4c86
commit
0a28d50b12
4 changed files with 45 additions and 50 deletions
|
@ -109,6 +109,8 @@ bool FGLRenderState::ApplyShader()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (mSpecialEffect > EFF_NONE)
|
||||
{
|
||||
activeShader = GLRenderer->mShaderManager->BindEffect(mSpecialEffect, mPassType);
|
||||
|
@ -150,7 +152,10 @@ bool FGLRenderState::ApplyShader()
|
|||
bool doDesaturate = false;
|
||||
doDesaturate = mStreamData.uDesaturationFactor != 0;
|
||||
|
||||
activeShader->Bind(textureMode, texFlags, blendFlags, twoDFog, fogEnabled, fogEquationRadial, colouredFog, doDesaturate);
|
||||
bool dynLights = false;
|
||||
dynLights = (mLightIndex >= 0);
|
||||
|
||||
activeShader->Bind(textureMode, texFlags, blendFlags, twoDFog, fogEnabled, fogEquationRadial, colouredFog, doDesaturate, dynLights);
|
||||
}
|
||||
|
||||
|
||||
|
@ -255,22 +260,11 @@ bool FGLRenderState::ApplyShader()
|
|||
matrixToGL(identityMatrix, activeShader->cur->normalmodelmatrix_index);
|
||||
}
|
||||
|
||||
int index = mLightIndex;
|
||||
// Mess alert for crappy AncientGL!
|
||||
if (!screen->mLights->GetBufferType() && index >= 0)
|
||||
if (mLightIndex >= 0)
|
||||
{
|
||||
/*
|
||||
size_t start, size;
|
||||
index = screen->mLights->GetBinding(index, &start, &size);
|
||||
|
||||
if (start != mLastMappedLightIndex)
|
||||
{
|
||||
mLastMappedLightIndex = start;
|
||||
static_cast<GLDataBuffer*>(screen->mLights->GetBuffer())->BindRange(nullptr, start, size);
|
||||
}
|
||||
*/
|
||||
float* ptr = ((float*)screen->mLights->GetBuffer()->Memory());
|
||||
ptr += ((int64_t)index * 4);
|
||||
ptr += ((int64_t)mLightIndex * 4);
|
||||
float array[64];
|
||||
memcpy(array, ptr, 4 * 64);
|
||||
|
||||
|
|
|
@ -646,9 +646,9 @@ FShader::~FShader()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
bool FShader::Bind(int textureMode, int texFlags, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog,bool doDesaturate)
|
||||
bool FShader::Bind(int textureMode, int texFlags, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog, bool doDesaturate, bool dynLights)
|
||||
{
|
||||
uint32_t tag = CreateShaderTag(textureMode, texFlags, blendFlags, twoDFog, fogEnabled, fogEquationRadial, colouredFog, doDesaturate);
|
||||
uint32_t tag = CreateShaderTag(textureMode, texFlags, blendFlags, twoDFog, fogEnabled, fogEquationRadial, colouredFog, doDesaturate, dynLights);
|
||||
|
||||
|
||||
cur = variants[tag];
|
||||
|
@ -665,6 +665,7 @@ bool FShader::Bind(int textureMode, int texFlags, int blendFlags, bool twoDFog,
|
|||
variantConfig.AppendFormat("#define DEF_FOG_COLOURED %d\n", colouredFog);
|
||||
|
||||
variantConfig.AppendFormat("#define DEF_DO_DESATURATE %d\n", doDesaturate);
|
||||
variantConfig.AppendFormat("#define DEF_DYNAMIC_LIGHTS %d\n", dynLights);
|
||||
|
||||
Printf("Shader: %s", variantConfig.GetChars());
|
||||
|
||||
|
@ -878,7 +879,7 @@ FShader *FShaderCollection::BindEffect(int effect)
|
|||
{
|
||||
if (effect >= 0 && effect < MAX_EFFECTS && mEffectShaders[effect] != NULL)
|
||||
{
|
||||
mEffectShaders[effect]->Bind(0,0,0,0,0,0,0,0);
|
||||
mEffectShaders[effect]->Bind(0,0,0,0,0,0,0,0,0);
|
||||
return mEffectShaders[effect];
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -353,7 +353,7 @@ public:
|
|||
|
||||
void LoadVariant();
|
||||
|
||||
uint32_t CreateShaderTag(int textureMode, int texf, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog, bool doDesaturate)
|
||||
uint32_t CreateShaderTag(int textureMode, int texf, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog, bool doDesaturate, bool dynLights)
|
||||
{
|
||||
uint32_t tag = 0;
|
||||
tag |= (textureMode & 0x7);
|
||||
|
@ -369,11 +369,12 @@ public:
|
|||
|
||||
tag |= (doDesaturate & 1) << 11;
|
||||
|
||||
tag |= (dynLights & 1) << 12;
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
bool Bind(int textureMode, int texFlags, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog, bool doDesaturate);
|
||||
bool Bind(int textureMode, int texFlags, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog, bool doDesaturate, bool dynLights);
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -42,10 +42,11 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
|
|||
vec4 dynlight = uDynLightColor;
|
||||
vec3 normal = material.Normal;
|
||||
|
||||
if (uLightIndex >= 0)
|
||||
{
|
||||
#if (DEF_DYNAMIC_LIGHTS == 1)
|
||||
|
||||
ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
|
||||
if (lightRange.z > lightRange.x)
|
||||
|
||||
//if (lightRange.z > lightRange.x)
|
||||
{
|
||||
// modulated lights
|
||||
for(int i=lightRange.x; i<lightRange.y; i+=4)
|
||||
|
@ -59,14 +60,10 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
|
|||
dynlight.rgb -= lightContribution(i, normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec3 frag = material.Base.rgb * clamp(color + desaturate(dynlight).rgb, 0.0, 1.4);
|
||||
|
||||
if (uLightIndex >= 0)
|
||||
{
|
||||
ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
|
||||
if (lightRange.w > lightRange.z)
|
||||
//if (lightRange.w > lightRange.z)
|
||||
{
|
||||
vec4 addlight = vec4(0.0,0.0,0.0,0.0);
|
||||
|
||||
|
@ -78,7 +75,9 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
|
|||
|
||||
frag = clamp(frag + desaturate(addlight).rgb, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
return frag;
|
||||
#else
|
||||
return material.Base.rgb * clamp(color, 0.0, 1.4);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue