Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Convert Shader to Lightweight SRP

Discussion in 'Graphics Experimental Previews' started by Elecman, May 3, 2018.

  1. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    -Where is the documentation which explains how to convert a shader from the Legacy Pipeline to Leightweight SRP?

    -Missing functions in Leightweight include files: https://forum.unity.com/threads/uni...sing-from-both-lightweight-and-hd-srp.529568/

    -Replacing the include "UnityCG.cginc" with "LWRP/ShaderLibrary/Core.hlsl" causes a lot of redefinition errors and warnings:
    -How is fog handled compared to the Legacy Pipeline?
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    This is almost entirely a duplicate of the other post you made, maybe just do them in one next time?
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Only one item in the list of 4 is a duplicate (which is why I posted the link), not all 4 ;-)
    Thanks for pointing that out though.

    Have you thought about applying for a moderator? We need more people like that.
     
    soleron and fherbst like this.
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Theres already an amazing moderator group here, they are surprisingly omniscient considering they are just mere volunteers!

    Did you manage to work out how to handle fog btw?
     
  5. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    The fog only works if I use the legacy code inside HD or LW, which is kind if interesting that it works at all. They said it should be handled automatially but that currently not the case. Not without some specific fog code in the shader. Anyway, it is all still experimental, so no big deal ATM.
     
  6. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    MadeFromPolygons and soleron like this.
  7. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
  8. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    This is the time to provide feedback on the shader api for LWRP. We are taking into account your feedback and updating the API to make more user friendly. There will be some breaking changes soon but I'll update that gist to have the lastest template once we have the package with breaking changes in.
     
  9. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    More transform related functions would be nice, for example:
    Code (CSharp):
    1. output.pos = TransformViewToClip(viewSpacePos);
    Instead of having to use this:
    Code (CSharp):
    1. output.pos = mul(UNITY_MATRIX_P, float4(viewSpacePos.xyz, 1.0f));
    This is needed in a billboard shader.
     
    AlanMattano likes this.
  10. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    Ok. Noted.
     
    AlanMattano likes this.
  11. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    There is now TransformWViewToHClip() for that purpose.
     
  12. stephero

    stephero

    Joined:
    Feb 8, 2016
    Posts:
    123
    Have you found something to fix the shader redefinition warning?
    In my case, I use the latest HDRP (4.6.0). If I start a new blank unlit shader and include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl", I got the same warning:
    Code (CSharp):
    1. Shader warning in 'Unlit/TestUnlit': 'SAMPLE_DEPTH_TEXTURE' : macro redefinition at Packages/com.unity.render-pipelines.core/ShaderLibrary/API/D3D11.hlsl(112) (on d3d11)
    2. Shader warning in 'Unlit/TestUnlit': 'SAMPLE_DEPTH_TEXTURE_LOD' : macro redefinition at Packages/com.unity.render-pipelines.core/ShaderLibrary/API/D3D11.hlsl(113) (on d3d11)
    Thanks
     
  13. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    Is your shader including any other file other than Common.hlsl?
     
  14. stephero

    stephero

    Joined:
    Feb 8, 2016
    Posts:
    123
    Yes, it also includes "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" for UNITY_VERTEX_INPUT_INSTANCE_ID, but the issue is the same if I include only Common.hlsl
     
  15. VLukianenko

    VLukianenko

    Joined:
    Mar 27, 2017
    Posts:
    30
    Wanna bump this thread, maybe somebody knows what's up with the redefinitions? I have such:

    Code (CSharp):
    1. redefinition of '_Time' at Library/PackageCache/com.unity.render-pipelines.lightweight@6.9.1/ShaderLibrary/UnityInput.hls
    The only include I have is:
    #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"

    Edit: was able to make my shader compile after rummaging through newer shader libraries... I have a fairly simple shader, so for me it was sufficient to replace the object-to-view transformation with:
    o.vertex = mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_I_M, float4(v.vertex.xyz, 1.0)));

    while including (I assume you'd need isntall Shader Graph package for this to work)
    #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesMatrixDefsLegacyUnity.hlsl"


    And also replacing some of UnityCG.cginc functions with simpler functions and values... But still an answer would be appreciated. Will update if I'll get to solve this quicker than there's an answer...
     
    Last edited: Nov 7, 2019
  16. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    I had the same problem, and it took me a long time to find the solution.

    For me, the culprit was this line:
    UnityCG.cginc

    After removing it, all the macro redefinition errors disapeared.
    In hindsight it seems obvious (and was also mentioned by some people), but it wasn't very clear to me.

    As some feedback for the devs:
    The console error only tells you which macro is being redefined, and by which file.
    However, it doesn't tell you where the macro definition that already exists comes from.
    This information would have helped quite a lot, as it took me a while to realize, that UnityCG.cginc isn't for URP shaders.

    Regards
    Chillersanim
     
  17. GameDeveloper1111

    GameDeveloper1111

    Joined:
    Jul 24, 2020
    Posts:
    100
    I ran into the `macro redefinition` shader warning for a VFX graph when I downgraded from HDRP to URP.

    Edit --> Visual Effects --> Rebuild And Save All Visual Effect Graphs worked for me.

    Meta: Arrived here from a search engine via `SAMPLE_DEPTH_TEXTURE macro redefinition unity`. Hoping it will help someone.