SleeplessOwl0102 / URP-Custom-Post-Processing

A framework that intends to quickly extend volume post-processing in Unity URP. And some experimental custom post-processing implement.
HomePage
MIT License
99 stars 13 forks source link

How to apply cloud shadows to a custom shader? +CloudShadows go completely black in orthographic mode. #2

Open SiriusRU opened 3 years ago

SiriusRU commented 3 years ago

Hi. Could you please give a hint - if I have, say, basic unlit shader - what would I need to add in my shader so cloud shadows effect is to appear on it? Also, I noticed that CloudShadows go completly black in orthographic camera mode and somewhat dark in scene view.

Great job, by the way.

SiriusRU commented 3 years ago

Okay, found another issue: When render scale is changed in current UniversalRenderPipelineAsset - effect ~breaks the game view, is not up to scale.

SiriusRU commented 3 years ago

And another one. Even with including post-process shaders in graphics settings - in build cloud shadows not properly rendered, geometry is only goes darker without any noise texture sight wnen closer and when has sharper camera angle.

SleeplessOwl0102 commented 3 years ago

Okay, found another issue: When render scale is changed in current UniversalRenderPipelineAsset - effect ~breaks the game view, is not up to scale.

I pushed a new commit to fix this issue.

SleeplessOwl0102 commented 3 years ago

Hi. Could you please give a hint - if I have, say, basic unlit shader - what would I need to add in my shader so cloud shadows effect is to appear on it? Also, I noticed that CloudShadows go completly black in orthographic camera mode and somewhat dark in scene view.

Great job, by the way.

Did your basic unlit shader have DepthOnly pass, and enable Depth texture in UniversalRenderPipelineAsset ?

if not, you can try to add this pass.

Pass
{
    Name "DepthOnly"
    Tags{"LightMode" = "DepthOnly"}

    ZWrite On
    ColorMask 0

    HLSLPROGRAM
    #pragma exclude_renderers gles gles3 glcore
    #pragma target 4.5

    //--------------------------------------
    // GPU Instancing
    #pragma multi_compile_instancing
    #pragma multi_compile _ DOTS_INSTANCING_ON

        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

    #pragma vertex Vert_Depth
    #pragma fragment Frag_Depth

    struct Varyings_Depth
    {
        float4 positionCS : SV_POSITION;
    };

    Varyings_Depth Vert_Depth(Attributes i)
    {
        Varyings_Depth o;
        VertexPositionInputs vertexInput = GetVertexPositionInputs(i.posOS);
        o.positionCS = vertexInput.positionCS;
        return o;
    }

    void Frag_Depth(Varyings_Depth i)
    {
        return;
    }

    ENDHLSL
}
SiriusRU commented 3 years ago

Did your basic unlit shader have DepthOnly pass?

Thanks for the quick response and for example even. Yeah, it does, but I'm not sure if I'm doing it right, but at least now I know in what direction it makes sense to dig in.

https://github.com/Cyanilux/URP_GrassGeometryShader/ In the end, I'm trying to get this^ shader to at least partially work with CloudShadows effect. Always wanted to achieve exactly this appearance from the game, but unfortunately I am not strong in graphic programming.

SleeplessOwl0102 commented 3 years ago

And another one. Even with including post-process shaders in graphics settings - in build cloud shadows not properly rendered, geometry is only goes darker without any noise texture sight wnen closer and when has sharper camera angle.

Can you tell me what is your target platform and device?

SiriusRU commented 3 years ago

Can you tell me what is your target platform and device?

Of course. Win10 64 bit, PC with NVidia card. Hmm. Outline effect, for example, works absolutely fine.

SleeplessOwl0102 commented 3 years ago

Did you enable Depth texture in UniversalRenderPipelineAsset? image

SiriusRU commented 3 years ago

Yes. And I actually have some water shaders that use it, so depth texture itself is there and it is present in the build. CloudShadows renders fine in editor, but not do that in build. If debug option is on - used noise texture is fine in editor, but in build it looks like just gradient between black and white based on camera angle as if there was no noise texture for some reason.

SleeplessOwl0102 commented 3 years ago

Yes. And I actually have some water shaders that use it, so depth texture itself is there and it is present in the build. CloudShadows renders fine in editor, but not do that in build. If debug option is on - used noise texture is fine in editor, but in build it looks like just gradient between black and white based on camera angle as if there was no noise texture for some reason.

Ok, this is a little strange. I build and run with Win10 64 bit, PC with NVidia card too, but work fine. If I have any new ideas, I will tell you.

SiriusRU commented 3 years ago

Thank you for your time. You made very neat effects, and the way everything looks with CloudShadows is especially amazing.

Also, here, the square area use a Lit shader. With debug toggle set to true that how it looks in editor and build. Ignore white dots on top. Just particles.

Снимок Снимок2

SiriusRU commented 3 years ago

Hi. So, I was able to "fix" my problem with CloudShadows effect not working in the build. Looks nice.

There is a line 114 in CloudShadow.shader float2 heightOffset = (pos.y / _WorldSpaceLightPos0.y) * _WorldSpaceLightPos0.xz; And I just changed it to: float2 heightOffset = pos.y / 2; I have no idea why _WorldSpaceLightPos0 works just fine in the editor, but it doesn't work in the build on my end, but without using it everything is seems fine. I probably don't get intended height shading now, but in my case it's not critical.

Also I lowered my _ShadowStrength value and changed line 132 in the same file from oriCol = lerp(oriCol, col, _ShadowStrength * pow((1- depth),10)); to: oriCol = lerp(oriCol, col, _ShadowStrength); so shadows stay consistent regardless of the camera distance which was somewhat off.