First, thank you so much for this great work and community.
I am trying to write a simple low poly style water material.
I know there are different ways of writing this kind of thing, and I would like as much as possible to do it in a js script (I come from C# dev', and I am not super comfy with frontend yet).
The one way I can understand after hours of compiling infos on the Net is this one:
var waterVertexShader =
"attribute float vertexDisplacement;" +
"uniform float time;" +
"varying vec3 vUv;" +
"void main() {" +
" vUv = position;" +
" vUv.y += sin(time) * 0.01;" +
" gl_Position = projectionMatrix * modelViewMatrix * vec4(vUv, 1.0);"+
"}"
;
var waterFragmentShader =
"void main() {" +
"gl_FragColor = vec4(0.65, 0.88, 1, 1);" +
"}";
},
flatShading : true,
vertexShader: waterVertexShader,
That gives me the beginning of the wanted behavior, but this is not my issue.
Now, if I want to inherit let's say the Lambert or Phong material properties, what is the right way to proceed?
It sounds very basic, but this is the only relevant link I found: ThreeJS - Extend Lambert Shader with Custom VertexShader and there is no answer.
Thank you for your attention.
There are several ways to enhance a built-in material in three.js
:
RawShaderMaterial
or ShaderMaterial
from scratch and reuse the existing shader chunks from the library. This approach is very flexible but it requires good knowledge about the internals of three.js
's material system.NodeMaterial
. However, this technique is not documented and no part of the core so far. There are some examples that demonstrate the usage like this one.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With