Search Unity

Create a shader that affects all objects within a sphere mesh instead of only objects behind it?

Discussion in 'Shaders' started by AdamAdams, Mar 18, 2018.

  1. AdamAdams

    AdamAdams

    Joined:
    Feb 10, 2018
    Posts:
    3
    Preface: I am relatively new to shaders. First post here so I hope this is fine. I am trying to do this for VRChat, so I can't use scripting for it and I can't attach a shader to the camera.

    =

    ( 1 ) I have a sphere mesh. I stand outside the sphere. In this example, the shader sees what is behind the sphere and alters its color. Maybe it makes what is behind it slightly redder, or blue like it is underwater, or maybe it inverts the colors. If I look at this sphere from the outside then anything inside of the sphere or directly behind the sphere will appear to be affected by the shader.

    ( 2 ) I now move inside of the sphere. I flip the normals of the sphere thru blender (or some other method) and apply the shader once again. When I look outward, now everything on the OUTSIDE of the sphere appears to be affected. Now, everything on the outside appears reddish (or blue-ish, etc).

    ( 3 ) My problem is that if I am within the sphere, nothing else within the sphere is affected. I am looking for a way or method or format to apply the current shader to everything within the sphere mesh // everything within a given area while still myself being inside of that area. Or at least give the illusion that this is happening.


    Details:
    -I need it like this because any number of players can walk in from any direction into the area and it needs to be able to affect everyone the same as long as they are nearby
    -I could use a light source but as far as I know setting (for example) a red light in the center of the sphere has issues with shadows and other things; unless it is possible to apply shaders to light sources to do a fancy thing?
    -I assume it would have to do with Grab Pass reading what the camera sees and rendering a recolored version over it all, but I'm not sure how to make it work the way I described it
    -In an ideal world, I get this figured out and can then tweak the code to use effects I want it to, for example to swap out a red shader for blue or for a color inverter or distortion etc

    I have been trying to get this working for 2+ weeks and I've found a lot of cool things but nothing for this specifically. I would be grateful for any link to a page that talks about this, or video tutorials on it, or example shader code, or name of what this is called so I can search it properly (searching for this is a real nightmare), etc etc.

    ====

    edit: I have found my solution; adding "Ztest always" just below {SubShader} and bumping up the render queue a bit higher than 3000 makes the shader render the sphere stuff last and over everything else.
     
    Last edited: Mar 20, 2018