5.10.1

Grid

Shader-based grid plane with customizable cell and section lines.

<Grid /> creates a shader-based grid plane. It has customizable grid cell and section lines, as well as fade out.

Usage

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

<template>
  <TresCanvas clear-color="#222222">
    <TresPerspectiveCamera :position="[8, 10, 10]" :fov="25" />
    <OrbitControls />
    <Grid
      :args="[10.5, 10.5]"
      cell-color="#82dbc5"
      :cell-size="0.6"
      :cell-thickness="0.5"
      section-color="#fbb03b"
      :section-size="2"
      :section-thickness="1.3"
      :infinite-grid="true"
      :fade-from="0"
      :fade-distance="12"
      :fade-strength="1"
    />
  </TresCanvas>
</template>

WebGPU

Import Grid from @tresjs/cientos/webgpu on a TresCanvas from @tresjs/core/webgpu. That version uses a TSL node material and has the same props. See WebGPU.

import { Grid } from '@tresjs/cientos/webgpu'

Thin lines can look a little brighter than with WebGLRenderer. WebGPURenderer blends transparent pixels in linear color space, and WebGLRenderer blends them in sRGB.

Props

PropDescriptionDefault
cellSizeCell size0.5
cellThicknessThickness of cell lines0.5
cellColorColor of cell lines'black'
sectionSizeSection size1
sectionThicknessThickness of section lines1
sectionColorColor of cell lines'blue'
followCameraWhether to follow camerafalse
infiniteGridWhether to display an infinite gridfalse
fadeDistanceFade distance100
fadeStrengthFade strength1
fadeFromFade from camera (1) or origin (0) or in between1
sideMaterial sideTHREE.BackSide