3D Occlusion cone with fading

Good afternoon community.

I have some problem to create an occlusion cone going from the camera to infinity with a fading on it’s edge.
Let’s me explain that with a picture ^^:

2611662--183110--upload_2016-4-26_17-57-16.png

This cone have a mesh collider, and if those red ball are inside they’re hidden ( GetComponent().enabled=false) than to a script. There is also a green sphere that have to be seen at all time (on the previous image it’s inside the cone).

So the actual rendering look like that :
2611662--183112--upload_2016-4-26_18-10-35.png

As my sphere are oscillating along the the z-axis, I have a glitter effect.
Of course my sphere leave the cone so appear, and then few millisecond later it’s back inside it and then hide.

I order to solve this I tried to use a black sphere in front of my camera (cf picture below).
The rendering is quite great as the sphere do not glitter anymore (they’re just hidden by the sphere), but my green sphere is at the same time hidden.

2611662--183114--upload_2016-4-26_18-16-26.png

— Problem –

My problems are the following ones : Basically found something that merge the two image ^^

    1. Is it possible to make this black sphere “invisible/clear” in order to let the light from the green sphere to come through.
      A shader will probably do the job but I do not how to code and use them.
    1. Is it possible to had a fading rather than a straight cut (in the second image) between the occulted area (dark area) and the other one.
    1. Is there is a way to make this cone goes to infinity ?

Than a lot for your help :slight_smile:

kosen

Up :slight_smile:

Have you tried using a custom pixel shader with fading according to the camera space position?

thanks for your reply :slight_smile:

Unfortunately I don’t know how to do that :-(.
Could you link me to some resources where I can learn to do that.

Actually I’m going through those post as they seem to cover some point of my pbm :

I don’t exactly get how you’re planning to do the fading.

in you shader you can do something like

float distanceFromCenter = distance( screenSpacePosition.xy * screenSpacePosition.z, 0.5f) * 2.0f; // gives a gradient from black at screen center to white on borders
const float fadeThickness = 0.05f; // make parameters
const float fadeDistance = 0.5f; // make parameters
float transparency = smoothstep( fadeDistance + fadeThickness, fadeDistance - fadeThickness, distanceFromCenter);

then simply multiply your alpha value by transparency and it should do it :slight_smile: