@@ -4,8 +4,9 @@ import { GodRaysEffect } from 'postprocessing'
4
4
import { makePropWatchers } from ' ../../util/prop'
5
5
import { useEffectPmndrs } from ' ./composables/useEffectPmndrs'
6
6
import { useTresContext } from ' @tresjs/core'
7
- import { toRaw , watch } from ' vue'
8
- import type { Mesh , Points } from ' three'
7
+ import { computed , toRaw , watch } from ' vue'
8
+ import type { Points } from ' three'
9
+ import { Mesh , MeshBasicMaterial , SphereGeometry } from ' three'
9
10
10
11
export interface GodRaysPmndrsProps {
11
12
/**
@@ -16,7 +17,7 @@ export interface GodRaysPmndrsProps {
16
17
/**
17
18
* The light source. Must not write depth and has to be flagged as transparent.
18
19
*/
19
- lightSource? : Mesh | Points
20
+ lightSource? : Mesh | Points | null
20
21
21
22
/**
22
23
* The opacity of the God Rays.
@@ -83,8 +84,15 @@ const props = defineProps<GodRaysPmndrsProps>()
83
84
84
85
const { camera } = useTresContext ()
85
86
87
+ const resolvedLightSource = computed (() =>
88
+ props .lightSource ?? new Mesh (
89
+ new SphereGeometry (0.00001 ),
90
+ new MeshBasicMaterial ({ visible: false }),
91
+ ),
92
+ )
93
+
86
94
const { pass, effect } = useEffectPmndrs (
87
- () => new GodRaysEffect (camera .value , toRaw ( props . lightSource ) , props ),
95
+ () => new GodRaysEffect (camera .value , resolvedLightSource . value , props ),
88
96
props ,
89
97
)
90
98
@@ -102,21 +110,34 @@ makePropWatchers(
102
110
[() => props .resolutionScale , ' resolution.scale' ],
103
111
[() => props .resolutionX , ' resolution.width' ],
104
112
[() => props .resolutionY , ' resolution.height' ],
105
- [() => props .kernelSize , ' kernelSize' ],
106
- [() => props .blur , ' blur ' ],
113
+ [() => props .kernelSize , ' blurPass. kernelSize' ],
114
+ [() => props .blur , ' blurPass.enabled ' ],
107
115
],
108
116
effect ,
109
117
() => new GodRaysEffect (),
110
118
)
111
119
120
+ watch (
121
+ [() => props .lightSource , effect ],
122
+ () => {
123
+ if (effect .value ) {
124
+ effect .value .lightSource = toRaw (resolvedLightSource .value )
125
+ }
126
+ },
127
+ { immediate: true },
128
+ )
129
+
112
130
watch (
113
131
[() => props .opacity ],
114
132
() => {
115
133
if (props .opacity !== undefined ) {
116
134
effect .value ?.blendMode .setOpacity (props .opacity )
117
135
}
118
136
else {
119
- const plainEffect = new GodRaysEffect (camera .value , toRaw (props .lightSource ))
137
+ const plainEffect = new GodRaysEffect (
138
+ camera .value ,
139
+ toRaw (resolvedLightSource .value ),
140
+ )
120
141
effect .value ?.blendMode .setOpacity (plainEffect .blendMode .getOpacity ())
121
142
plainEffect .dispose ()
122
143
}
0 commit comments