Hi, I have a problem with shaders. I need foamy water. I only found this code, but I don’t know how to use this code in WEBGL 2.0. I know that “WEBGL_depth_texture” is for WEBGL 1.0
Does anyone know how to rewrite this to work in webgl 2.0?
In WebGL2 things are different in shaders. Varying does not exist in WebGL2. You have to use “in” and “out”. You also have to set the “presicion” for the variable types used in the shader. And in the three.js code you have to use “glslVersion: THREE.GLSL3,” so that three.js knows that it is a WebGL2 shader. I turned the ShaderMaterial into a RawShaderMaterial because ShaderMaterial uses buildins that certainly won’t work with WebGL2. I can’t say whether my suggestions alone are enough, because codesandbox with the tablet is terrible. I can hardly select anything. Otherwise I would have tested it straight away.
Once you know these small differences, WebGL2 shaders hardly feel different than WebGL1. Personally, I haven’t used WebGL1 for a long time.
var waterMaterial = new THREE.RawShaderMaterial({
glslVersion: THREE.GLSL3,
defines: {
DEPTH_PACKING: supportsDepthTextureExtension === true ? 0 : 1,
ORTHOGRAPHIC_CAMERA: 0
},