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

ReplacementShader does not work in 2018.2 Beta

Discussion in 'General Graphics' started by TheShock, Jul 8, 2018.

  1. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    In previous version of Unity I had short working script, but now it does not affect anything. Does "SetReplacementShader" work correctly in beta version? What is my mistake?

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace Assets.Asimov.Utils
    4. {
    5.     [RequireComponent(typeof(Camera))]
    6.     public class CameraShaderReplacement : MonoBehaviour
    7.     {
    8.         [SerializeField]
    9.         private Shader ReplacementShader;
    10.  
    11.         public void Start ()
    12.         {
    13.             Debug.Log("Activate replacement shader");
    14.             GetComponent<Camera>().SetReplacementShader(ReplacementShader, "RenderType");
    15.         }
    16.     }
    17. }
    Code (CSharp):
    1. Shader "ColorReplacement" {
    2.  
    3.     Properties {
    4.         ReplacementColor ("ReplacementColor", Color) = (0,0,0,1)
    5.         _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 100
    11.         Pass
    12.         {
    13.             CGPROGRAM
    14.             #pragma vertex vert
    15.             #pragma fragment frag
    16.  
    17.             struct appdata
    18.             {
    19.                 float4 vertex : POSITION;
    20.             };
    21.  
    22.             struct v2f
    23.             {
    24.                 float4 vertex : SV_POSITION;
    25.             };
    26.             float4 ReplacementColor;
    27.            
    28.             v2f vert (appdata v)
    29.             {
    30.                 v2f o;
    31.                 o.vertex = UnityObjectToClipPos(v.vertex);
    32.                 return o;
    33.             }
    34.            
    35.             fixed4 frag (v2f i) : SV_Target
    36.             {
    37.                 return ReplacementColor;
    38.             }
    39.             ENDCG
    40.         }
    41.     }
    42. }
     
  2. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    I found, that the reason is using new rendering pipeline. Does SetReplacementShader works while using new pipeline?

    Here is test project for Unity 2018.2 Beta, ReplacementShader works correctly:
    https://drive.google.com/open?id=1TJxIGUGQxTl1KOFVV0IPEnvGdpKRO6Uu



    But the same in HD Rendering Pipeline doesnt work.



    How can I use SetReplacementShader in new pipeline?
     
    unity_H5hJ_Sth4neu5g likes this.
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Hi. ShaderReplace is a feature that is not designed to work at all with SRP. SRP is basically a form of shader replace (you can code what you want). So if you want to do something like this you should write an SRP that does rendering in your custom way.
     
    unity_H5hJ_Sth4neu5g likes this.