Skip to content

Commit fc1159a

Browse files
committed
Added normal_flip.glsl
1 parent fbf9be7 commit fc1159a

File tree

5 files changed

+13
-31
lines changed

5 files changed

+13
-31
lines changed

src/renderers/shaders/ShaderChunk/envmap_fragment.glsl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323

2424
#endif
2525

26-
#ifdef DOUBLE_SIDED
27-
float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
28-
#else
29-
float flipNormal = 1.0;
30-
#endif
26+
#include <normal_flip>
3127

3228
#ifdef ENVMAP_TYPE_CUBE
3329

@@ -42,7 +38,7 @@
4238

4339
#elif defined( ENVMAP_TYPE_SPHERE )
4440

45-
vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));
41+
vec3 reflectView = flipNormal * normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );
4642
vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );
4743

4844
#endif

src/renderers/shaders/ShaderChunk/lights_pars.glsl

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,7 @@ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
165165

166166
vec3 getLightProbeIndirectIrradiance( /*const in SpecularLightProbe specularLightProbe,*/ const in GeometricContext geometry, const in int maxMIPLevel ) {
167167

168-
#ifdef DOUBLE_SIDED
169-
170-
float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
171-
172-
#else
173-
174-
float flipNormal = 1.0;
175-
176-
#endif
168+
#include <normal_flip>
177169

178170
vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
179171

@@ -238,15 +230,7 @@ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
238230

239231
#endif
240232

241-
#ifdef DOUBLE_SIDED
242-
243-
float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
244-
245-
#else
246-
247-
float flipNormal = 1.0;
248-
249-
#endif
233+
#include <normal_flip>
250234

251235
reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
252236

@@ -293,7 +277,7 @@ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
293277

294278
#elif defined( ENVMAP_TYPE_SPHERE )
295279

296-
vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));
280+
vec3 reflectView = flipNormal * normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );
297281

298282
#ifdef TEXTURE_LOD_EXT
299283

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifdef DOUBLE_SIDED
2+
float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
3+
#else
4+
float flipNormal = 1.0;
5+
#endif

src/renderers/shaders/ShaderChunk/normal_fragment.glsl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88

99
#else
1010

11-
vec3 normal = normalize( vNormal );
11+
#include <normal_flip>
1212

13-
#ifdef DOUBLE_SIDED
14-
15-
normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );
16-
17-
#endif
13+
vec3 normal = normalize( vNormal ) * flipNormal;
1814

1915
#endif
2016

utils/build/includes/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl",
181181
"src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl",
182182
"src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl",
183+
"src/renderers/shaders/ShaderChunk/normal_flip.glsl",
183184
"src/renderers/shaders/ShaderChunk/normal_fragment.glsl",
184185
"src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl",
185186
"src/renderers/shaders/ShaderChunk/packing.glsl",

0 commit comments

Comments
 (0)