Search Unity

Shader World Space

Discussion in 'Shaders' started by Xurupitinha, May 26, 2017.

  1. Xurupitinha

    Xurupitinha

    Joined:
    May 25, 2017
    Posts:
    1
    Can someone help me, I'm trying to make a shader that the sphere changes color according to the color of the wall when it gets close to it. I looked for several tutorials and found none to help me.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    What you're talking about is essentially the same thing as real time global illumination. The wall and the sphere know almost nothing about each other unless there's another system that exists to pass that information. Generally this is something handled well before an object gets rendered, so isn't going to be something you can do with just a shader.

    Now there are a bunch of ways you could handle this.

    You could construct a 3D texture that the sphere uses to determine the color it needs to be, which basically requires you learn how to voxelize the scene, which is non-trivial.

    You could do raycasts in c# to find the closest point(s) of the cube mesh and either read the texture color in script, or pass the cube mesh's UVs at that location to the sphere if it's just a texture.

    If the cube's color is determined by a works space position then you could do the same calculations for the sphere's shader.

    You could abuse Unity's lighting system and make your cube static and use an emissive material and place light probes in your scene.

    There's a hundred other ways to go about this depending on the complexity of what you need.