5.13.0

Mesh Reflection Material

Makes floors or walls that reflect the objects in your Scene.

The cientos package provides a <MeshReflectionMaterial /> component for making floors or walls that reflect the objects in your Scene.

The component is based on the excellent component of the same name.

It extends THREE.MeshStandardMaterial and accepts all the same props.

Usage

<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { MeshReflectionMaterial } from '@tresjs/cientos'
</script>

<template>
  <TresCanvas>
    <TresPerspectiveCamera :position="[3, 3, 3]" :look-at="[0, 0, 0]" />
    <TresMesh :rotation="[-Math.PI / 2, 0, 0]">
      <TresPlaneGeometry :args="[10, 10]" />
      <MeshReflectionMaterial
        :blur="[300, 100]"
        :mixBlur="30"
        :mixStrength="80"
        :mixContrast="1"
        color="#a0a0a0"
        metalness="0.5"
        roughness="1"
        mirror="0"
      />
    </TresMesh>
    <TresMesh :position="[0, 1, 0]">
      <TresBoxGeometry />
      <TresMeshStandardMaterial color="orange" />
    </TresMesh>
    <TresAmbientLight />
    <TresDirectionalLight :position="[0, 2, 4]" />
  </TresCanvas>
</template>

Props

NameDescriptionDefault
resolutionLength in pixels of one side of the square reflective textures256
mixOverall strength of the reflection1
sharpMixStrength of the sharp reflection on smooth surfaces1
sharpDepthScaleSharp reflection can be faded out by depth – distance from the reflective surface. 0 turns the fade off1
sharpDepthBiasSharp reflection depth falloff bias0
sharpDepthEdgeMinSharp reflection depth falloff start0
sharpDepthEdgeMaxSharp reflection depth falloff end0.2
blurMixSmoothStrength of the blurred reflection on smooth surfaces1
blurMixRoughStrength of the blurred reflection on rough surfaces1
blurDepthScaleBlurred reflection can spread out by depth – distance from the reflective surface. 0 turns the spread off1
blurDepthBiasBlurred reflection depth spread bias0
blurDepthEdgeMinBlurred reflection depth spread start0
blurDepthEdgeMaxBlurred reflection depth spread end0.2
blurSizeSize of the blur. If [number, number], first number is width, second is height[0, 0]
distortionMapTexture for offsetting the reflectionundefined
distortionInfluence of distortionMap0
reflectorOffsetOffsets the reflection0

The component renders a depth texture and runs the blur pass every frame. A depth scale of 0 turns off the effect in the shader, but not the render work.

The component does not support reversedDepthBuffer. It logs a warning and renders no reflection.

Additionally, the component extends THREE.MeshStandardMaterial and accepts all the same props including color, roughness, metalness, map, normalMap, roughnessMap, metalnessMap, and more.

WebGPU

Import MeshReflectionMaterial from @tresjs/cientos/webgpu on a TresCanvas from @tresjs/core/webgpu. That version extends MeshStandardNodeMaterial, renders into a generic RenderTarget and has the same props. See WebGPU.

On WebGPU, blurSize, the depth scales and distortionMap are uniforms, so switching them on or off does not recompile the shader. A change to a texture map, such as normalMap or roughnessMap, still recompiles it. The material does not remount in either case.