Search Unity

Issue with SetReplacementShader in new rendering pipeline

Discussion in '2018.2 Beta' started by TheShock, Jul 10, 2018.

  1. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    33
    Sorry for repost, but I've noticed, that previous topic category was wrong, and I should write my question here.

    My problem is not working of SetReplacementShader while using HDRP. My script is light and it works correctly in standard 2018.2 beta, but it does nothing in 2018.2 beta with HDRP turned on.

    Is it correct behavior in new RP or will be fixed? If it is correct - how can I change shaders for all objects in scenes for single camera (SetReplacementShader is very good for this)?

    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. }
    Here is result for SetReplacementShader in 2018.2 Standard:


    Here is result for same code in 2018.2 HDRP:


    Here is demo project with this code:
    https://drive.google.com/open?id=1TJxIGUGQxTl1KOFVV0IPEnvGdpKRO6Uu
     
unityunity