From 33b7c893cb63a24a4633cea81fda0e564710d705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Fri, 31 Jul 2020 22:01:33 +0200 Subject: [PATCH 1/2] Allow length of the light direction vector to influence strength of the light source. This fixes the issue with objects and terrain being darker than they should be. As it turns out, most levels have not normalized light direction which happens to make light brighter and this is the expected result. To keep in line with GL14 engine, newer engines should use the length of the vector to make light brighter. --- src/graphics/opengl/shaders/gl21/fs_normal.glsl | 4 ++-- src/graphics/opengl/shaders/gl33/fs_normal.glsl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/graphics/opengl/shaders/gl21/fs_normal.glsl b/src/graphics/opengl/shaders/gl21/fs_normal.glsl index 77402258..1aeffcbe 100644 --- a/src/graphics/opengl/shaders/gl21/fs_normal.glsl +++ b/src/graphics/opengl/shaders/gl21/fs_normal.glsl @@ -84,8 +84,8 @@ void main() { LightParams light = uni_Light[i]; - vec3 lightDirection = normalize(light.Position.xyz); - vec3 reflectAxis = normalize(lightDirection + camera); + vec3 lightDirection = light.Position.xyz; + vec3 reflectAxis = normalize(normalize(lightDirection) + camera); float diffuseComponent = clamp(dot(normal, lightDirection), 0.0f, 1.0f); float specularComponent = pow(clamp(dot(normal, reflectAxis), 0.0f, 1.0f), 10.0f); diff --git a/src/graphics/opengl/shaders/gl33/fs_normal.glsl b/src/graphics/opengl/shaders/gl33/fs_normal.glsl index 7b498723..be58f4fd 100644 --- a/src/graphics/opengl/shaders/gl33/fs_normal.glsl +++ b/src/graphics/opengl/shaders/gl33/fs_normal.glsl @@ -83,8 +83,8 @@ void main() for (int i = 0; i < uni_LightCount; i++) { - vec3 lightDirection = normalize(uni_Light[i].Position.xyz); - vec3 reflectAxis = normalize(lightDirection + camera); + vec3 lightDirection = uni_Light[i].Position.xyz; + vec3 reflectAxis = normalize(normalize(lightDirection) + camera); ambient += uni_Light[i].Ambient; diffuse += clamp(dot(normal, lightDirection), 0.0f, 1.0f) From 4c14050b27f6f2a54ea7b552afceb6929e7bc2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Fri, 31 Jul 2020 22:04:47 +0200 Subject: [PATCH 2/2] Fixed mipmaps being outdates after texture update. --- src/graphics/opengl/gl33device.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 2ca1aa4f..bd26d35b 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -886,6 +886,8 @@ void CGL33Device::UpdateTexture(const Texture& texture, Math::IntPoint offset, I glTexSubImage2D(GL_TEXTURE_2D, 0, offset.x, offset.y, texData.actualSurface->w, texData.actualSurface->h, texData.sourceFormat, GL_UNSIGNED_BYTE, texData.actualSurface->pixels); + glGenerateMipmap(GL_TEXTURE_2D); + SDL_FreeSurface(texData.convertedSurface); }