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

UnityCG.cginc functions missing from both Lightweight and HD SRP

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

  1. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    With the Lightweight and HD SRP we are not supposed to include UnityCG.cginc anymore, but that file contains a bunch of handy functions which are missing from the Lightweight and HD include equivalents. This requires a lot of shader refactoring. Why not add these missing functions?
     
    Last edited: May 8, 2018
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    I feel your 3 threads about almost identical things could have been 1 thread.
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    There is one post with one identical item out of 4, which is why I included the link to that item. But not all 3 post are identical because one post is specifically for HD only (camera relative rendering).

    In case you wonder why I made a separate post for the camera relative rendering shade issue, it is is because I was told to do that in the Beta forum by one of the UT employees. He said I should keep posts for HD and LW separate.

    Are they are still looking for moderators?
     
    Last edited: May 4, 2018
    AlanMattano likes this.
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    Did you ever figure out where the UnityCG.cginc alternatives were / how to replicate functions?
     
  5. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    I just copied the missing functions from UnityCG.cginc and put them into my own include file. I just don't understand why it is not included in the new LW and HD versions as these functions contain nothing fancy. Just some math.
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    No, but you're responding above to a non moderator and non staff. As far as I'm concerned, your behaviour is correct.
     
  7. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    We are currently still heavily changing the shader libraries for Core, HD and Lightweight so nothing is set in stone, right now things that are not needed by the pipeline are being left out, as it is all code that bloats any shader(precompiled) and slows compile time so having functions that are not needed by the core rendering makes sense to not be included.
    One major point of SRP is to ditch a lot of legacy code that is bloating the legacy render pipelines, this is the only way we can go forward and more importantly open the rendering up to users for full customisation.

    In saying that I'm sure we are missing a few functions that will be useful to you guys, feel free to post a list of functions that you have run into needing to use that don't exist in the current SRP libraries, if we feel that they would be useful across the board we will look into adding them where appropriate.
     
    MadeFromPolygons and hippocoder like this.
  8. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    I am all for bloat reduction. Maybe you can add a separate include file, not needed by the core SRP?

    The functions I need for my shader are:
    Code (CSharp):
    1. ObjSpaceViewDir()
    2. UnityObjectToViewPos()
     
    AlanMattano likes this.
  9. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982

    These plus a reasonable way of getting light direction for different types of lights would be great
     
  10. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    For lightweight this is very straightforward as it's a forward only renderer so we have set buffers for the light data, we also have two functions:
    Light GetMainLight()

    which gives you the main lights data

    Light GetLight(half i, float3 positionWS)

    which returns the additional lights based on the index you ask for, this lets you use it in an loop if you want to light all additional lights
    for eg(from the lighting.hlsl):
    int pixelLightCount = GetPixelLightCount();
    for (int i = 0; i < pixelLightCount; ++i)
    {
    Light light = GetLight(i, inputData.positionWS);
    light.attenuation *= LocalLightRealtimeShadowAttenuation(light.index, inputData.positionWS);
    color += LightingPhysicallyBased(brdfData, light, inputData.normalWS, inputData.viewDirectionWS);
    }


    Actual light direction isn't stored as it is recreated by the offset in word space from the object being rendered to get the direction from the object, we do store it for the main directional light but thats about it.
    Again this is all going through changes right now so all of this might change.

    Funnily enough I needed this for a water shader I was working on and did the same, copied it out from the UnityCG.cginc and had it embedded in the water shader, I believe we may have simply just missed adding that in along the way, all the transform functions are changing right now as it makes no sense for HD and Lightweight to have the same functions locally so these will be moved to core, I'll bring up adding these two.
     
    Elecman, MadeFromPolygons and elbows like this.
  11. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    Thanks this was exactly the info I needed!

    Very glad you included the call to getting the actual light count using GetPixelLightCount (which I had no idea existed). Should be able to get a decent start now with this info
     
  12. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    Hey guys, I'm writing some documentation on shader and we are some of the shader and C# API for LWRP based on feedback we received. Meanwhile don't refrain from posting the things you feel are missing or that could change. We are taking all of that into account.
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Rendering meshes on top of anything else while receiving lighting correctly and casting shadows without 2 camera overhead (first person melee in my case) for HDRP and LWRP. It's a super common use case for everything really. Do we need 2 cameras for such a common use case?

    Thanks :)
     
    AlanMattano likes this.
  14. Sark_Klimento

    Sark_Klimento

    Joined:
    Jan 17, 2019
    Posts:
    12
    Hi, i'm trying to use the
     Light mainLight = GetMainLight(); Direction = mainLight.direction;
    in Shader Graph code, but i always get the error
    "Assertion failed on expression: 'success'
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()"
    And it returns nothing.
     
  15. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    Sorry. I completely missed your message. No, we are going away from camera stacking approach as this is bad for many reasons (extra culling, extra bandwidth, problems like you said to resolve shadows).

    So, we are prototyping a solution that will allow this. I can't promise anything yet in terms of when we do it but I'm super excited for this as it's a major workflow improvement.

    This solution would make the renderer and all render passes in LWRP data driven and customizable.
    So you could 1) inject easily custom render passes in the LWRP renderers 2) customize the built-in ones, f.ex, tell the RenderOpaquesPass to render specific layers and specific shader passes. This would also solve the lack of rendering all passes in a shader people have been asking for in SRP.

    This way you could, render your character/guns/hands in shadowcaster pass by adding it to a specific layer that only the shadow caster pass renders.

    Then in the render opaques/transparent you inject a custom render pass for rendering the gun/hands. We might also provide with LWRP a render pass that renders object with custom camera matrices/fov so devs don't have to create it, just add it to the renderer. But also, can't promise anything now.
     
    hippocoder likes this.
  16. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    For shader graph feedback/issues I'd recommend posting here: https://forum.unity.com/threads/feedback-wanted-shader-graph.511960/
     
  17. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    Hi,
    How to get " unity_StereoEyeIndex " in the shader graph (LW)?
    Thanks
     
  18. ekakiya

    ekakiya

    Joined:
    Jul 25, 2011
    Posts:
    79
    I tried to use Core RP Library instead of UnityCG and some of standard Lib, to study.

    1. I believe BoxProjectedCubemapDirection is not yet ..or maybe somewhere with another name?

    2. OptimizeProjectionMatrix

    Other than the UnityCG.cginc, I think
    3. TransformHClipToNDC in core Lib will be helpful.

    4. V_SmithJointGGXAniso with partLambdaV doesn't need TdotV and BdotV for there argument.
     
  19. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    @phil_lira I would argue you seriously underestimate the scope of the problems camera stacking solves. It's going to be a nightmare with out that.
     
  20. ekakiya

    ekakiya

    Joined:
    Jul 25, 2011
    Posts:
    79
    I found I forgot the link to the shader code..
    The code is litChk.shader in this blog post.
    techblog.sega.jp/entry/2019/04/25/100000
    Sorry the blog is in Japanese but the code itself is no jp.