Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shader Replacement Problems .. :/

Discussion in 'Shaders' started by Hjeldnes, Jul 25, 2013.

  1. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    Hello!

    I'm working on a bloom shader, where you bloom the screen based on a specific texture (not a treshold).

    I have the blurring and blooming part working fine, but I just can't get replacement shaders to work. I either only get the backdrop, or it looks like the replacement shader is not used.

    I understood I can simply set
    camera.SetReplacementShader(shader, null); and it will render all objects in the scene with the specified shader?
    I tested this with a superbasic scene, just trying to replace the default shader with one that just draws red. But no success.

    Do I need to setup a new camera to render the replacement shader, or can I use the existing one.

    Any input would be greatly appreciated.

    Thanks a lot.
     
  2. wdcstudios

    wdcstudios

    Joined:
    Apr 18, 2011
    Posts:
    11
    You may need to include a game object in your scene with your custom shader assigned. I handle writing the shaders on the art side and I remember the programmer/developer having a simular issue with a custom shader I wrote. He said unity just saw the shader as an unused asset and didn't include it in the build until he put a cube in one of the scenes with the shader assigned. Maybe you have the same issue
     
  3. psantoki

    psantoki

    Joined:
    Oct 24, 2012
    Posts:
    17
    Hi Hjeldnes

    Same problem here.

    Here's an article that includes a shader and code that demonstrates SetSceneViewShaderReplace actually not failing. Caveat is that only the shader provided works--if I use any other shader, even a shader that provably works, SetSceneViewShaderReplace will not accept it.
    http://blogs.unity3d.com/2013/03/15/4-1-graphics-features/

    The Unity code for shader replacement seems almost completely broken, or is so esoteric and finicky that no one understands why it doesn't work (you "just get the backdrop", meaning nothing is drawing). The documentation is nonexistent.

    Some things in the Unity engine are just awful and because it's closed-source you are completely shafted. It's like a bike with training wheels permanently attached. And you can't even fix it. This feature would be trivial using an open source game engine. Anyway at least you have that article that shows one feeble path in. Good luck
     
  4. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    Thanks a lot guys! It really helps with a proper sample. :) And I will try to include the game object in scene as well. I just put the task on hold, but I guess now I can give it another go.

    kjetil