The idea is to use functionality of clipping planes, with some modifications of the code for clipping Now it’s not clipping, but interpolation between values of 0 and the depth of fog, using distance from a point to the plane.
Looks fine when the camera is above the plane, but when it goes down below, then you can see what’s the trick.
UPD #1
The example that doesn’t break functionality of clipping planes:
It looks like function getFoggyMaterial simply extends MeshStandardMaterial… I don’t see a traverse method in the second pen, maybe I’m missing it, there’s a for loop that just creates a sphere and adds it to the scene each iteration…
it seems to create a material with an onBeforeCompile, if you had a model (say, GLTFLoader) i’m guessing you would have to traverse and apply oBC on each material, unless you change the prototype of all (?) materials, which would pose other problems since oBC is overwritten. this is what i meant with generic. with fog or fogexp2 it just works, no mesh or material has to be prepared in a specific way, i was hoping the same could be possible here.
this is tricky as in the example it is the actual material being affected by the fog itself, whereas ( afaiu ) fog and fogexp2 act like a dithered far clipping plane similar to the cameras clipping plane, whereby everything beyond a certain distance is simply swollowed by the fog itself…
i have tried my best to use @prisoner849’s example and extend MeshStandardMaterial similarly to how you have done with dreis MTM, see here…
and here’s a link to the MeshFoggyMaterial on github (excuse the file naming missmatch)…
this seems to work well but not sure how well it would stand up with the (const property in this) loop, this may need some expert attention to make fully workable with all properties of MeshStandardMaterial
i think the main hinderance is that in a real world project you have all kinds of materials, basic, standard, lambert, phong, physical, transmission, or any custom material. the inclusion of the fog import shader chunk should be enough for things to just work.
right yeah i see what you mean, i’m not sure what would be needed to replace parts of the MeshStandardMaterial’s THREE.ShaderChunk.clipping_planes_fragment and THREE.ShaderChunk.fog_fragment to make this work the way you suggest as both chunks are dependent on the planeFog float which is derived from one uniform… fPlane…