Skip to content

Instantly share code, notes, and snippets.

@seantai
Created July 9, 2024 20:56
Show Gist options
  • Save seantai/4b84ef9778e4c627aadaaf972e0914cf to your computer and use it in GitHub Desktop.
Save seantai/4b84ef9778e4c627aadaaf972e0914cf to your computer and use it in GitHub Desktop.
const uniforms = useRef(null)
useFrame(({ clock }) => {
if (!uniforms.current) return
uniforms.current.u_color.value.y = Math.sin(clock.elapsedTime * 2)
})
return (
<mesh geometry={Suz.nodes.geometry}>
<meshNormalMaterial
onBeforeCompile={(shader) => {
shader.uniforms.u_color = { value: new Vector3(0.2, 0, 0.02) }
shader.fragmentShader = 'uniform vec3 u_color;\n' + shader.fragmentShader
shader.fragmentShader = shader.fragmentShader.replace(' normal ', ' normal * u_color')
uniforms.current = shader.uniforms
}}
/>
</mesh>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment