Search Unity

Can render the one object which need to add image effect in post render?

Discussion in 'Shaders' started by dreamerflyer, Jul 3, 2012.

  1. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Hi all, I want to control which object to be render in the image effect(post render),and do not render all the objects in the camera view.How can I ?

    ps: why not can upload image now???
     
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    You need to use replacement shaders for easily doing what you want.
    My glow per object asset does that. You can check it in the assetstore.
     
  3. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Thank you nice man~~,btw,may i use my self tag,like this:Tags { "RenderType"="MyTags" }?
     
    Last edited: Jul 3, 2012
  4. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    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. }
    17.  
    Above is the replacement shader example code . I do not understand the relationship between "RenderType"="Funky" and Tags { "RenderType"="Opaque" },when I change Tags { "RenderType"="Opaque" } to Tags { "RenderType"="Transparent" }
    the effect is deferent.So, what has happened about this ?
     
  5. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    For example, if you had these three shaders in your scene...

    Code (csharp):
    1.  
    2. // One shader, renders things white.
    3. Shader "Custom/RenderWhite" {
    4.     SubShader {
    5.         Tags { "RenderType"="Opaque" "MyTag" = "RenderWhite" }
    6.         Pass {
    7.             Fog { Mode Off }        
    8.             Color (1,1,1,1)
    9.         }
    10.     }
    11. }
    12.  
    13. // Second shader, renders things black.
    14. Shader "Custom/RenderBlack" {
    15.     SubShader {
    16.         Tags { "RenderType"="Opaque" "MyTag" = "RenderBlack" }
    17.         Pass {
    18.             Fog { Mode Off }
    19.             Color (0,0,0,0)
    20.         }
    21.     }
    22. }
    23.  
    24. // Third shader, renders things grey.
    25. Shader "Custom/RenderGrey" {
    26.     SubShader {
    27.         Tags { "RenderType"="Opaque" "MyTag" = "RenderGrey" }
    28.         Pass {
    29.             Fog { Mode Off }
    30.             Color (0.5,0.5,0.5,0)
    31.         }
    32.     }
    33. }
    34.  
    So you'd use the replacement shader like so;
    Code (csharp):
    1.  
    2. Camera.RenderWithShader ( [shader that contains the code below], "MyTag" );
    3.  
    With the shader you tell it to render with being this shader.
    Code (csharp):
    1.  
    2. // Replacement shader, any shader in your scene that has a matching MyTag to one of these subshaders will use the subshader defined here.
    3. // In this case;
    4. // It'll render anything with MyTag RenderWhite in red.
    5. // And anything with MyTag RenderBlack in green.
    6. // And because there isn't a subshader with MyTag RenderGrey, it won't render that material at all in this render pass.
    7. Shader "Custom/ReplacementShader" {
    8.     SubShader {
    9.         Tags { "RenderType"="Opaque" "MyTag" = "RenderWhite" }
    10.         Pass {
    11.             Fog { Mode Off }
    12.             Color (1,0,0,0) // Render it red rather than white!
    13.         }
    14.     }
    15.    
    16.     SubShader {
    17.         Tags { "RenderType"="Opaque" "MyTag" = "RenderBlack" }
    18.         Pass {
    19.             Fog { Mode Off }
    20.             Color (0,1,0,0) // Render it green rather than black!
    21.         }
    22.     }
    23. }
    24.  
    Bear in mind that the replacement shader results will not have shadows.
     
    Last edited: Jul 4, 2012
    Ramphic and Jason-Michael like this.
  6. Ramphic

    Ramphic

    Joined:
    Jun 21, 2017
    Posts:
    60
    Thankyou for explanation !!