@@ -4,8 +4,9 @@ import { GodRaysEffect } from 'postprocessing'
44import { makePropWatchers } from ' ../../util/prop'
55import { useEffectPmndrs } from ' ./composables/useEffectPmndrs'
66import { 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'
910
1011export interface GodRaysPmndrsProps {
1112 /**
@@ -16,7 +17,7 @@ export interface GodRaysPmndrsProps {
1617 /**
1718 * The light source. Must not write depth and has to be flagged as transparent.
1819 */
19- lightSource? : Mesh | Points
20+ lightSource? : Mesh | Points | null
2021
2122 /**
2223 * The opacity of the God Rays.
@@ -83,8 +84,15 @@ const props = defineProps<GodRaysPmndrsProps>()
8384
8485const { camera } = useTresContext ()
8586
87+ const resolvedLightSource = computed (() =>
88+ props .lightSource ?? new Mesh (
89+ new SphereGeometry (0.00001 ),
90+ new MeshBasicMaterial ({ visible: false }),
91+ ),
92+ )
93+
8694const { pass, effect } = useEffectPmndrs (
87- () => new GodRaysEffect (camera .value , toRaw ( props . lightSource ) , props ),
95+ () => new GodRaysEffect (camera .value , resolvedLightSource . value , props ),
8896 props ,
8997)
9098
@@ -102,21 +110,34 @@ makePropWatchers(
102110 [() => props .resolutionScale , ' resolution.scale' ],
103111 [() => props .resolutionX , ' resolution.width' ],
104112 [() => props .resolutionY , ' resolution.height' ],
105- [() => props .kernelSize , ' kernelSize' ],
106- [() => props .blur , ' blur ' ],
113+ [() => props .kernelSize , ' blurPass. kernelSize' ],
114+ [() => props .blur , ' blurPass.enabled ' ],
107115 ],
108116 effect ,
109117 () => new GodRaysEffect (),
110118)
111119
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+
112130watch (
113131 [() => props .opacity ],
114132 () => {
115133 if (props .opacity !== undefined ) {
116134 effect .value ?.blendMode .setOpacity (props .opacity )
117135 }
118136 else {
119- const plainEffect = new GodRaysEffect (camera .value , toRaw (props .lightSource ))
137+ const plainEffect = new GodRaysEffect (
138+ camera .value ,
139+ toRaw (resolvedLightSource .value ),
140+ )
120141 effect .value ?.blendMode .setOpacity (plainEffect .blendMode .getOpacity ())
121142 plainEffect .dispose ()
122143 }
0 commit comments