Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

UPGEN Lighting (Standard, HDRP, URP)

Discussion in 'Assets and Asset Store' started by mm_ASH, May 26, 2020.

  1. Michael-ClockStone

    Michael-ClockStone

    Joined:
    Jan 18, 2012
    Posts:
    90
    Like I said, the shader does not compile an Android because the #pragma only_renderers list does not contain gles3.

    Anyway, I fixed the shader on Android for URP 12.x (Unity 2021.2.x). You need the following changes in "UPGEN Lighting.shader"

    1)
    Code (CSharp):
    1.  
    2. #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch gles3
    3.  
    2)
    Code (CSharp):
    1.  
    2. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
    3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
    4.  
    3)
    Code (CSharp):
    1.  
    2. float depth = SampleSceneDepth(uv);
    3.        
    4. #if !UNITY_REVERSED_Z
    5.         depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, depth ); // Adjust Z to match NDC for OpenGL ([-1, 1])
    6. #endif
    7.         float3 wpos = ComputeWorldSpacePosition(input.texcoord, depth, UNITY_MATRIX_I_VP);
    8.         float3 normal = SampleSceneNormals(uv);
    9.  
    Furthermore I wonder about the "loop unrolling". I would remove those lines unless you have a good reason for this. The loop can never unroll as far as I know as _LightsCount is uniform.
     
    PeachClamNine and mm_ASH like this.
  2. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    Sure you can, for performance reasons you even can replace all IFs there in code with compile conditions instead that uniform counter and switch it on material setup in CS code.
     
  3. Michael-ClockStone

    Michael-ClockStone

    Joined:
    Jan 18, 2012
    Posts:
    90
    To my understanding loop unrolling tells the compiler to generate code without IF conditions by duplicating the code instead. In order to work it must know the number of iterations at compile time. There is [unroll] in HLSL to achieve that. I don't see how that could work with a uniform count variable that changes at runtime. You could make shader variants (use e.g. multi_compile) to achieve that for specific constant light count values (e.g. 1,2,3,4 lights).
     
  4. ryanflees

    ryanflees

    Joined:
    Nov 15, 2014
    Posts:
    50
    Hello, I have some followup feedback about fixing forward rendering in UPGen, in builtin pipeline.
    By default, UPGen will lit the forward objects pixels incorrectly if they have gbuffer on it.
    I use a simple way to check if the pixel on the screen is from a forward rendered object , insert CommandBuffers to CameraEvent.BeforeForwardOpaque and CameraEvent.AfterSkybox on camera, and grab the screen. Then compare the 2 textures to see any color difference, then make a mask texture to determine if it's forward rendered pixel.
    Then check the mask texture in UPGen shader to ignore those pixel from forward rendering.
    So forward objects like the outline, particle effects can be correct with UPGen.


    Here's a short clip, the ball has a forward opaque shader, with and extra outline pass.
    HDRP fix should be similar, I haven't look deeper into HDRP version yet though

    QQ截图20220228163328.png
    However, in builtin pipeline, the UPGen is draw before forward alpha objects, like glass and particles. There's no way to know if there's a forward alpha object over it. But since forward alpha will overlap and make object behind darker, it doesn't appear too odd. So I'm ok with what's being like right now.
     
  5. frbrz

    frbrz

    Joined:
    May 10, 2016
    Posts:
    72
    Hi. Just a question. Are you still working on this asset? I'm asking this because last update for URP version was on November 2021. It looks cool.
     
  6. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    Hi, ryanflees!
    Thats sounds like a great idea. Thank you for sharing this to us!
     
  7. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    From time to time. Exactly now I am not working at all - there is a war in Ukraine and I live in Kiev =(
     
    Last edited: Mar 14, 2022
    blueivy, frbrz and CastryGames like this.
  8. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    My respect and my prayers are for you.
     
  9. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    Thanks, bro!
     
  10. alchemist_wurzelpurzel

    alchemist_wurzelpurzel

    Joined:
    Sep 4, 2018
    Posts:
    39
    For anyone using this in URP 2021.2 or 2021 LTS and experiencing issues with either Unity SSAO or wrongly lit areas, here are solutions that worked for me.

    For SSAO:
    Unity has changed SSAO so the resulting RenderTexture is called "_SSAO_OcclusionTexture" instead of "_SSAO_OcclusionTexture2" like it was before. So in the UPGEN Lighting shader, just change
    Code (CSharp):
    1. TEXTURE2D_X_FLOAT(_SSAO_OcclusionTexture2);
    2. SAMPLER(sampler_SSAO_OcclusionTexture2);
    to
    Code (CSharp):
    1. TEXTURE2D_X_FLOAT(_SSAO_OcclusionTexture);
    2. SAMPLER(sampler_SSAO_OcclusionTexture);
    and
    Code (CSharp):
    1. #if SSAO
    2.         fastLight *= SAMPLE_TEXTURE2D_X(_SSAO_OcclusionTexture2, sampler_SSAO_OcclusionTexture2, uv).rgb; // Add SSAO
    3. #endif
    to
    Code (CSharp):
    1. #if SSAO
    2.         fastLight *= SAMPLE_TEXTURE2D_X(_SSAO_OcclusionTexture, sampler_SSAO_OcclusionTexture, uv).rgb; // Add SSAO
    3. #endif
    For general lighting issues, when importing UPGEN into a 2021 LTS project or upgrading the project to 2021 LTS, Unity changed the UPGEN Lighting shader which messes up the Frag() function. To make it work again I had to adjust the following lines (commented out stuff is what Unity automatically added):
    Code (CSharp):
    1.         float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
    2.         float3 outColor = SAMPLE_TEXTURE2D_X(_CameraColorTexture, sampler_CameraColorTexture, uv).rgb;
    3.         float depth = SampleSceneDepth(uv);
    4. // #if UNITY_REVERSED_Z
    5. //         float depth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, uv).x;
    6. // #else
    7. //         float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, uv).x); // Adjust Z to match NDC for OpenGL ([-1, 1])
    8. // #endif    
    9.         float3 wpos = ComputeWorldSpacePosition(input.texcoord, depth, UNITY_MATRIX_I_VP);
    10.         //float3 normal = UnpackNormalOctRectEncode(SAMPLE_TEXTURE2D_X(_CameraNormalsTexture, sampler_CameraNormalsTexture, uv).xy);
    11.         float3 normal = SampleSceneNormals(uv);
    12.         // normal = mul((float3x3)_NormalsViewToWorldMatrix, normal);
    I am unsure about the Reversed Z part here as it was mentioned in another post. You might want to keep it for specific use cases.

    You will also need to include two files:
    Code (CSharp):
    1.     #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
    2.     #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
    and remove automatically added Depth and Normals Texture samplers because they are handled from the included files:
    Code (CSharp):
    1.     // TEXTURE2D_X_FLOAT(_CameraDepthTexture);
    2.     // SAMPLER(sampler_CameraDepthTexture);
    3.  
    4.     // TEXTURE2D_X_FLOAT(_CameraNormalsTexture);
    5.     // SAMPLER(sampler_CameraNormalsTexture);
    I hope this will help some people.
     
  11. MidnightCoffeeInc

    MidnightCoffeeInc

    Joined:
    Feb 28, 2017
    Posts:
    426
    I know the asset doesn't support it out of the box, but has anyone attempted to create a directional light variant that places Fast Lights in realtime to simulate directional light bounces?
     
  12. Rotem5

    Rotem5

    Joined:
    Dec 24, 2020
    Posts:
    1
    Hey guys !

    Does anyone know if UPGEN Fast-Light Culling is enabled / possible to set in some way ? I'm having this too-fast culling issue in my scene:



    Many thanks in advance for any help !!!
     
    PutridEx likes this.
  13. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    94
    I am having trouble with using Upgen in OpenGLCore. Whenever Upgen is activated in the scene, the whole screen would turn pink. Anyone have any ideas or fixes?

    [Solved]
    Needed to add glcore to the Upgen lighting shader, really should include all of them by default!

    #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch gles3 glcore
     
    Last edited: May 29, 2022
  14. Karmahero

    Karmahero

    Joined:
    Feb 11, 2012
    Posts:
    6
    Is there any chance of future WebGL support? Also, you may want to indicate on the store page or in the Manual that WebGL is not currently supported.
     
  15. CastryGames

    CastryGames

    Joined:
    Oct 1, 2014
    Posts:
    73
    or deletted pragma only_renderers line
     
    iceb_ likes this.
  16. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    94
    Think WebGL will work without that line?
     
  17. RevC2

    RevC2

    Joined:
    May 2, 2021
    Posts:
    33
    Hey there!
    I'm thinking about buying the Upgen lighting asset for HDRP, but I've read some conflicting informations and I'd like to be sure the system suits my needs.

    - Does it support VR?
    - Are Directional lights supported? I've read in the review section that are not supported anymore

    thanks in advance!
     
  18. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,414
    Hi, awesome asset, I have prebuy questions:

    URP: Does it work on WebGL, Android and Iphone?
    Cheers
     
  19. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    94
    What would be the limitation for preventing it from being available for WebGL? Because it would be awesome to have WebGL available and find the performance elsewhere to still use Upgen.
     
  20. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    1,794
    Are there any problems when using normal unity lights with Upgen lights ? HDRP
     
  21. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    no, they should work well together
     
  22. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    269
    Hey @mm_ASH ,

    I saw your asset in the Ukraine Mega Bundle (the HDRP version) and I am interested in the Standard RP version.
    I´ve read somewhere here I can upgrade for ~10$ so this would be my plan since I could also make use of the other assets in the bundle, but yours would be the one why I consider buying it at all ^^. However. I have some questions:

    I would make use of it in my mobile racing game for streetlamps, car headlights, and cop signal lights.
    Right now I disable all streetlamp lights at a certian distance and enable a fake light projector using a custom shader.
    Headlights and cop signal lights just get disabled at a set distance. However there is always a decent amount of lights enabled. Do you think it makes sense implementing it in this scenario? or would be the potential overhead of your asset make it sensless again?

    I also assume, since you said it relies on colliders, I would have to use at least some low poly colliders for some stuff instead just box colliders to get reasonable results? And colliders that are marked as triggers get ignored right?

    The F.A.Q. says
    "It should work on any platform. RTX video cards are not required to use Ray-Tracing components."

    I know someone said it does not work on mobile, but it would be cool If you could provide me a demo apk using
    open GL 3.1 as graphics api and deferred using the build in rp, so I can test it myself.

    Any other thoughts when seeing my video? Do you think it could work and improve the performance in my case?

    Thanks ;)
     
    Last edited: Jun 14, 2022
    Deleted User likes this.
  23. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    269
    Hi @Michael-ClockStone ,

    I am having problems with open gl too and have the standard rp version.

    I was able to make the first part of your solution work, but I dont know how to translate the following code from your solution to the standard RP version:
    Code (CSharp):
    1. float3 wpos = ComputeWorldSpacePosition(input.texcoord, depth, UNITY_MATRIX_I_VP);
    2. float3 normal = SampleSceneNormals(uv);
    this part from the standard rp version:

    Code (CSharp):
    1. float4 normal = 2 * SAMPLE_TEXTURE2D(_CameraGBufferTexture2, sampler_CameraGBufferTexture2, uv) - 1;
    2.         // transform screen to world space
    3.         float4 viewPos = mul(_ViewFromScreen, float4(uv * 2 - 1, depth, 1)); // inverse projection by clip position
    4.         viewPos /= viewPos.w; // perspective division
    5.         float3 wpos = mul(_WorldFromView, viewPos).xyz;
    Any Idea?

    Thanks ;)
     
  24. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    94
    try just removing the whole #pragma only_renderers line to see what happens first.
     
  25. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    269
    Tried that already. Didn't worked. I need to wait for his response.

    Thx anyway ;)
     
  26. MadStuntman

    MadStuntman

    Joined:
    Jun 27, 2019
    Posts:
    20

    Hi!
    I met the bug in UPGEN HDRP which was reported here.
    https://forum.unity.com/threads/upgen-lighting-standard-hdrp-urp.898526/page-5#post-7359254
    I'm using HDRP shaders (made with Shader Graphs) included in Measured Material Library with a goal to unify and minify count of used materials in my project. Unfortunately every material is affected by light glitches described in the post linked above. Also I'm using Daz3D shaders provided by DazToUnity bridge and some of them affected by that bug too.

    You advised to report bug or use "better" materials but all of those shaders works perfect with standard Unity lights. Moreover its aren't third-party shaders from a random asset but the shaders provided by Unity itself.

    I'd like if you look again how we can fix this bug. Perhaps we can add specific node in Shader Graph to fix the bug or something else?
     
    Last edited: Jul 6, 2022
  27. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    52
    Hi, I am using Upgen URP with unity 2021.3 and it's working great in VR Multipass but Single Pass Instanced have rendering issues (one eye is white)
    Is there any plan to support SPI in the future ?
    Thanks !
     
    NeatWolf likes this.
  28. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    Hi!
    Yes am working on new much better version of UPGEN lighting, which is also support URP single pass.
    But (because of war in my country) I can't give you any promises about therms when I`ll submit it to the asset store - hopefully till the end of this year.
     
  29. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    52
    I wish you the best, thanks for your work.
     
    mm_ASH likes this.
  30. HideoKojimaPunchFace

    HideoKojimaPunchFace

    Joined:
    Sep 2, 2011
    Posts:
    274
    Hi, I am using UpGen Standard, and I get this shader error with the current 2021.x LTS version.

    Upgen 2021 LTS.PNG

    I tried to change the folder to the new one, that Unity 2021 LTS is using now, which is:

    Library/PackageCache/com.unity.postprocessing/PostProcessing@3.2.2/Shaders/StdLib.hlsl

    So I tried: Library/PackageCache/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl

    But I still get the line 7 error
     
    hopeful likes this.
  31. McGunn

    McGunn

    Joined:
    Aug 7, 2012
    Posts:
    33
    Does anyone know if UPGEN HDRP works in 2022.1 ? I'd really like to know, thanks!
     
  32. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    432
    hey there.
    does anyone know how to push limit of 1024 lights in camera? i mean problem with "maximum array size (1024)"
     
  33. FlightFight

    FlightFight

    Joined:
    May 29, 2017
    Posts:
    16
    Hello,
    I would like to set the position, color and intensity of fast lights from code without the neeGameobjects.
    Is this possible in the URP version of Upgen?
    Can Upgen render 96 fast lights simultaneously in URP?
     
    Last edited: Jan 8, 2023
  34. FlightFight

    FlightFight

    Joined:
    May 29, 2017
    Posts:
    16
    Yes, it works. I tried it myself. However I only use the fast lights and am not interested in the other features of Upgen.
     
    hopeful likes this.