Search Unity

Odd Screenbuffer bug with instantiated prefab

Discussion in 'Shaders' started by cthomas1970, Dec 7, 2018.

  1. cthomas1970

    cthomas1970

    Joined:
    Sep 12, 2017
    Posts:
    75
    I have created a shader, using ShaderForge, that fakes Refraction using the screen buffer, warped using the surface normal of the object. This has been working well until now. And produces a pretty good refraction effect, even when two objects using the same shader overlap. Z-Depth is working fine, and the visual warping is good. Objects using this shader dropped into scenes from prefabs work just fine.

    Here is a dropbox link, for an image, showing red gems, seen through a glass marble. The same shader is used on both. Note the gems are distorted by the refraction effect.
    https://www.dropbox.com/s/kg2e917jtzhkd86/Refraction_Correct.JPG?dl=0

    However, I have now started instantiating the exact same Prefabs that use this shader, and I get a very odd bug. The shader, when seen through another object using the same shader, appears unwarped. Its as if the instantiated objects are not being treated in the same way as objects of the same prefab that are loaded via a scene.

    Here the exact same gem prefab is seen through the same glass marble, here the gem is instantiated. Note that although it is behind the marble, it is NOT distorted in this case.
    https://www.dropbox.com/s/mzxa0g7v41lmm3y/Refraction_InCorrect.JPG?dl=0

    Why would the same prefab loaded in a scene, act differently when instantiated post scene load?