layerMaterial.js
This file
Path
examples/demo/src/materials/layerMaterial.js
45 lines · 1.4 KiB · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than f85898f point at it.
chore(eslint.config.mjs): update 'eslint-plugin-react-hooks', 'eslint-plugin-react-compiler' config (#3043)Wonsuk Choibefore adoptionf85898f
lines 1–45why, one step back1import { shaderMaterial } from '@react-three/drei'2import { extend } from '@react-three/fiber'34// This material takes care of wiggling and punches a hole into5// alpha regions so that the depth-of-field effect can process the layers.6// Credit: Gianmarco Simone https://twitter.com/ggsimm78const LayerMaterial = shaderMaterial(9 { textr: null, movement: [0, 0, 0], scale: 1, factor: 0, wiggle: 0, time: 0 },10 ` uniform float time;11 uniform vec2 resolution;12 uniform float wiggle;13 varying vec2 vUv;14 varying vec3 vNormal;15 void main() {16 vUv = uv;17 vec3 transformed = vec3(position);18 if (wiggle > 0.) {19 float theta = sin(time + position.y) / 2.0 * wiggle;20 float c = cos(theta);21 float s = sin(theta);22 mat3 m = mat3(c, 0, s, 0, 1, 0, -s, 0, c);23 transformed = transformed * m;24 vNormal = vNormal * m;25 }26 gl_Position = projectionMatrix * modelViewMatrix * vec4(transformed, 1.);27 }`,28 ` uniform float time;29 uniform vec2 resolution;30 uniform float factor;31 uniform float scale;32 uniform vec3 movement;33 uniform sampler2D textr;34 varying vec2 vUv;35 void main() {36 vec2 uv = vUv / scale + movement.xy * factor;37 vec4 color = texture2D(textr, uv);38 if (color.a < 0.1) discard;39 gl_FragColor = vec4(color.rgb, .1);40 #include <tonemapping_fragment>41 #include <colorspace_fragment>42 }`,43)4445extend({ LayerMaterial })