Dynamic lights hacked back in for GLES2, needs optimisation

This commit is contained in:
Emile Belanger 2021-03-08 20:23:12 +00:00
parent 36d50328ef
commit e395c660ec
5 changed files with 36 additions and 22 deletions

View file

@ -36,6 +36,7 @@
#include "gles_hwtexture.h"
#include "gles_buffers.h"
#include "hw_clock.h"
#include "printf.h"
#include "hwrenderer/data/hw_viewpointbuffer.h"
namespace OpenGLESRenderer
@ -258,6 +259,7 @@ bool FGLRenderState::ApplyShader()
// Mess alert for crappy AncientGL!
if (!screen->mLights->GetBufferType() && index >= 0)
{
/*
size_t start, size;
index = screen->mLights->GetBinding(index, &start, &size);
@ -266,9 +268,17 @@ bool FGLRenderState::ApplyShader()
mLastMappedLightIndex = start;
static_cast<GLDataBuffer*>(screen->mLights->GetBuffer())->BindRange(nullptr, start, size);
}
}
*/
float* ptr = ((float*)screen->mLights->GetBuffer()->Memory());
ptr += ((int64_t)index * 4);
float array[64];
memcpy(array, ptr, 4 * 64);
glUniform4fv(activeShader->cur->lights_index, 64, ptr);
//activeShader->cur->muLightIndex.Set(index);
activeShader->cur->muLightIndex.Set(0);
}
return true;
}

View file

@ -312,7 +312,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
uniform mat4 TextureMatrix;
// light buffers
uniform vec4 lights[32];
uniform vec4 lights[128];
// textures
@ -333,25 +333,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
uniform float timer;
// material types
#if defined(SPECULAR)
#define normaltexture texture2
#define speculartexture texture3
#define brighttexture texture4
#define detailtexture texture5
#define glowtexture texture6
#elif defined(PBR)
#define normaltexture texture2
#define metallictexture texture3
#define roughnesstexture texture4
#define aotexture texture5
#define brighttexture texture6
#define detailtexture texture7
#define glowtexture texture8
#else
#define brighttexture texture2
#define detailtexture texture3
#define glowtexture texture4
#endif
)";

View file

@ -1,3 +1,16 @@
How can I remove the alpha test discard?
--------------------------------------
uTextureMode
0xFFFF =

View file

@ -260,6 +260,10 @@ float spotLightAttenuation(vec4 lightpos, vec3 spotdir, float lightCosInnerAngle
return smoothstep(lightCosOuterAngle, lightCosInnerAngle, cosDir);
}
vec3 ApplyNormalMap(vec2 texcoord)
{
return normalize(vWorldNormal.xyz);
}
//===========================================================================
//
@ -270,6 +274,7 @@ float spotLightAttenuation(vec4 lightpos, vec3 spotdir, float lightCosInnerAngle
void SetMaterialProps(inout Material material, vec2 texCoord)
{
material.Base = getTexel(texCoord.st);
material.Normal = ApplyNormalMap(texCoord.st);
#if (DEF_TEXTURE_FLAGS & 0x1)
material.Bright = texture2D(brighttexture, texCoord.st);
@ -389,7 +394,7 @@ vec4 applyFog(vec4 frag, float fogfactor)
void main()
{
if (ClipDistanceA.x < 0.0 || ClipDistanceA.y < 0.0 || ClipDistanceA.z < 0.0 || ClipDistanceA.w < 0.0 || ClipDistanceB.x < 0.0) discard;
//if (ClipDistanceA.x < 0.0 || ClipDistanceA.y < 0.0 || ClipDistanceA.z < 0.0 || ClipDistanceA.w < 0.0 || ClipDistanceB.x < 0.0) discard;
#ifndef LEGACY_USER_SHADER
Material material;

View file

@ -24,6 +24,8 @@ vec3 lightContribution(int i, vec3 normal)
attenuation *= clamp(dotprod, 0.0, 1.0);
}
if (attenuation > 0.0) // Skip shadow map test if possible
{
attenuation *= shadowAttenuation(lightpos, lightcolor.a);
@ -52,7 +54,7 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
}
// subtractive lights
for(int i=lightRange.y; i<lightRange.z; i+=4)
for(int i=lightRange.y; i<lightRange.z; i+=4)
{
dynlight.rgb -= lightContribution(i, normal);
}
@ -77,6 +79,6 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
frag = clamp(frag + desaturate(addlight).rgb, 0.0, 1.0);
}
}
return frag;
}