Possible to Cast Ray from Camera in Shader?

I kinda want to detect areas of the surface that is only visible to the camera (or from a certain vector).

Sort of like how shadows are computed.
Is this possible?

334658-shadowing.png

Green: Visible

Red: Not visible

Fresnel is close, but it will still shade the back parts even if it is being blocked by itself (self shadowing)

Like this:

334683-camfacing.gif

Hi! thank you so much for the reply! I appreciate it.
Although looking at your graph, this is very similar to how fresnel is being computed. :frowning:
Sadly, it will still shade the occluded polygons behind.

334684-occluded.png

For now, closest function i can think of is a Ray function from the camera, where it should be able to mark hit pixels facing it.

What is this for?

I’m experimenting with a way to render 3D smoke geometry to look like 2D.
But also want it to dissolve with a hard edge (not soft gradient). You typically would see this on 2d hand drawn VFX like this:

https://cdn.dribbble.com/users/637323/screenshots/3406359/philipvonborries_explosion02.gif

So far, i have a look going that i’m semi-happy with.

334688-smoke-01.png

So for now, I proceeded to the part where it would fade out.
But, by animating the opacity, it tends to show the surfaces behind it.

334689-smoke-fade.png

Thus, a solution i was thinking of is to first hide the surfaces behind that are actually occluded from the camera view. This way, i could have more or less a cleaner looking dissipation of the 2d smoke.

Hmmm, tricky.

Rather than changing opacity, it might be an idea to just animate the smoke away ( the puffs become smaller and move away or something ). Then you don’t have this problem.

Is this one puff, or is it multiple puff? You might be able to so something with actor occlusion if the 2nd…

Yes, quite tricky indeed. I might hammer away with this a bit more. Shaders is so much fun (for now lol)
But i’ll also be looking at other options haha

Currently it’s a single mesh as i’m planning to bake out vertex animation for it.
I’ll consider checking on actor occlusion if i do end up separating the puffs.
Thanks for the tip!

This post seems to be about the same thing. It’s a bit of a ‘mare’…

https://forums.unrealengine.com/development-discussion/rendering/71863-check-if-pixel-is-occluded-with-depth-mask

Thanks for the link! That was a very interesting thread, i will need to read thru it multiple times in order to absorb the details haha
But so far, it gave me an idea to experiment in the direction of using captures and render targets. Hopefully the approach could help with what i’m trying to achieve. If not, i’ll chunk it to experience :slight_smile: