Skip to content

Commit fc55d16

Browse files
authored
fix: integrate fog support into SpotLightMaterial shader (#80)
1 parent 9816a31 commit fc55d16

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/materials/SpotLightMaterial.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color, Vector2, Vector3, type Texture } from 'three'
1+
import { Color, Vector2, Vector3, type Texture, UniformsLib, UniformsUtils } from 'three'
22
import { shaderMaterial } from '../core/shaderMaterial'
33
import { version } from '../helpers/constants'
44

@@ -37,10 +37,15 @@ export const SpotLightMaterial = shaderMaterial<SpotLightMaterialProps>(
3737
uniform vec3 spotPosition;
3838
uniform float attenuation;
3939
40+
#include <fog_pars_vertex>
4041
#include <common>
4142
#include <logdepthbuf_pars_vertex>
42-
43+
4344
void main() {
45+
#include <begin_vertex>
46+
#include <project_vertex>
47+
#include <fog_vertex>
48+
4449
// compute intensity
4550
vNormal = normalize(normalMatrix * normal);
4651
vec4 worldPosition = modelMatrix * vec4(position, 1);
@@ -66,6 +71,7 @@ export const SpotLightMaterial = shaderMaterial<SpotLightMaterialProps>(
6671
uniform float cameraFar;
6772
uniform float opacity;
6873
74+
#include <fog_pars_fragment>
6975
#include <packing>
7076
#include <logdepthbuf_pars_fragment>
7177
@@ -100,5 +106,9 @@ export const SpotLightMaterial = shaderMaterial<SpotLightMaterialProps>(
100106
101107
#include <tonemapping_fragment>
102108
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
103-
}`
109+
#include <fog_fragment>
110+
}`,
111+
(material) => {
112+
Object.assign(material.uniforms, UniformsUtils.merge([UniformsLib['fog']]))
113+
}
104114
)

0 commit comments

Comments
 (0)