5.8.1

Mesh Transmission Material

A glass-like transmission material with chromatic aberration, distortion, and backside support. Ported from drei.

The cientos package provides a <MeshTransmissionMaterial /> component that produces high-quality glass and transmission effects.

The material renders the scene into a buffer texture each frame to simulate refraction, chromatic aberration, distortion, and anisotropic blur, effects that <TresMeshPhysicalMaterial> alone cannot achieve.

This component is a port of the drei MeshTransmissionMaterial. All credit goes to the original authors.

Usage

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

<template>
  <TresCanvas>
    <TresPerspectiveCamera :position="[0, 0, 5]" />
    <Environment preset="city" />
    <TresMesh>
      <TresTorusKnotGeometry :args="[1, 0.3, 128, 32]" />
      <MeshTransmissionMaterial
        :transmission="1"
        :thickness="0.5"
        :chromatic-aberration="0.03"
        :resolution="512"
      />
    </TresMesh>
  </TresCanvas>
</template>

Props

PropDescriptionTypeDefault
transmissionGlass opacity (maps to the internal _transmission uniform)number1
thicknessThickness of the glass volumenumber0
roughnessSurface roughnessnumber0
chromaticAberrationChromatic aberration intensitynumber0.03
anisotropicBlurAnisotropic blur amountnumber0.1
distortionDistortion amountnumber0
distortionScaleScale of the distortion noisenumber0.5
temporalDistortionAnimates the distortion over timenumber0
iorIndex of refractionnumber1.5
colorBase color of the glassTresColorwhite
clearcoatClearcoat layer intensitynumber0
clearcoatRoughnessClearcoat roughnessnumber0
attenuationDistanceDistance at which light is attenuated through the volumenumberInfinity
attenuationColorColor the light shifts to as it passes through the volumeTresColorwhite
backsideRender back faces into a separate buffer for proper glass thicknessbooleanfalse
backsideThicknessThickness used during the backside passnumber0
resolutionResolution of the FBO render target in pixelsnumber256
backsideResolutionResolution of the backside FBO. Defaults to resolutionnumberresolution
backgroundOverride the scene background during the FBO passTHREE.Color | nullundefined
bufferSupply your own render-target texture, skipping the internal FBO passTHREE.Texture | nullundefined
samplesNumber of refraction samples. Baked at compile time — changing requires remount.number6
transmissionSamplerUse THREE's built-in transmission sampler instead of an FBO pass. Baked at compile time.booleanfalse

The component extends THREE.MeshPhysicalMaterial and accepts all the same props.

Tips

  • An <Environment> or envMap on the scene is strongly recommended. Without one, the material will render dark.
  • samples and transmissionSampler are baked into the shader at compile time. Changing them at runtime triggers a remount automatically.
  • Enable backside with a non-zero backsideThickness for more convincing thick-glass effects.
  • Lower resolution (e.g. 128) improves performance at the cost of refraction sharpness.