God Rays

Simulate volumetric light rays shining through objects in the scene.

The GodRays effect is part of the postprocessing package. It simulates the appearance of light rays shining through objects, creating a volumetric lighting effect. This effect can enhance the visual appeal of your scene by adding a dramatic and realistic lighting effect.

Usage

The <GodRaysPmndrs> component is easy to use and provides customizable options to suit different visual styles.

<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { NoToneMapping } from 'three'
import { EffectComposerPmndrs, GodRaysPmndrs } from '@tresjs/post-processing'

const gl = {
  toneMapping: NoToneMapping,
}

const sphereMeshRef = ref(null)

const effectProps = {
  opacity: 0.8,
  exposure: 0.8,
  resolutionScale: 0.65,
}
</script>

<template>
  <TresCanvas v-bind="gl">
    <TresPerspectiveCamera :position="[5, 5, 5]" />

    <!-- The lightSource (in this case a Sphere) -->
    <TresMesh ref="sphereMeshRef" :position="[-10, 8, 0]">
      <TresSphereGeometry :args="[2, 32, 32]" />
      <TresMeshBasicMaterial color="#FFDDAA" :transparent="true" />
    </TresMesh>

    <Suspense>
      <EffectComposerPmndrs>
        <GodRaysPmndrs
          v-bind="effectProps"
          :light-source="sphereMeshRef"
        />
      </EffectComposerPmndrs>
    </Suspense>
  </TresCanvas>
</template>

Props

PropDescriptionDefault
blendFunctionDefines how the effect blends with the original scene. See the BlendFunction options.BlendFunction.SCREEN
lightSourceThe light source. Must not write depth and has to be flagged as transparent. This can be a Mesh or a Points.undefined
opacityThe opacity of the God Rays.1.0
densityThe density of the light rays.0.96
decayThe decay of the light rays.0.9
kernelSizeThe blur kernel size. Has no effect if blur prop is disabled. See the KernelSize options.KernelSize.SMALL
resolutionScaleThe resolution scale.0.5
blurWhether the god rays should be blurred to reduce artifacts.true
resolutionXThe horizontal resolution.Resolution.AUTO_SIZE
resolutionYThe vertical resolution.Resolution.AUTO_SIZE
weightThe weight of the light rays.0.4
exposureA constant attenuation coefficient.0.6
samplesThe number of samples per pixel.60
clampMaxAn upper bound for the saturation of the overall effect.1.0

Further Reading

For more details, see the GodRaysEffect documentation.