Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Additional Cascade Shadow map in URP?

Discussion in 'Universal Render Pipeline' started by minsunny5_unity, Mar 9, 2023.

  1. minsunny5_unity

    minsunny5_unity

    Joined:
    Mar 9, 2023
    Posts:
    3
    I want to cast shadow for the tree which is very far away from the camera so, I changed urp asset setting's max distance higher but It makes overall shadow quality worse.

    So I want to try max distance shorter and add additional cascade shadow (more than 4 in urp) like this post to get more precise cascade shadow map. (I heard genshin used 8 cascade shadow map to get high quality shadow, and that's what I want.)

    The Post Link: https://zhuanlan.zhihu.com/p/588991...UyWIzGUwaZXkXMGQgwXLc4TCo-BW65-uSTW3xihC1a8aQ

    Therefore I tried to customize urp script to change the split ratio of the cascade shadow etc..like the above post, but code samples are not enough for me to understand whole process..

    I can make the gui like that but I have some trouble with unity's native c++ code.
    The URP codes about cascade shadow uses Vector3 to present split ratio of cascade shadow range. In my case I want to make that Vector3 to List or Array of 7 element. So I try to change the Vector3 to Array for example, the urp function named ComputeDirectionalShadowMatricesAndCullingPrimitives(using Vector3 split ratio but I cannot see inside implementation of it.) is replaced with that post's function about calculating casecade range ComputeDirectionalShadowMatricesAndCullingSphere(using float array split ratio) like the above post.

    However, I can't see inside of the urp native functions which is using Vector3 cascade split ratio so I don't know this way is right or not.. and don't know what function should I change more.

    Does anyone try to solve this kind of problem? Could you give me any advice or help?

    reference: catlikecoding - unity/tutorials/scriptable-render-pipeline/directional-shadows
    forum thread - rendering-additional-shadow-cascades.856882/
     
    Last edited: Mar 10, 2023
    SangYun_Yi likes this.
  2. wechat_os_Qy0z-7zpawpqXNqcuLz4nvHLI_unity

    wechat_os_Qy0z-7zpawpqXNqcuLz4nvHLI_unity

    Joined:
    Nov 10, 2022
    Posts:
    4
    Have you tried to use ComputeDirectionalShadowMatricesAndCullingPrimitives twice and when the second time, set the nearplane offset to previous cascade max distance?
     
  3. minsunny5_unity

    minsunny5_unity

    Joined:
    Mar 9, 2023
    Posts:
    3
    Well.. I also thought that idea. But I solved this problem by adding (not replacing) ComputeDirectionalShadowMatricesAndCullingSphere() after the ComputeDirectionalShadowMatricesAndCullingPrimitives(). Recalculation is not the best solution anyway it's working. If I have more time to digging this problem, I'll try your idea Thank you!
     
  4. wechat_os_Qy0z-7zpawpqXNqcuLz4nvHLI_unity

    wechat_os_Qy0z-7zpawpqXNqcuLz4nvHLI_unity

    Joined:
    Nov 10, 2022
    Posts:
    4
    Yes, now I also use his ComputeDirectionalShadowMatricesAndCullingSphere(), in my case I just delete the call of ComputeDirectionalShadowMatricesAndCullingPrimitives() and only use his ComputeDirectionalShadowMatricesAndCullingSphere() and it works just fine. Now I have a question: how to write the depth to RT? I set the colormask to 0 nothing shows on the RT,but when it's not zero, every fragment's color becomes it's depth value, do you have any solution? Thanks you any reply!
     
    minsunny5_unity likes this.
  5. minsunny5_unity

    minsunny5_unity

    Joined:
    Mar 9, 2023
    Posts:
    3
    1. Could you give me more detail about your problem? Do you want this?-> https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.GetTemporaryRT.html
    I made 8 csm according to https://zhuanlan.zhihu.com/p/588991...UyWIzGUwaZXkXMGQgwXLc4TCo-BW65-uSTW3xihC1a8aQ this post but I didn't make other feature like pccs. Do you have problem with making 8 csm than I could help you by making tutorial.

    2. How to replace that function? I had a problem to match the parameter of the ComputeDirectionalShadowMatricesAndCullingSphere() and ComputeDirectionalShadowMatricesAndCullingPrimitives().. Could you explain me more detail?
     
  6. Egi010

    Egi010

    Joined:
    Dec 13, 2020
    Posts:
    11
    Are you already find the answer for that problem?
     
  7. wechat_os_Qy09MzvGZbG0f91bxTKOiQWrw

    wechat_os_Qy09MzvGZbG0f91bxTKOiQWrw

    Joined:
    Mar 16, 2023
    Posts:
    1
    I also want to know more detail about ShadowSplitData..