I’d like to share a water shader that might be useful when rendering scenes with NPR-techniques. The great thing about this code is the ability to detect obstacles in the water and then render a nice foam around them. I’ve seen this effect in Unity some time ago and I though it would be useful to have this in three.js.
The shader should work with perspective and orthographic cameras, it supports output encoding, inline tonemapping and fog and is much faster than the (more realistic) water shaders of the official repo.
Looks very nice, the illusion is broken when you move the camera around, you really need a depth buffer perpendicular to water plane to figure out where the edges are, I have a much less good looking shader in Might is Right that simulates the shore-line (foam, whatever) - I use the inverse of terrain height-map to figure out where the shore is.
I get that that’s extra processing in general, so maybe not suitable for everyone.
Really like it! Feel there are many more uses for it other than just water, after tweaking your settings a bit I could see it being useful for other effects like heat waves coming off of an object.
Very cool stuff, really enjoy the cartoon look too!
Of course it’s a matter of taste. I’ve just implemented the style of the Untiy showcase where the foam is white and only visible at the intersection points:
Next level achieved! The waterfall has now a nice particle effect based on THREE.InstancedMesh and MeshBasicMaterial enhanced with a simple dissolve shader.
Looks sweet!
Will definitely try it out with a bloom pass when I have some time.
Arent sprite billboards way more popular as particles? I feel like most p systems make great uses of alpha textures.
It obviously depends on the case, but what do you think? What are the adventages of using THREE.InstancedMesh for particles? Or rather which effects would be better suited for it, instead of billboards?
The waterfall’s particle system uses spheres (THREE.SphereBufferGeometry) for its foam. So a geometry rendered with gl.TRIANGLES instead of gl.POINTS. You can’t achieve the same volumetric effect with a 2D primitive. Check out the volumetric particles here:
It would be obviously bad to render each particle with a single draw call. That’s not an issue when rendering points but when rendering meshes. Using instanced rendering solves this issue.
I guess the 3D shape is the obvious point (pun unintended ). I was just trying to come up with different uses for gl.TRIANGLES type particles and Im failing miserably
My job has twitter blocked but I’ll make sure to check it out later. I’ll try to look up some more volumetric effects as well.
Thanks for the resources!
thx this helps a lot,
still have some problems with the DepthMap if objects are moving
the idea was only use the Terrain object3d for the target Render pass like
const terrain = scene.getObjectByName(“Terrain”)
renderer.setRenderTarget( this.target );
renderer.render( terrain, camera );
renderer.setRenderTarget( null );
this works, but slow because i cannot set the overrideMaterial ?
I’ve been fiddling with the sandbox a while, but can’t seem to understand how the water can be scaled up to. say - 100, 100. It just stretches the shader
What does it look like from a top-down perspective?
I assume this is using the depth-buffer to determine where foam should be placed, in which case it will only show on the parts that the camera actually faces (underwater), meaning 2 directions never have foam.
I’m asking because I’ve been struggling with this a couple of weeks ago
@Mugen87 I referred to the method of obtaining the depth map in your demo,since I need to get the depth map of the entire scene ,so I don’t need to hide anything,But this leads to a problem. When I don’t use overrideMaterial only use THREE.DepthTexture, I get a warning(Feedback loop formed between Framebuffer and active Texture) that interrupts rendering. Can you explain to me why this warning appears?