light optimization
This commit is contained in:
parent
fc0586de57
commit
c7bd5ca2e6
|
|
@ -301,6 +301,8 @@ void DynamicLightShader::setWallMapResolution(int x, int y){
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicLightShader::setCameraPosition(int x, int y){
|
void DynamicLightShader::setCameraPosition(int x, int y){
|
||||||
|
cameraPositionCache.x = x;
|
||||||
|
cameraPositionCache.y = y;
|
||||||
gl.Uniform2f(u_cameraPosition, x, y);
|
gl.Uniform2f(u_cameraPosition, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,21 +312,31 @@ void DynamicLightShader::setTileMapOffset(int x, int y){
|
||||||
|
|
||||||
void DynamicLightShader::setLightSources(std::vector<LightSource> sources){
|
void DynamicLightShader::setLightSources(std::vector<LightSource> sources){
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for(int i = 0; i < sources.size(); i++) {
|
int screenWidth = shState->graphics().width();
|
||||||
|
int screenHeight = shState->graphics().height();
|
||||||
|
for(int i = 0; i < sources.size(); ++i) {
|
||||||
if (count < 64) {
|
if (count < 64) {
|
||||||
if (!sources[i].hasEffect())
|
LightSource source = sources[i];
|
||||||
|
if (!source.hasEffect())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (source.x * 32 < cameraPositionCache.x - source.radius * 32
|
||||||
|
|| source.y * 32 < cameraPositionCache.y - source.radius * 32
|
||||||
|
|| source.x * 32 > cameraPositionCache.x + source.radius * 32 + screenWidth
|
||||||
|
|| source.y * 32 > cameraPositionCache.y + source.radius * 32 + screenHeight
|
||||||
|
) continue;
|
||||||
|
|
||||||
gl.Uniform4f(u_lightSources + count,
|
gl.Uniform4f(u_lightSources + count,
|
||||||
sources[i].x,
|
source.x,
|
||||||
sources[i].y,
|
source.y,
|
||||||
sources[i].power,
|
source.power,
|
||||||
sources[i].radius
|
source.radius
|
||||||
);
|
);
|
||||||
gl.Uniform4f(u_lightSourcesColors + count,
|
gl.Uniform4f(u_lightSourcesColors + count,
|
||||||
sources[i].color.red / 255.0,
|
source.color.red / 255.0,
|
||||||
sources[i].color.green / 255.0,
|
source.color.green / 255.0,
|
||||||
sources[i].color.blue / 255.0,
|
source.color.blue / 255.0,
|
||||||
sources[i].color.alpha / 255.0
|
source.color.alpha / 255.0
|
||||||
);
|
);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLint u_wallMapTexture, u_wallMapResolution, u_cameraPosition, u_tileMapOffset, u_lightSources, u_lightSourcesCount, u_lightSourcesColors, u_ambientLight;
|
GLint u_wallMapTexture, u_wallMapResolution, u_cameraPosition, u_tileMapOffset, u_lightSources, u_lightSourcesCount, u_lightSourcesColors, u_ambientLight;
|
||||||
|
Vec2i cameraPositionCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SimpleColorShader : public ShaderBase{
|
class SimpleColorShader : public ShaderBase{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue