Search Unity

UPGEN Lighting (Standard, HDRP, URP)

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

  1. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    337
    Ok. As far as you already discovered UpgenLighting.shader =) .. you can use it to debug your scene.
    There is few debug code lines at lines 72-74
    // DEBUG
    //return float4(cos(wpos * 100), 1);
    //return float4(depth, depth, depth, 1);
    //return float4(normal, 1);
    Just uncomment to see what info you has in normals and depth buffers.
    First commented line should draw regular grid to check if shader reconstruct world coordinates correctrly.
     
  2. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    65
    haha yeah, been using that already, wanted to make sure the models on my end was fine before complaining to you =)

    The normal looks properly flat on the ground here as you can see: (not sure if normal is correct but at least it's properly flat)

    upload_2021-11-25_14-36-9.png


    I don't understand how to read it, but here's the results:
    upload_2021-11-25_14-37-36.png


    And strange, when I uncommented to debug Depth texture, it is pure solid white.
     
  3. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    337
    Ok that two screenshots looks correct. Seems problem is in the depth buffer, it should not be solid white.
    Maybe you can send me your project with this scene or some other small scene, so I can try to reproduce your problem.
     
  4. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    65
    I just tested this in 2021.2.3f1, using the default test scene, added a red Fast light there. It's using ONLY upgen as the renderer feature, fresh install of Upgen.
    You can see that it's hitting the side wall, and only half the floor.

    upload_2021-11-25_18-29-39.png
    upload_2021-11-25_18-32-7.png
    upload_2021-11-25_18-32-31.png
    upload_2021-11-25_18-33-21.png


    The depth map returns at least, but it doesn't seem to be what's causing the issue.
     
  5. ryanflees

    ryanflees

    Joined:
    Nov 15, 2014
    Posts:
    38
    QQ截图20211126113848.png
    Desktop 2021.11.26 - 11.35.55.0621-11-26-11-37-56.gif
    hello, me again.
    I'm trying to use UPGen built-in with my FPS project, in unity 2019.4 builtin deferred pipeline.
    The outline shader is implemented along with a forward surface shader on the object, and it weirdly gets affected by UPGen, seems like these outline pixels get lighted by the gbuffer. But the forward base shader works right.
    I thought it was due to the depthnormal texture because outline didn't write the depth. I try to custom the Internal-DepthNormalsTexture.shader and expand the vertex like the outline, but the problem is still here.

    The ouline shader is something like below.
    Code (CSharp):
    1.         Tags{ "RenderType" = "Outline"  "Queue" = "Geometry+0" }
    2.         ZWrite On
    3.         Cull Front
    4.         CGPROGRAM
    5.         #pragma target 3.0
    6.         #pragma surface outlineSurf Outline nofog  keepalpha noshadow noambient novertexlights nolightmap nodynlightmap nodirlightmap nometa noforwardadd vertex:outlineVertexDataFunc
    7.      
    8.         struct Input {
    9.             half filler;
    10.         };
    11.         float4 _ASEOutlineColor;
    12.         float _ASEOutlineWidth;
    13.         void outlineVertexDataFunc( inout appdata_full v, out Input o )
    14.         {
    15.             UNITY_INITIALIZE_OUTPUT( Input, o );
    16.             v.vertex.xyz += ( v.normal * _ASEOutlineWidth );
    17.         }
    18.         inline half4 LightingOutline( SurfaceOutput s, half3 lightDir, half atten ) { return half4 ( 0,0,0, s.Alpha); }
    19.         void outlineSurf( Input i, inout SurfaceOutput o )
    20.         {
    21.             o.Emission = _ASEOutlineColor.rgb;
    22.             o.Alpha = 1;
    23.         }
    24.         ENDCG
    I've tried different geometry outline , write my own, ASE outline, Realtoon Shader outline and other toon shader outlines. It all have this problem. (I have postprocess outline and due to particle effect issue I can't let them affect forward rendered object)
    This problem is probably out of the UPGen scale. But if you have ever met this issue, can you give me some direction how to let forward outline works good with UPGen?
    @mm_ASH
     
  6. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    337
    Sounds like a problem. Will try to reproduce.
     
    iceb_ likes this.
  7. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    337
    Hi there!
    Forward geometry if a problem described in manual as not-supported. UPGEN Lighting as a screen space effect use GBuffer data to calculate lighting. Forward geometry does not write anything to GBuffer and enabling DepthNormal texture will not help - lighting will be writed on top of it. Easiest solution here is to use post effect based outline.
     
  8. ryanflees

    ryanflees

    Joined:
    Nov 15, 2014
    Posts:
    38
    I kind of figured 2 ways to workaround.

    QQ截图20211126195049.png
    1, I find that the shadowcast will affect depth at very ealy of frame debugger. So if the outline surface shader has a "addshadow" paramemter, it will write into the depth and work correct with UPGen. but will cast shadows. And adding shadow caster to a outline vertex/fragment should may not be so simple.

    2, I add a command buffer to CameraEvent.AfterGBuffer to save the depth into my own renderer texture. (Tried to Blit the internal _CameraDepthTexture, but can't get it out, i don't know why, so I have to save the depth by my own)
    And add an custom "OutLine" render type to Internal-DepthNormalsTexture.shader to write depth. But this only affects _CameraDepthNormalsTexture.
    Then in the UPGen post shader, compare the two depth texture to see if there is difference. the pixel with difference means it's behind an forward opaque object and will be ignored. Something like below

    Code (CSharp):
    1. float depth4= tex2D(_CameraDepthNormalsTexture, uv);
    2.         float3 decodedNormal;
    3.         float decodedDepth;
    4.         DecodeDepthNormal(depth4, decodedDepth, decodedNormal);
    5.         float realDepth = Linear01Depth(decodedDepth);
    6.  
    7. float4 deferredDepth = SAMPLE_DEPTH_TEXTURE(_LastDepthTexture, sampler_LastDepthTexture, uv);
    8.    
    9. float offset = abs(realDepth - deferredDepth.r);
    10. float hasColor = step(offset, 0.01);
    11.  
    12. float3 targetColor = color.rgb + albedo.rgb * light * albedo.a * _Intensity;
    13.   float3 result = lerp(color.rgb, targetColor.rgb, hasColor);
    14.  
    15. return float4(result.rgb, 1);
    QQ截图20211126194928.png
    It works correctly like this, with UPGen working. But I still need to check the GPU cost and review the workflow to make it tiny and clean.
     
    Last edited: Nov 26, 2021 at 1:49 PM
  9. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    337
    Sounds interesting but screen space outline will be 100% faster than rendering to GBuffer and then DepthNormalsTexture
     
  10. ryanflees

    ryanflees

    Joined:
    Nov 15, 2014
    Posts:
    38
    Yeah but post process outline has its own issue with forward objects. like a smoke or a fire, you could draw the smoke's outline or ignore it and draw the deferred object outline behind the smoke. both ain't exact correct.
    Post outline also needs a lot detailed workaround
     
    mm_ASH likes this.
  11. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    65
    Thanks ASH, your latest hot fix works now in URP 12.1 Unity 2021.2.4f1, looking great!

    upload_2021-11-29_19-8-34.png
     
    ryanflees and mm_ASH like this.
unityunity