Issue with shaderMaterial #433
marekalgoud
started this conversation in
General
Replies: 1 comment 2 replies
-
then it looks like you cant share shaders in threejs. it's probably enough to do: const shader = useMemo(() => ({ ... CustomShader }), [])
return <shaderMaterial args={[CustomShader]} /> personally i like to create shaders like this: https://codesandbox.io/s/r3f-shader-material-0b2b0?file=/src/ColorMaterial.js import * as THREE from "three"
import { extend } from "react-three-fiber"
class CustomMaterial extends THREE.ShaderMaterial {
constructor() {
super({
uniforms: { color: { value: new THREE.Color("white") } },
vertexShader: `...`,
fragmentShader: `...`
})
}
get color() {
return this.uniforms.color.value
}
}
extend({ CustomMaterial }) and then <mesh>
<planeBufferGeometry attach="geometry" />
<customMaterial attach="material" color="hotpink" /> that takes care of the uniforms problem, and you get to define real props that you can alter declaratively. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm learning shaders, so I tried to make a really simple one. The goal is to change the color of a cone depending of the normal. My shader works pretty well, but I have a strange behavior : I use uniforms to pass a color to the sader. If I have 3 differents cone in my App, but the color of the first is applied to all the others... I don't understand why the uniforms are shared beetween them.
Here's the code :
the shader :
the 'Cone' :
and in my app :
Many thanks for your help and for your works !
Beta Was this translation helpful? Give feedback.
All reactions