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

How do you get replacementTag to work

Discussion in 'Scripting' started by monark, Jul 31, 2009.

  1. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    I'm trying unsuccessfully so far to use the replacementTag option when using a replacement shader. Unfortunately the help doesn't give any examples. It says

    However a tag is made up of a key and a value, I've tried supplying just the key and just the value and both but nothing seems to work.

    This is my replacement shader line

    Code (csharp):
    1. camera.SetReplacementShader (renderSceneShader, "VisibleInDepth=On");
    and this is my tag definition in the shader

    Code (csharp):
    1. Tags { "RenderType"="Opaque" "VisibleInDepth"="On"}
    How is this suppose to work?
     
  2. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    ok so i found an example that uses RenderType

    So this works
    Code (csharp):
    1. camera.SetReplacementShader (renderSceneShader, "RenderType");
    Therefore it looks like you supply the key not the value as it says in the help.

    But if I change it to my own tag key "VisibleInDepth" it doesn't work so it only seems to work with RenderType and not with your own tags. Is this a bug? or just a very annoying limitation?
     
    ModLunar likes this.
  3. DerWoDaSo

    DerWoDaSo

    Joined:
    May 25, 2009
    Posts:
    131
    Is there any solution to this? I have the same problem... ;)

    And another question: If I render from a cam with replacement shader, are there the shadows of ALL objects included? I ask, because when I use a culling mask it is not.
     
  4. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    Well I ended up using a work around, so I can;t shed any further light on it i'm afraid.
     
  5. DerWoDaSo

    DerWoDaSo

    Joined:
    May 25, 2009
    Posts:
    131
    Ah, I think I understand it now...

    Here is the shader from the FunkyGlowingThings Example:

    Code (csharp):
    1. Shader "Hidden/RenderFunkyThings" {
    2. SubShader {
    3.     Tags { "RenderType"="Funky" }
    4.     Pass {
    5.         Fog { Mode Off }       
    6.         Color (1,1,1,1)
    7.     }
    8. }
    9. SubShader {
    10.     Tags { "RenderType"="Opaque" }
    11.     Pass {
    12.         Fog { Mode Off }
    13.         Color (0,0,0,0)
    14.     }
    15. }
    16. }
    As you can see there are two subshaders.
    If you render the scene now with
    Code (csharp):
    1. camera.SetReplacementShader (renderSceneShader, "RenderType");
    Unity will check for all existing shaders in the scene, if they have a RenderType-Tag with either funky or Opaque and replace this very subshader with the one from the replacement shader.

    All shaders that DONT have a RenderType-tag set to funky or Opaque will be ignored.

    Didn't test it... but I will do now! :D
     
  6. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    I see, so you are saying you it just matches the tags in the replacement shader with the tag in the existing shader and swaps the ones that match.... that makes a lot of sense. If only the help had explained it that way.... :roll:
     
  7. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    I discovered strange behavior, like it was only ever doing the first SubShader.

    The resolution was to add a light to the scene. My scene doesn't use lights so I just set the light color to black.
     
  8. DerWoDaSo

    DerWoDaSo

    Joined:
    May 25, 2009
    Posts:
    131
    Did you check the LightMode-Tags? Maybe it's set to render only for Pixel and/or Vertex lights...

    For example if there is something like
    Code (csharp):
    1. Tags { "LightMode" = "Pixel" }
    try to change it to
    Code (csharp):
    1.  Tags { "LightMode" = "PixelOrNone" }
    Have a look at the documentation here:
    http://unity3d.com/support/documentation/Components/SL-PassTags.html
     
    Hunger720 and ilya_ca like this.
  9. badweasel

    badweasel

    Joined:
    Jan 11, 2015
    Posts:
    18
    Oh my God DerWoDaSo you're a life saver! I know it's been like 5 years since this was posted. But still I have to say in about 5 hours of searching for how freaking replacement shaders work this was the only thing that explains it.
     
    ModLunar likes this.
  10. rimberWearrus

    rimberWearrus

    Joined:
    Jul 28, 2017
    Posts:
    1
    I'm having the same issue with Unity always using the first SubShader regardless of what the tags are in it.
    This is rather annoying as I wanna create a generic shader that has multiple SubShaders that responds to different Replacement Shaders. Basically this "bug" renders my idea useless.

    Any Unity guys around to verify whether this is actually a bug or a wanted behaviour?
     
  11. chineseoldghost

    chineseoldghost

    Joined:
    Nov 28, 2017
    Posts:
    4
    upload_2017-12-18_15-24-1.png
    scene use shader with tag "rendertype=opaque",the tank body material shader with tag"rendertype=tank",close replacement shader in camera.

    setreplacementshader in camera,use a shader has two subshader:
    subshader0 set tag "rendertype= tank" not use diffuse texture but only purecolor red.
    subshader1 set tag"rendertype=opaque" same as standard shader.

    get this picture
    if remove subshader1, or set "RenderType" = "somethingelse" all scene like picture ,and no change
    upload_2017-12-18_15-27-23.png

    if change subshader1 not use diffuse texture but only purecolor red ,we got this

    upload_2017-12-18_15-36-39.png


    if change tank body shader set tag "rendertype1 = tank" set replacement shader subshader0 set tag "rendertype1=tank",set camera replacementshader "rendertype1" ,only tank is render no else render.
    upload_2017-12-18_15-33-1.png
     
  12. aastha10678

    aastha10678

    Joined:
    May 2, 2018
    Posts:
    1
    hey guys i need that script which attach to camera and shader please

    i am new in unity and need same output you did above, i need whole scene color with a simple shader with my camera.
    which i can't do because of nothing detail about replacement shader use.
    i am not a programmer so i just need simple script which i drag to my 2nd camera and render the scene as another color and my 1st camera as original,but i cant't do this
    please guys anyone have the solution please help me please :(