From 7b483c197c82703965418289506e0ad7ff85e30d Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Sun, 18 Oct 2020 15:43:29 +0200 Subject: [PATCH] Remove pointless optimization --- .../rendering/shaders/shading-fs-100.glsl | 6 ++-- .../rendering/shaders/shading-fs.glsl | 8 ++--- .../rendering/shaders/shading-vs-100.glsl | 34 ++----------------- .../rendering/shaders/shading-vs.glsl | 34 ++----------------- 4 files changed, 8 insertions(+), 74 deletions(-) diff --git a/src/graphics/rendering/shaders/shading-fs-100.glsl b/src/graphics/rendering/shaders/shading-fs-100.glsl index f70e322..a277f40 100644 --- a/src/graphics/rendering/shaders/shading-fs-100.glsl +++ b/src/graphics/rendering/shaders/shading-fs-100.glsl @@ -39,7 +39,6 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2 uniform vec2 circleLightCenters[CIRCLE_LIGHT_COUNT]; uniform float circleLightIntensities[CIRCLE_LIGHT_COUNT]; uniform vec3 circleLightColors[CIRCLE_LIGHT_COUNT]; - varying vec2 circleLightDirections[CIRCLE_LIGHT_COUNT]; #endif #endif @@ -49,7 +48,6 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2 uniform float flashlightIntensities[FLASHLIGHT_COUNT]; uniform vec3 flashlightColors[FLASHLIGHT_COUNT]; uniform vec2 flashlightDirections[FLASHLIGHT_COUNT]; - varying vec2 flashlightActualDirections[FLASHLIGHT_COUNT]; float intensityInDirection(vec2 lightDirection, vec2 targetDirection) { return smoothstep( @@ -79,7 +77,7 @@ void main() { lightCenterDistance / circleLightIntensities[i] + 1.0, 2.0 ); - vec2 direction = normalize(circleLightDirections[i]) / squareToAspectRatioTimes2; + vec2 direction = normalize(circleLightCenters[i] - position) / squareToAspectRatioTimes2; lighting += lightColorAtPosition * shadowTransparency( startingDistance, lightCenterDistance, @@ -94,7 +92,7 @@ void main() { #ifdef FLASHLIGHT_COUNT #if FLASHLIGHT_COUNT > 0 for (int i = 0; i < FLASHLIGHT_COUNT; i++) { - vec2 originalDirection = normalize(flashlightActualDirections[i]); + vec2 originalDirection = normalize(flashlightCenters[i] - position); float lightCenterDistance = distance(flashlightCenters[i], position); diff --git a/src/graphics/rendering/shaders/shading-fs.glsl b/src/graphics/rendering/shaders/shading-fs.glsl index ea1384f..3567e28 100644 --- a/src/graphics/rendering/shaders/shading-fs.glsl +++ b/src/graphics/rendering/shaders/shading-fs.glsl @@ -40,8 +40,6 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2 uniform float circleLightIntensities[CIRCLE_LIGHT_COUNT]; uniform vec3 circleLightColors[CIRCLE_LIGHT_COUNT]; - in vec2 circleLightDirections[CIRCLE_LIGHT_COUNT]; - vec3 colorInPosition(int lightIndex, out float lightCenterDistance) { lightCenterDistance = distance(circleLightCenters[lightIndex], position); return circleLightColors[lightIndex] / pow( @@ -59,8 +57,6 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2 uniform vec2 flashlightDirections[FLASHLIGHT_COUNT]; uniform float flashlightStartCutoffs[FLASHLIGHT_COUNT]; - in vec2 flashlightActualDirections[FLASHLIGHT_COUNT]; - float intensityInDirection(vec2 lightDirection, vec2 targetDirection) { return smoothstep( 0.0, @@ -95,7 +91,7 @@ void main() { float lightCenterDistance; vec3 lightColorAtPosition = colorInPosition(i, lightCenterDistance); - vec2 direction = normalize(circleLightDirections[i]) / squareToAspectRatioTimes2; + vec2 direction = normalize(circleLightCenters[i] - position) / squareToAspectRatioTimes2; lighting += lightColorAtPosition * shadowTransparency( startingDistance, lightCenterDistance, @@ -110,7 +106,7 @@ void main() { #ifdef FLASHLIGHT_COUNT #if FLASHLIGHT_COUNT > 0 for (int i = 0; i < FLASHLIGHT_COUNT; i++) { - vec2 originalDirection = normalize(flashlightActualDirections[i]); + vec2 originalDirection = normalize(flashlightCenters[i] - position); float lightCenterDistance; vec3 lightColorAtPosition = colorInPosition( diff --git a/src/graphics/rendering/shaders/shading-vs-100.glsl b/src/graphics/rendering/shaders/shading-vs-100.glsl index c785eca..c35ff4d 100644 --- a/src/graphics/rendering/shaders/shading-vs-100.glsl +++ b/src/graphics/rendering/shaders/shading-vs-100.glsl @@ -5,27 +5,13 @@ precision lowp float; {macroDefinitions} uniform mat3 modelTransform; +uniform vec2 squareToAspectRatio; + attribute vec4 vertexPosition; varying vec2 position; varying vec2 uvCoordinates; -uniform vec2 squareToAspectRatio; - -#ifdef CIRCLE_LIGHT_COUNT -#if CIRCLE_LIGHT_COUNT > 0 - uniform vec2 circleLightCenters[CIRCLE_LIGHT_COUNT]; - varying vec2 circleLightDirections[CIRCLE_LIGHT_COUNT]; -#endif -#endif - -#ifdef FLASHLIGHT_COUNT -#if FLASHLIGHT_COUNT > 0 - uniform vec2 flashlightCenters[FLASHLIGHT_COUNT]; - varying vec2 flashlightActualDirections[FLASHLIGHT_COUNT]; -#endif -#endif - void main() { vec3 vertexPosition2D = vec3(vertexPosition.xy, 1.0) * modelTransform; gl_Position = vec4(vertexPosition2D.xy, 0.0, 1.0); @@ -36,20 +22,4 @@ void main() { 0.0, 0.5, 0.5, 0.0, 0.0, 1.0 )).xy; - - #ifdef CIRCLE_LIGHT_COUNT - #if CIRCLE_LIGHT_COUNT > 0 - for (int i = 0; i < CIRCLE_LIGHT_COUNT; i++) { - circleLightDirections[i] = circleLightCenters[i] - position; - } - #endif - #endif - - #ifdef FLASHLIGHT_COUNT - #if FLASHLIGHT_COUNT > 0 - for (int i = 0; i < FLASHLIGHT_COUNT; i++) { - flashlightActualDirections[i] = flashlightCenters[i] - position; - } - #endif - #endif } diff --git a/src/graphics/rendering/shaders/shading-vs.glsl b/src/graphics/rendering/shaders/shading-vs.glsl index 6e23548..0f17bf1 100644 --- a/src/graphics/rendering/shaders/shading-vs.glsl +++ b/src/graphics/rendering/shaders/shading-vs.glsl @@ -5,27 +5,13 @@ precision lowp float; {macroDefinitions} uniform mat3 modelTransform; +uniform vec2 squareToAspectRatio; + in vec4 vertexPosition; out vec2 position; out vec2 uvCoordinates; -uniform vec2 squareToAspectRatio; - -#ifdef CIRCLE_LIGHT_COUNT -#if CIRCLE_LIGHT_COUNT > 0 - uniform vec2 circleLightCenters[CIRCLE_LIGHT_COUNT]; - out vec2[CIRCLE_LIGHT_COUNT] circleLightDirections; -#endif -#endif - -#ifdef FLASHLIGHT_COUNT -#if FLASHLIGHT_COUNT > 0 - uniform vec2 flashlightCenters[FLASHLIGHT_COUNT]; - out vec2[FLASHLIGHT_COUNT] flashlightActualDirections; -#endif -#endif - void main() { vec3 vertexPosition2D = vec3(vertexPosition.xy, 1.0) * modelTransform; gl_Position = vec4(vertexPosition2D.xy, 0.0, 1.0); @@ -36,20 +22,4 @@ void main() { 0.0, 0.5, 0.5, 0.0, 0.0, 1.0 )).xy; - - #ifdef CIRCLE_LIGHT_COUNT - #if CIRCLE_LIGHT_COUNT > 0 - for (int i = 0; i < CIRCLE_LIGHT_COUNT; i++) { - circleLightDirections[i] = circleLightCenters[i] - position; - } - #endif - #endif - - #ifdef FLASHLIGHT_COUNT - #if FLASHLIGHT_COUNT > 0 - for (int i = 0; i < FLASHLIGHT_COUNT; i++) { - flashlightActualDirections[i] = flashlightCenters[i] - position; - } - #endif - #endif }