Skip to content

Commit 4756f67

Browse files
committed
added support for indirect lighting on lambert shading
1 parent bdf5fc2 commit 4756f67

File tree

3 files changed

+12
-36
lines changed

3 files changed

+12
-36
lines changed

src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,11 @@ backGeometry.normal = -geometry.normal;
1212
backGeometry.viewDir = geometry.viewDir;
1313
1414
vLightFront = vec3( 0.0 );
15-
16-
#if defined (USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0
17-
vAmbientLightFront = vec3( 0.0 );
18-
#endif
15+
vIndirectFront = vec3( 0.0 );
1916
2017
#ifdef DOUBLE_SIDED
2118
vLightBack = vec3( 0.0 );
22-
#if defined(USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0
23-
vAmbientLightBack = vec3( 0.0 );
24-
#endif
19+
vIndirectBack = vec3( 0.0 );
2520
#endif
2621
2722
IncidentLight directLight;
@@ -110,19 +105,11 @@ vec3 directLightColor_Diffuse;
110105
#pragma unroll_loop
111106
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
112107
113-
#ifdef USE_SHADOWMAP
114-
vAmbientLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );
115-
#else
116-
vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );
117-
#endif
108+
vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );
118109
119110
#ifdef DOUBLE_SIDED
120111
121-
#ifdef USE_SHADOWMAP
122-
vAmbientLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );
123-
#else
124-
vLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );
125-
#endif
112+
vIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );
126113
127114
#endif
128115

src/renderers/shaders/ShaderLib/meshlambert_frag.glsl.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ uniform vec3 emissive;
44
uniform float opacity;
55
66
varying vec3 vLightFront;
7-
#if defined(USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0
8-
varying vec3 vAmbientLightFront;
9-
#endif
7+
varying vec3 vIndirectFront;
108
119
#ifdef DOUBLE_SIDED
1210
varying vec3 vLightBack;
13-
#if defined(USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0
14-
varying vec3 vAmbientLightBack;
15-
#endif
11+
varying vec3 vIndirectBack;
1612
#endif
1713
1814
@@ -56,16 +52,14 @@ void main() {
5652
// accumulation
5753
reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );
5854
59-
#if defined(USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0
60-
#ifdef DOUBLE_SIDED
55+
#ifdef DOUBLE_SIDED
6156
62-
reflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vAmbientLightFront : vAmbientLightBack;
57+
reflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;
6358
64-
#else
59+
#else
6560
66-
reflectedLight.indirectDiffuse += vAmbientLightFront;
61+
reflectedLight.indirectDiffuse += vIndirectFront;
6762
68-
#endif
6963
#endif
7064
7165
#include <lightmap_fragment>

src/renderers/shaders/ShaderLib/meshlambert_vert.glsl.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ export default /* glsl */`
22
#define LAMBERT
33
44
varying vec3 vLightFront;
5-
#if defined(USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0
6-
varying vec3 vAmbientLightFront;
7-
#endif
5+
varying vec3 vIndirectFront;
86
97
#ifdef DOUBLE_SIDED
108
varying vec3 vLightBack;
11-
#if defined(USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0
12-
varying vec3 vAmbientLightBack;
13-
#endif
9+
varying vec3 vIndirectBack;
1410
#endif
1511
1612
#include <common>
@@ -51,6 +47,5 @@ void main() {
5147
#include <lights_lambert_vertex>
5248
#include <shadowmap_vertex>
5349
#include <fog_vertex>
54-
5550
}
5651
`;

0 commit comments

Comments
 (0)