Search Unity

[LWRP]Any macro in shaderlab tell which pipeline is using?

Discussion in 'Universal Render Pipeline' started by PuzzledBoy, Jul 31, 2019.

  1. PuzzledBoy

    PuzzledBoy

    Joined:
    Sep 9, 2014
    Posts:
    23
    Hi,I have to make a adaptive fix for our old build-in pipeline plugin to support LWRP.
    I create a new SubShader with Tags "RenderPipeline = "LightweightPipeline",so that in LWRP project shaderlab with use the first subshader and build-in pipeline use the second:
    Code (CSharp):
    1. Shader ""{
    2.     SubShader {
    3.        Tags{"RenderPipeline" = "LightweightPipeline" "Queue" = "Transparent"}
    4.         //...
    5.     }
    6.  
    7.     SubShader{
    8.        Tags{"Queue" = "Transparent"}
    9.         //...
    10.     }
    11. }
    And obvisouly the two subshader has lot of same logic but little different code,I want to strip them out,and use a macro to define the different code,any build-in macro support this? such as:
    Code (CSharp):
    1. #if LWRP
    2.   //...
    3. #else
    4.   //...
    5. #endif
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    There is none.
    The shader system is not aware of the graphics pipeline used.
     
  3. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,163
    Couldn't unity editor aware about it and set some project wide define for us?
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    @Thaina it's not as simple as it sounds :)
     
  5. msue

    msue

    Joined:
    Jun 10, 2015
    Posts:
    6
    Hi, I stumbled on this thread as I wanted to keep my shader somewhat compatible between using either UnityCG.cginc or Core.hlsl (the latter only usable when also using HLSLPROGRAM macro instead of CGPROGRAM).

    The following seems to work:

    Code (CSharp):
    1. #ifdef UNITY_CG_INCLUDED
    2.     o.vertex = UnityObjectToClipPos(v.vertex); // old
    3. #else
    4.     o.vertex = TransformObjectToHClip(v.vertex); // URP
    5. #endif
     
  6. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    Would be nice if a define existed for each of the render pipelines. Seems simple enough..?
     
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    IIRC they include a define with the pipeline version number nowadays.
     
  8. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    Is there any documentation on this anywhere? This post by itself isn't enough to figure out how to determine what these defines are.
     
  9. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    I just checked, it's something different - it's the version of the shader library that I recalled.

    I suppose they could have a define somewhere in URP/ShaderLibrary/Core.hlsl to tell that it's URP.
     
  10. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    It would be great! Would also be great if they didn't do it halfway, and added nodes to shadergraph to check these defines existence as well for conditional compilation!