mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.95k stars 35.4k forks source link

Volumetric SpotLights #16147

Open sneha-belkhale opened 5 years ago

sneha-belkhale commented 5 years ago

Hey all,

I came across a cool and efficient implementation of volumetrics for spotlights -- and was able to achieve a pretty neat effect by using this approach paired with a noise texture and using multiple cones with decreasing radii.

Screen Shot 2019-04-04 at 1 10 29 PM

I think this could be helpful for people, as it is the only one i've seen that does not require multiple render passes. I think it's not fundamental enough to add to the THREE.Spotlight, but probably better for an example.

Let me know!

Usnul commented 5 years ago

I think it's really cool, the only problem is that for this technique to work - you need to sort your primitives (polygons that make up the cones), and that's one thing that WebGL doesn't do. Basically - you either have to sort the polygons yourself, or this technique won't work.

sneha-belkhale commented 5 years ago

@Usnul, for the demo above I was using additive blending. Also for this specific use case, the only reason there are multiple cones is so that it looks more full when you walk inside / underneath.

Usnul commented 5 years ago

You're right, for one cone it should work 👍

mrdoob commented 5 years ago

An example of this would be great indeed!

arpu commented 1 year ago

looks like this is the same https://github.com/jeromeetienne/threex.volumetricspotlight

arpu commented 1 year ago

found this https://codepen.io/tgcnzn/pen/OJWPEOj as example

mrdoob commented 1 year ago

Seems like @vis-prime is working on a solution for this: https://twitter.com/vis_prime/status/1635468289316114433

vis-prime commented 1 year ago

It's the same implementation

There's a cylinder mesh overlapping the spotlight It's material has the shader which does volume effect

and optionally depth map can be passed to prevent sharp intersection between the scene meshes and the cylinder mesh

It'll be available in drei-vanila library someday but for now here's a Demo and messy Code Camera is not locked here so you can get to know the limitations and strengths

based on r3f drei spotlight & demo

spot