@@ -32,9 +32,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3232#endif
3333
3434#if defined(USE_REFLECTIVE_SPECULAR)
35- uniform samplerCube u_EnvironmentMap0;
36- uniform samplerCube u_EnvironmentMap1;
37- uniform float u_EnvironmentInterpolation;
35+ uniform samplerCube u_EnvironmentMap0;
36+ uniform samplerCube u_EnvironmentMap1;
37+ uniform float u_EnvironmentInterpolation;
38+
39+ // Only the RGB components are meaningful
40+ // FIXME: using reflective specular will always globally decrease the scene brightness
41+ // because we're multiplying with something that can only be less than 1.
42+ vec4 EnvironmentalSpecularFactor( vec3 viewDir, vec3 normal )
43+ {
44+ vec4 envColor0 = textureCube (u_EnvironmentMap0, reflect ( - viewDir, normal ) );
45+ vec4 envColor1 = textureCube (u_EnvironmentMap1, reflect ( - viewDir, normal ) );
46+ return mix ( envColor0, envColor1, u_EnvironmentInterpolation );
47+ }
3848#endif // USE_REFLECTIVE_SPECULAR
3949
4050// lighting helper functions
@@ -59,15 +69,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5969#endif
6070
6171#if defined(USE_DELUXE_MAPPING) || defined(USE_GRID_DELUXE_MAPPING) || (defined(r_realtimeLighting) && r_realtimeLightingRenderer == 1 )
62- #if defined(USE_REFLECTIVE_SPECULAR)
63- void computeDeluxeLight( vec3 lightDir, vec3 normal, vec3 viewDir, vec3 lightColor,
64- vec4 diffuseColor, vec4 materialColor,
65- inout vec4 color, in samplerCube u_EnvironmentMap0, in samplerCube u_EnvironmentMap1 )
66- #else // !USE_REFLECTIVE_SPECULAR
6772void computeDeluxeLight( vec3 lightDir, vec3 normal, vec3 viewDir, vec3 lightColor,
6873 vec4 diffuseColor, vec4 materialColor,
6974 inout vec4 color )
70- #endif // !USE_REFLECTIVE_SPECULAR
7175{
7276 vec3 H = normalize ( lightDir + viewDir );
7377
@@ -122,15 +126,6 @@ void computeDeluxeLight( vec3 lightDir, vec3 normal, vec3 viewDir, vec3 lightCol
122126 color.a = mix ( diffuseColor.a, 1.0 , FexpNV );
123127
124128 #else // !USE_PHYSICAL_MAPPING
125-
126- #if defined(USE_REFLECTIVE_SPECULAR)
127- // not implemented for PBR yet
128- vec4 envColor0 = textureCube (u_EnvironmentMap0, reflect ( - viewDir, normal ) );
129- vec4 envColor1 = textureCube (u_EnvironmentMap1, reflect ( - viewDir, normal ) );
130-
131- materialColor.rgb *= mix ( envColor0, envColor1, u_EnvironmentInterpolation ).rgb;
132- #endif // USE_REFLECTIVE_SPECULAR
133-
134129 color.rgb += lightColor.rgb * NdotL * diffuseColor.rgb;
135130 #if defined(r_specularMapping)
136131 color.rgb += computeSpecularity(lightColor.rgb, materialColor, NdotH);
@@ -164,13 +159,8 @@ layout(std140) uniform u_Lights {
164159
165160uniform int u_numLights;
166161
167- #if defined(USE_REFLECTIVE_SPECULAR)
168- void computeDynamicLight( uint idx, vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse,
169- vec4 material, inout vec4 color, in samplerCube u_EnvironmentMap0, in samplerCube u_EnvironmentMap1 )
170- #else // !USE_REFLECTIVE_SPECULAR
171162void computeDynamicLight( uint idx, vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse,
172163 vec4 material, inout vec4 color )
173- #endif // !USE_REFLECTIVE_SPECULAR
174164{
175165 Light light = GetLight( idx );
176166 vec3 L;
@@ -202,15 +192,9 @@ void computeDynamicLight( uint idx, vec3 P, vec3 normal, vec3 viewDir, vec4 diff
202192 attenuation = 1.0 ;
203193 }
204194
205- #if defined(USE_REFLECTIVE_SPECULAR)
206- computeDeluxeLight( L, normal, viewDir,
207- attenuation * attenuation * light.color,
208- diffuse, material, color, u_EnvironmentMap0, u_EnvironmentMap1 );
209- #else // !USE_REFLECTIVE_SPECULAR
210- computeDeluxeLight( L, normal, viewDir,
211- attenuation * attenuation * light.color,
212- diffuse, material, color );
213- #endif // !USE_REFLECTIVE_SPECULAR
195+ computeDeluxeLight(
196+ L, normal, viewDir, attenuation * attenuation * light.color,
197+ diffuse, material, color );
214198}
215199
216200const int lightsPerLayer = 16 ;
@@ -230,14 +214,8 @@ uint nextIdx( in uint count, in idxs_t idxs ) {
230214 return ( idxs[count / 4 ] >> ( 8 * ( count % 4 ) ) ) & 0xFFu;
231215}
232216
233- #if defined(USE_REFLECTIVE_SPECULAR)
234- void computeDynamicLights( vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse, vec4 material,
235- inout vec4 color, in usampler3D u_LightTiles,
236- in samplerCube u_EnvironmentMap0, in samplerCube u_EnvironmentMap1 )
237- #else // !USE_REFLECTIVE_SPECULAR
238217void computeDynamicLights( vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse, vec4 material,
239218 inout vec4 color, in usampler3D u_LightTiles )
240- #endif // !USE_REFLECTIVE_SPECULAR
241219{
242220 if ( u_numLights == 0 ) {
243221 return ;
@@ -259,13 +237,8 @@ void computeDynamicLights( vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse, vec4
259237 /* Light IDs are stored relative to the layer
260238 Subtract 1 because 0 means there's no light */
261239 idx = ( idx - 1 ) * NUM_LIGHT_LAYERS + layer;
262-
263- #if defined(USE_REFLECTIVE_SPECULAR)
264- computeDynamicLight( idx, P, normal, viewDir, diffuse, material, color, u_EnvironmentMap0, u_EnvironmentMap1 );
265- #else // !USE_REFLECTIVE_SPECULAR
266- computeDynamicLight( idx, P, normal, viewDir, diffuse, material, color );
267- #endif // !USE_REFLECTIVE_SPECULAR
268240
241+ computeDynamicLight( idx, P, normal, viewDir, diffuse, material, color );
269242 lightCount++ ;
270243 }
271244 }
0 commit comments