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

Convert to SRP Low End

Discussion in '2018.1 Beta' started by Elecman, Feb 1, 2018.

  1. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    How do I convert my project to the Low End SRP?
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Thanks! I must say that documentation about this SRP thing is a bit all over the place though.
     
  4. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Is the low end pipeline mature in that if I start converting my project now, do I run into trouble later?
     
  5. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    From the documentation:
    However, nothing related to the lightweight pipeline is present in beta 4. It looks like the GIT repo still needs to be downloaded and added to the project folder.
     
  6. WilkerLucio

    WilkerLucio

    Joined:
    May 2, 2017
    Posts:
    18
    Mind you, this whole stuff is still in preview.
     
    MadeFromPolygons likes this.
  7. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    How do I convert a custom unlit shader to be compatible with the Low End pipeline?
     
  8. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    The base of it will not change, some of the shader library or core SRP function may still change so doing any heavy customisation to the pipe, Including writing lit shaders that make use of the LW shader library will need adjustments later on. If you use the lightweight pipeline as is and use the shader graph as much as possible for now everything will upgrade as we continue to work on the pipeline, bear in mind visually things might change as we are still refining the features.

    So the package manager has only been given a GUI in beta6 so please download that to have full access to the pipelines from within unity, they also have the new template system which will start the project in the configuration of your choice.

    Currently unlit shaders work out the box in LW pipe, but there are a few things you should do to make it 100% compatible, you need to remove
    Code (CSharp):
    1. #include "UnityCG.cginc"
    as now you should use the SRP shader library, for LW pipe this means at least
    Code (CSharp):
    1. #include "LWRP/ShaderLibrary/Core.hlsl"
    and then replacing any functions that come from the legacy unity cginc, right now we don't have any concrete documentation but you can look through the new code here https://github.com/Unity-Technologi...peline/LightweightPipeline/LWRP/ShaderLibrary
     
  9. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Historically Unity has changed the lighting pipeline quite often during the 5.0 cycle, requiring UAS authors who do not use a surface shader to update their lighting code with each new version. In my experience, this takes a lot of time, because Unity does not document this code or even really tell you what changed. You're left diffing shader files and trying to figure out what changed. In response to this, all of my newer projects used surface shaders exclusively and lived with their limitations, because the support cost of doing anything else is just too high.

    As there is no more surface shader abstraction, how can asset authors who don't want to use a shader graph due to it's immense limitations avoid making SRP support a 2x nightmare compared to the previous pipeline?
     
    twobob likes this.
  10. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,981
    Wait, can we not write shaders by code for SRP? If not , that is really a step backwards...
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Oh no, you can- but you're going to have to write them without the surface shader abstraction, and once for each SRP that you want to support, which makes them much more troublesome to write and support over multiple versions of Unity. This is particularly problematic if you publish on the UAS. IE: Unity adds a new feature to the lighting engine in 2018.3, and you have to change all your shaders around in such a way that they work on the old and new pipeline, or have two different versions which need to be maintained. You will also be expected to support the traditional pipeline, LD, and HD by users, which means writing and maintaining three separate versions of your shaders, despite the fact that all three of those pipelines could be easily covered by a surface shader like abstraction (they all have the same inputs to the lighting equations).

    The only way around this is to use the new shader graph (which doesn't work for the old pipeline, but abstracts LD/HD so you can run the shader on both).

    IMO, a text based abstraction for the pipelines should have been available, with the graph built on top of that as a separate system, rather than having the graph also be the abstraction layer. This would have allowed SRP authors to make new SRPs which are automatically compatible with existing libraries of surface shaders, unless their SRP is so different that it doesn't conform to standard PBR style texturing (a possibility, but I suspect most will conform). This would have helped make a market on the UAS for SRPs while also making it much easier to write and support shaders for the UAS.
     
    Last edited: Feb 13, 2018
    brn, MadeFromPolygons and Peter77 like this.
  12. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,981
    I see now, from reading this I think I have been looking at shaders all wrong from a learning approach.

    I have been trying to learn vertex + fragment with the idea that surface shaders were in some way more complicated, or "not preferred" method. I now am realizing this is the opposite to the case. I've been really struggling to write a accumulation shader with vertex + frag but I think Ill be alright using surface, from what I have just seen in the docs as it looks like I can still write a vert function for use with a surface shader?

    Anyway, I agree that if there are abstractions at the moment for writing code that make writing shaders easier, we should maintain the same sort of level of abstraction with the new system, to ensure that developers who are invested in writing shaders for unity continue to do so.
     
  13. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Yes, surface shaders abstract a lot of complexity from you; not only lighting but pass semantics as well. Writing a complete vert/frag shader which supports all of Unity's lighting modes is very complex, and made more complex if you have to do it in a way that is compatible across multiple unity versions.

    I have various issues with the particulars of the surface shader implementation (magic keywords and variable names, hidden TBN matrix, etc), but the overall level of abstraction they provide is extremely valuable, similar to what a shader graph provides, but retaining much of the power a graph cost you. I see why Unity is leery of supporting them in an SRP world, because someone might write an SRP which is extremely different from the current pipeline and not easily translated - but the two example pipelines, along with many other potential ones that are likely to be created, could use the same basic abstraction. And their shader graph will have the exact same issue anyway, so combining the abstraction layer and graph tool as one thing seems like a mistake to me. Being able to hand author shaders and code was one of the main reasons I chose Unity over UE4 for our studio.
     
    Last edited: Feb 14, 2018
    MadeFromPolygons likes this.
  14. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    That is good news because the HD pipeline causes problems with the camera rotation matrix. Considering this question remains unanswered I assume this is a bug in the HD pipeline code. Why is the camera transform system different with the HD pipeline anyway?
     
  15. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    Unfortunately I haven't spent a whole heap of time in the HD render pipeline as that is handled by another team, but I looked at that post of yours and I can answer what I have done in Lightweight pipe to get around the current lack of ObjectSpaceViewDir().

    Code (CSharp):
    1. inline half3 ObjSpaceViewDir( in half3 posWS )
    2. {
    3. half3 objSpaceCameraPos = mul(GetWorldToObjectMatrix(), float4(GetCameraPositionWS(), 1)).xyz;
    4. return objSpaceCameraPos - posWS.xyz;
    5. }
    Which is essential what was in UnityCG.cginc just using LT pipe shader library.

    Again right now writing your own shaders in the pipelines is going to be very painful at the start while we get the documentation ready for the shader libraries, but the pay off of being able to have custom render pipelines and complete control over how you want to render anything is very much worth it, and for now if you don't like the idea of them don't use them, or wait till the documentation is there and shader graph is feature complete :) Legacy pipes are still in there and will be for a while.
     
  16. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Is fog still handled the same way in a shader as with the Lagacy pipeline?

    Also, is the shader upgrade manual somewhere to be found yet? I get a bunch of shader redefinition errors/warnings like:
     
    Last edited: May 2, 2018