From ac778081d12633da6f41b60ba5aaa4ff529501b5 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sun, 16 Jul 2023 00:42:16 +0800 Subject: [PATCH] Remove unnecessary light define checks --- core/renderer/shaders/3D_colorNormal.frag | 39 +--- .../shaders/3D_colorNormalTexture.frag | 44 +--- .../shaders/3D_positionNormalTexture.vert | 200 +++++++----------- 3 files changed, 81 insertions(+), 202 deletions(-) diff --git a/core/renderer/shaders/3D_colorNormal.frag b/core/renderer/shaders/3D_colorNormal.frag index 628262bf14..121fff33d7 100644 --- a/core/renderer/shaders/3D_colorNormal.frag +++ b/core/renderer/shaders/3D_colorNormal.frag @@ -25,50 +25,32 @@ const char* CC3D_colorNormal_frag = R"( -#if (MAX_DIRECTIONAL_LIGHT_NUM > 0) uniform vec3 u_DirLightSourceColor[MAX_DIRECTIONAL_LIGHT_NUM]; uniform vec3 u_DirLightSourceDirection[MAX_DIRECTIONAL_LIGHT_NUM]; -#endif -#if (MAX_POINT_LIGHT_NUM > 0) + uniform vec3 u_PointLightSourceColor[MAX_POINT_LIGHT_NUM]; uniform float u_PointLightSourceRangeInverse[MAX_POINT_LIGHT_NUM]; -#endif -#if (MAX_SPOT_LIGHT_NUM > 0) + uniform vec3 u_SpotLightSourceColor[MAX_SPOT_LIGHT_NUM]; uniform vec3 u_SpotLightSourceDirection[MAX_SPOT_LIGHT_NUM]; uniform float u_SpotLightSourceInnerAngleCos[MAX_SPOT_LIGHT_NUM]; uniform float u_SpotLightSourceOuterAngleCos[MAX_SPOT_LIGHT_NUM]; uniform float u_SpotLightSourceRangeInverse[MAX_SPOT_LIGHT_NUM]; -#endif + uniform vec3 u_AmbientLightSourceColor; #ifdef GL_ES varying mediump vec2 TextureCoordOut; -#if MAX_POINT_LIGHT_NUM varying mediump vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM]; -#endif -#if MAX_SPOT_LIGHT_NUM varying mediump vec3 v_vertexToSpotLightDirection[MAX_SPOT_LIGHT_NUM]; -#endif -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) varying mediump vec3 v_normal; -#endif - #else - varying vec2 TextureCoordOut; -#if MAX_POINT_LIGHT_NUM -varying vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM]; -#endif -#if MAX_SPOT_LIGHT_NUM +varying vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM varying vec3 v_vertexToSpotLightDirection[MAX_SPOT_LIGHT_NUM]; -#endif -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) varying vec3 v_normal; #endif -#endif - uniform vec4 u_color; vec3 computeLighting(vec3 normalVector, vec3 lightDirection, vec3 lightColor, float attenuation) @@ -81,33 +63,26 @@ vec3 computeLighting(vec3 normalVector, vec3 lightDirection, vec3 lightColor, fl void main(void) { -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) vec3 normal = normalize(v_normal); -#endif vec4 combinedColor = vec4(u_AmbientLightSourceColor, 1.0); // Directional light contribution -#if (MAX_DIRECTIONAL_LIGHT_NUM > 0) for (int i = 0; i < MAX_DIRECTIONAL_LIGHT_NUM; ++i) { vec3 lightDirection = normalize(u_DirLightSourceDirection[i] * 2.0); combinedColor.xyz += computeLighting(normal, -lightDirection, u_DirLightSourceColor[i], 1.0); } -#endif // Point light contribution -#if (MAX_POINT_LIGHT_NUM > 0) for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) { vec3 ldir = v_vertexToPointLightDirection[i] * u_PointLightSourceRangeInverse[i]; float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0); combinedColor.xyz += computeLighting(normal, normalize(v_vertexToPointLightDirection[i]), u_PointLightSourceColor[i], attenuation); } -#endif // Spot light contribution -#if (MAX_SPOT_LIGHT_NUM > 0) for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) { // Compute range attenuation @@ -125,13 +100,7 @@ void main(void) attenuation = clamp(attenuation, 0.0, 1.0); combinedColor.xyz += computeLighting(normal, vertexToSpotLightDirection, u_SpotLightSourceColor[i], attenuation); } -#endif -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) gl_FragColor = u_color * combinedColor; -#else - gl_FragColor = u_color; -#endif - } )"; diff --git a/core/renderer/shaders/3D_colorNormalTexture.frag b/core/renderer/shaders/3D_colorNormalTexture.frag index 481c11f00b..91b80f72fe 100644 --- a/core/renderer/shaders/3D_colorNormalTexture.frag +++ b/core/renderer/shaders/3D_colorNormalTexture.frag @@ -25,71 +25,52 @@ const char* CC3D_colorNormalTexture_frag = R"( -#if (MAX_DIRECTIONAL_LIGHT_NUM > 0) uniform vec3 u_DirLightSourceColor[MAX_DIRECTIONAL_LIGHT_NUM]; uniform vec3 u_DirLightSourceDirection[MAX_DIRECTIONAL_LIGHT_NUM]; -#endif -#if (MAX_POINT_LIGHT_NUM > 0) + uniform vec3 u_PointLightSourceColor[MAX_POINT_LIGHT_NUM]; uniform float u_PointLightSourceRangeInverse[MAX_POINT_LIGHT_NUM]; -#endif -#if (MAX_SPOT_LIGHT_NUM > 0) + uniform vec3 u_SpotLightSourceColor[MAX_SPOT_LIGHT_NUM]; uniform vec3 u_SpotLightSourceDirection[MAX_SPOT_LIGHT_NUM]; uniform float u_SpotLightSourceInnerAngleCos[MAX_SPOT_LIGHT_NUM]; uniform float u_SpotLightSourceOuterAngleCos[MAX_SPOT_LIGHT_NUM]; uniform float u_SpotLightSourceRangeInverse[MAX_SPOT_LIGHT_NUM]; -#endif + uniform vec3 u_AmbientLightSourceColor; #ifdef GL_ES varying mediump vec2 TextureCoordOut; #ifdef USE_NORMAL_MAPPING -#if MAX_DIRECTIONAL_LIGHT_NUM varying mediump vec3 v_dirLightDirection[MAX_DIRECTIONAL_LIGHT_NUM]; #endif -#endif -#if MAX_POINT_LIGHT_NUM varying mediump vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM]; -#endif -#if MAX_SPOT_LIGHT_NUM varying mediump vec3 v_vertexToSpotLightDirection[MAX_SPOT_LIGHT_NUM]; #ifdef USE_NORMAL_MAPPING varying mediump vec3 v_spotLightDirection[MAX_SPOT_LIGHT_NUM]; #endif -#endif #ifndef USE_NORMAL_MAPPING -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) varying mediump vec3 v_normal; #endif -#endif #else varying vec2 TextureCoordOut; #ifdef USE_NORMAL_MAPPING -#if MAX_DIRECTIONAL_LIGHT_NUM varying vec3 v_dirLightDirection[MAX_DIRECTIONAL_LIGHT_NUM]; #endif -#endif -#if MAX_POINT_LIGHT_NUM varying vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM]; -#endif -#if MAX_SPOT_LIGHT_NUM varying vec3 v_vertexToSpotLightDirection[MAX_SPOT_LIGHT_NUM]; #ifdef USE_NORMAL_MAPPING varying vec3 v_spotLightDirection[MAX_SPOT_LIGHT_NUM]; #endif -#endif #ifndef USE_NORMAL_MAPPING -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) varying vec3 v_normal; #endif -#endif #endif @@ -112,19 +93,14 @@ void main(void) { #ifdef USE_NORMAL_MAPPING - #if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) - vec3 normal = normalize(2.0 * texture2D(u_normalTex, TextureCoordOut).xyz - 1.0); - #endif + vec3 normal = normalize(2.0 * texture2D(u_normalTex, TextureCoordOut).xyz - 1.0); #else - #if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) - vec3 normal = normalize(v_normal); - #endif + vec3 normal = normalize(v_normal); #endif vec4 combinedColor = vec4(u_AmbientLightSourceColor, 1.0); // Directional light contribution -#if (MAX_DIRECTIONAL_LIGHT_NUM > 0) for (int i = 0; i < MAX_DIRECTIONAL_LIGHT_NUM; ++i) { #ifdef USE_NORMAL_MAPPING @@ -134,20 +110,16 @@ void main(void) #endif combinedColor.xyz += computeLighting(normal, -lightDirection, u_DirLightSourceColor[i], 1.0); } -#endif // Point light contribution -#if (MAX_POINT_LIGHT_NUM > 0) for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) { vec3 ldir = v_vertexToPointLightDirection[i] * u_PointLightSourceRangeInverse[i]; float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0); combinedColor.xyz += computeLighting(normal, normalize(v_vertexToPointLightDirection[i]), u_PointLightSourceColor[i], attenuation); } -#endif // Spot light contribution -#if (MAX_SPOT_LIGHT_NUM > 0) for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) { // Compute range attenuation @@ -169,13 +141,7 @@ void main(void) attenuation = clamp(attenuation, 0.0, 1.0); combinedColor.xyz += computeLighting(normal, vertexToSpotLightDirection, u_SpotLightSourceColor[i], attenuation); } -#endif -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) gl_FragColor = texture2D(u_tex0, TextureCoordOut) * u_color * combinedColor; -#else - gl_FragColor = texture2D(u_tex0, TextureCoordOut) * u_color; -#endif - } )"; diff --git a/core/renderer/shaders/3D_positionNormalTexture.vert b/core/renderer/shaders/3D_positionNormalTexture.vert index 5d84a94ab1..6d24c0e979 100644 --- a/core/renderer/shaders/3D_positionNormalTexture.vert +++ b/core/renderer/shaders/3D_positionNormalTexture.vert @@ -26,19 +26,13 @@ const char* CC3D_positionNormalTexture_vert = R"( #ifdef USE_NORMAL_MAPPING -#if (MAX_DIRECTIONAL_LIGHT_NUM > 0) uniform vec3 u_DirLightSourceDirection[MAX_DIRECTIONAL_LIGHT_NUM]; #endif -#endif -#if (MAX_POINT_LIGHT_NUM > 0) uniform vec3 u_PointLightSourcePosition[MAX_POINT_LIGHT_NUM]; -#endif -#if (MAX_SPOT_LIGHT_NUM > 0) uniform vec3 u_SpotLightSourcePosition[MAX_SPOT_LIGHT_NUM]; #ifdef USE_NORMAL_MAPPING uniform vec3 u_SpotLightSourceDirection[MAX_SPOT_LIGHT_NUM]; #endif -#endif attribute vec4 a_position; attribute vec2 a_texCoord; @@ -50,25 +44,17 @@ attribute vec3 a_binormal; varying vec2 TextureCoordOut; #ifdef USE_NORMAL_MAPPING -#if MAX_DIRECTIONAL_LIGHT_NUM varying vec3 v_dirLightDirection[MAX_DIRECTIONAL_LIGHT_NUM]; #endif -#endif -#if MAX_POINT_LIGHT_NUM varying vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM]; -#endif -#if MAX_SPOT_LIGHT_NUM varying vec3 v_vertexToSpotLightDirection[MAX_SPOT_LIGHT_NUM]; #ifdef USE_NORMAL_MAPPING varying vec3 v_spotLightDirection[MAX_SPOT_LIGHT_NUM]; #endif -#endif #ifndef USE_NORMAL_MAPPING -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) varying vec3 v_normal; #endif -#endif uniform mat4 u_MVPMatrix; uniform mat4 u_MVMatrix; @@ -79,61 +65,47 @@ void main(void) { vec4 ePosition = u_MVMatrix * a_position; #ifdef USE_NORMAL_MAPPING - #if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) - vec3 eTangent = normalize(u_NormalMatrix * a_tangent); - vec3 eBinormal = normalize(u_NormalMatrix * a_binormal); - vec3 eNormal = normalize(u_NormalMatrix * a_normal); - #endif - #if (MAX_DIRECTIONAL_LIGHT_NUM > 0) - for (int i = 0; i < MAX_DIRECTIONAL_LIGHT_NUM; ++i) - { - v_dirLightDirection[i].x = dot(eTangent, u_DirLightSourceDirection[i]); - v_dirLightDirection[i].y = dot(eBinormal, u_DirLightSourceDirection[i]); - v_dirLightDirection[i].z = dot(eNormal, u_DirLightSourceDirection[i]); - } - #endif + vec3 eTangent = normalize(u_NormalMatrix * a_tangent); + vec3 eBinormal = normalize(u_NormalMatrix * a_binormal); + vec3 eNormal = normalize(u_NormalMatrix * a_normal); + for (int i = 0; i < MAX_DIRECTIONAL_LIGHT_NUM; ++i) + { + v_dirLightDirection[i].x = dot(eTangent, u_DirLightSourceDirection[i]); + v_dirLightDirection[i].y = dot(eBinormal, u_DirLightSourceDirection[i]); + v_dirLightDirection[i].z = dot(eNormal, u_DirLightSourceDirection[i]); + } - #if (MAX_POINT_LIGHT_NUM > 0) - for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) - { - vec3 pointLightDir = u_PointLightSourcePosition[i].xyz - ePosition.xyz; - v_vertexToPointLightDirection[i].x = dot(eTangent, pointLightDir); - v_vertexToPointLightDirection[i].y = dot(eBinormal, pointLightDir); - v_vertexToPointLightDirection[i].z = dot(eNormal, pointLightDir); - } - #endif + for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) + { + vec3 pointLightDir = u_PointLightSourcePosition[i].xyz - ePosition.xyz; + v_vertexToPointLightDirection[i].x = dot(eTangent, pointLightDir); + v_vertexToPointLightDirection[i].y = dot(eBinormal, pointLightDir); + v_vertexToPointLightDirection[i].z = dot(eNormal, pointLightDir); + } - #if (MAX_SPOT_LIGHT_NUM > 0) - for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) - { - vec3 spotLightDir = u_SpotLightSourcePosition[i] - ePosition.xyz; - v_vertexToSpotLightDirection[i].x = dot(eTangent, spotLightDir); - v_vertexToSpotLightDirection[i].y = dot(eBinormal, spotLightDir); - v_vertexToSpotLightDirection[i].z = dot(eNormal, spotLightDir); + for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) + { + vec3 spotLightDir = u_SpotLightSourcePosition[i] - ePosition.xyz; + v_vertexToSpotLightDirection[i].x = dot(eTangent, spotLightDir); + v_vertexToSpotLightDirection[i].y = dot(eBinormal, spotLightDir); + v_vertexToSpotLightDirection[i].z = dot(eNormal, spotLightDir); - v_spotLightDirection[i].x = dot(eTangent, u_SpotLightSourceDirection[i]); - v_spotLightDirection[i].y = dot(eBinormal, u_SpotLightSourceDirection[i]); - v_spotLightDirection[i].z = dot(eNormal, u_SpotLightSourceDirection[i]); - } - #endif + v_spotLightDirection[i].x = dot(eTangent, u_SpotLightSourceDirection[i]); + v_spotLightDirection[i].y = dot(eBinormal, u_SpotLightSourceDirection[i]); + v_spotLightDirection[i].z = dot(eNormal, u_SpotLightSourceDirection[i]); + } #else - #if (MAX_POINT_LIGHT_NUM > 0) - for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) - { - v_vertexToPointLightDirection[i] = u_PointLightSourcePosition[i].xyz - ePosition.xyz; - } - #endif + for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) + { + v_vertexToPointLightDirection[i] = u_PointLightSourcePosition[i].xyz - ePosition.xyz; + } - #if (MAX_SPOT_LIGHT_NUM > 0) - for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) - { - v_vertexToSpotLightDirection[i] = u_SpotLightSourcePosition[i] - ePosition.xyz; - } - #endif + for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) + { + v_vertexToSpotLightDirection[i] = u_SpotLightSourcePosition[i] - ePosition.xyz; + } - #if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) - v_normal = u_NormalMatrix * a_normal; - #endif + v_normal = u_NormalMatrix * a_normal; #endif TextureCoordOut = a_texCoord; @@ -145,19 +117,14 @@ void main(void) const char* CC3D_skinPositionNormalTexture_vert = R"( #ifdef USE_NORMAL_MAPPING -#if (MAX_DIRECTIONAL_LIGHT_NUM > 0) uniform vec3 u_DirLightSourceDirection[MAX_DIRECTIONAL_LIGHT_NUM]; #endif -#endif -#if (MAX_POINT_LIGHT_NUM > 0) uniform vec3 u_PointLightSourcePosition[MAX_POINT_LIGHT_NUM]; -#endif -#if (MAX_SPOT_LIGHT_NUM > 0) + uniform vec3 u_SpotLightSourcePosition[MAX_SPOT_LIGHT_NUM]; #ifdef USE_NORMAL_MAPPING uniform vec3 u_SpotLightSourceDirection[MAX_SPOT_LIGHT_NUM]; #endif -#endif attribute vec3 a_position; @@ -184,25 +151,18 @@ uniform mat4 u_PMatrix; varying vec2 TextureCoordOut; #ifdef USE_NORMAL_MAPPING -#if MAX_DIRECTIONAL_LIGHT_NUM varying vec3 v_dirLightDirection[MAX_DIRECTIONAL_LIGHT_NUM]; #endif -#endif -#if MAX_POINT_LIGHT_NUM varying vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM]; -#endif -#if MAX_SPOT_LIGHT_NUM + varying vec3 v_vertexToSpotLightDirection[MAX_SPOT_LIGHT_NUM]; #ifdef USE_NORMAL_MAPPING varying vec3 v_spotLightDirection[MAX_SPOT_LIGHT_NUM]; #endif -#endif #ifndef USE_NORMAL_MAPPING -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) varying vec3 v_normal; #endif -#endif void getPositionAndNormal(out vec4 position, out vec3 normal, out vec3 tangent, out vec3 binormal) { @@ -247,7 +207,6 @@ void getPositionAndNormal(out vec4 position, out vec3 normal, out vec3 tangent, position.z = dot(p, matrixPalette3); position.w = p.w; -#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) vec4 n = vec4(a_normal, 0.0); normal.x = dot(n, matrixPalette1); normal.y = dot(n, matrixPalette2); @@ -262,7 +221,6 @@ void getPositionAndNormal(out vec4 position, out vec3 normal, out vec3 tangent, binormal.y = dot(b, matrixPalette2); binormal.z = dot(b, matrixPalette3); #endif -#endif } void main() @@ -275,62 +233,48 @@ void main() vec4 ePosition = u_MVMatrix * position; #ifdef USE_NORMAL_MAPPING - #if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) - vec3 eTangent = normalize(u_NormalMatrix * tangent); - vec3 eBinormal = normalize(u_NormalMatrix * binormal); - vec3 eNormal = normalize(u_NormalMatrix * normal); - #endif + vec3 eTangent = normalize(u_NormalMatrix * tangent); + vec3 eBinormal = normalize(u_NormalMatrix * binormal); + vec3 eNormal = normalize(u_NormalMatrix * normal); - #if (MAX_DIRECTIONAL_LIGHT_NUM > 0) - for (int i = 0; i < MAX_DIRECTIONAL_LIGHT_NUM; ++i) - { - v_dirLightDirection[i].x = dot(eTangent, u_DirLightSourceDirection[i]); - v_dirLightDirection[i].y = dot(eBinormal, u_DirLightSourceDirection[i]); - v_dirLightDirection[i].z = dot(eNormal, u_DirLightSourceDirection[i]); - } - #endif + for (int i = 0; i < MAX_DIRECTIONAL_LIGHT_NUM; ++i) + { + v_dirLightDirection[i].x = dot(eTangent, u_DirLightSourceDirection[i]); + v_dirLightDirection[i].y = dot(eBinormal, u_DirLightSourceDirection[i]); + v_dirLightDirection[i].z = dot(eNormal, u_DirLightSourceDirection[i]); + } - #if (MAX_POINT_LIGHT_NUM > 0) - for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) - { - vec3 pointLightDir = u_PointLightSourcePosition[i].xyz - ePosition.xyz; - v_vertexToPointLightDirection[i].x = dot(eTangent, pointLightDir); - v_vertexToPointLightDirection[i].y = dot(eBinormal, pointLightDir); - v_vertexToPointLightDirection[i].z = dot(eNormal, pointLightDir); - } - #endif + for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) + { + vec3 pointLightDir = u_PointLightSourcePosition[i].xyz - ePosition.xyz; + v_vertexToPointLightDirection[i].x = dot(eTangent, pointLightDir); + v_vertexToPointLightDirection[i].y = dot(eBinormal, pointLightDir); + v_vertexToPointLightDirection[i].z = dot(eNormal, pointLightDir); + } - #if (MAX_SPOT_LIGHT_NUM > 0) - for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) - { - vec3 spotLightDir = u_SpotLightSourcePosition[i] - ePosition.xyz; - v_vertexToSpotLightDirection[i].x = dot(eTangent, spotLightDir); - v_vertexToSpotLightDirection[i].y = dot(eBinormal, spotLightDir); - v_vertexToSpotLightDirection[i].z = dot(eNormal, spotLightDir); + for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) + { + vec3 spotLightDir = u_SpotLightSourcePosition[i] - ePosition.xyz; + v_vertexToSpotLightDirection[i].x = dot(eTangent, spotLightDir); + v_vertexToSpotLightDirection[i].y = dot(eBinormal, spotLightDir); + v_vertexToSpotLightDirection[i].z = dot(eNormal, spotLightDir); - v_spotLightDirection[i].x = dot(eTangent, u_SpotLightSourceDirection[i]); - v_spotLightDirection[i].y = dot(eBinormal, u_SpotLightSourceDirection[i]); - v_spotLightDirection[i].z = dot(eNormal, u_SpotLightSourceDirection[i]); - } - #endif + v_spotLightDirection[i].x = dot(eTangent, u_SpotLightSourceDirection[i]); + v_spotLightDirection[i].y = dot(eBinormal, u_SpotLightSourceDirection[i]); + v_spotLightDirection[i].z = dot(eNormal, u_SpotLightSourceDirection[i]); + } #else - #if (MAX_POINT_LIGHT_NUM > 0) - for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) - { - v_vertexToPointLightDirection[i] = u_PointLightSourcePosition[i].xyz- ePosition.xyz; - } - #endif + for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i) + { + v_vertexToPointLightDirection[i] = u_PointLightSourcePosition[i].xyz- ePosition.xyz; + } - #if (MAX_SPOT_LIGHT_NUM > 0) - for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) - { - v_vertexToSpotLightDirection[i] = u_SpotLightSourcePosition[i] - ePosition.xyz; - } - #endif + for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i) + { + v_vertexToSpotLightDirection[i] = u_SpotLightSourcePosition[i] - ePosition.xyz; + } - #if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0)) - v_normal = u_NormalMatrix * normal; - #endif + v_normal = u_NormalMatrix * normal; #endif TextureCoordOut = a_texCoord;