Volumes with space-dependent light intensity



ShaderToy’s search resulsts are very bad solved, they just load the entire stuff for every entry instead showing just thumbnails or generated gif’s. It frequently crashes in every browser and device.


Something related:


@MasterJames https://www.falstad.com/qmatom/ is exactly what I was looking for! Thank you very much! But I can’t accomplish the same results with ShaderMaterial. See this very little example custom_shader.html (2.6 KB). Transparency is intended in one side of the cube, but it completely blocks the color coming from the other side, so the desired effect is not feasible. I guess I’m not using ShaderMaterial in the right way… what do you think?


First off it’s much better to use something like JSFiddle to test and share this kind of thing.
here is your file maybe get an account and redo it there if you want.

I’m no expert in these matters of how to build what you want, but I’m glad you found that link enlightening.
My general thought was if there was a way to in the shader cast a second ray to the same scene with the object’s normals inverted you would potentially be able to calculate the distance the ray traverses through the body of a shape and then give it a weight/strength based on depth aka penetration length. The other cloud volume shaders examples on ShaderToy seem to be doing something like that (what you do want) but with shadows which you probably don’t want.


I hadn’t realized about JSFiddle, but yes, that’s the right way :sweat_smile: thanks!!


I had another thought that an inverted XRay shader might give the effect you want on basically spherical forms.

[select load xray from the menu]

Anyway if the surface normal is orthogonal or tangential to the camera you want it to be contributing nothing but when it’s pointing at the camera it would have the most color contribution, so an inversion of the xray might generate something that is similar to the depth when applied to mostly spherical forms.

Maybe one could even invert that xray resulting image with the post processing example?
No I think that would fall short.

I tried to find something more on this links follow.