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.
  2. Dismiss Notice

[Released] Screen Space Cavity & Curvature for Unity - Inspired by Blender's Cavity effects.

Discussion in 'Assets and Asset Store' started by JollyTheory, Mar 31, 2022.

  1. BunnyViking

    BunnyViking

    Joined:
    Nov 28, 2019
    Posts:
    16
    Using SSCC in BiRP i've found if a mesh renderer is set to cast shadows 'shadows only' (even with receive shadows off) it will still receive SSCC to some degree (which is a problem for using a shadow only full body model for 1st person)
     
  2. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Just checked, Unity unfortunately makes opaque objects marked as Shadows Only still write to _CameraDepthNormalsTexture, so there's not much I can do to force it to not do that. Even the Standard shader writes to it, so i think for some reason it's the intended behaviour in Unity.
    You can try setting the Normals Source to Reconstructed from Depth, as _CameraDepthTexture does not seem to be written to by Shadows Only objects (weird inconsistency, i guess they really need the normals for the shadow pass, post-processing effects be damned).
    If you still want to use Camera normals source you can also set the shaders of Shadows Only objects to be transparent, so they don't render to _CameraDepthNormalsTexture.
     
  3. BunnyViking

    BunnyViking

    Joined:
    Nov 28, 2019
    Posts:
    16
    Cheers for the reply, that makes sense technically, i'll see if I can work around it.

    The other thing I was thinking of was if you put in a layermask for what receives SSCC but I don't know enough about the backend that that would even work.
     
  4. slushieboy99

    slushieboy99

    Joined:
    Aug 29, 2014
    Posts:
    74
    Hi there, bought this asset the other day and am very happy with the screenspace effect but I am having trouble understanding how to make the effect work on particular objects. I am running URP 10.9.0 and get the error: 'LitShaderCavity2021' does not implement inherited abstract member 'BaseShaderGUI.MaterialChanged(Material)' when I unpack the URP2021_SSCC Texture Example.

    I'd like to simply apply this effect to certain existing shader graphs I have as shown in this image you posted earlier:

    Are there clear instructions anywhere on how I can do this on recent URP versions? Thanks!
     
  5. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, URP 10.9.0 is Unity 2020 if im not mistaken, if it is then you should import 'URP2020_SSCC' not 'URP2021_SSCC'.

    To apply the effect to existing shadergraphs just copy the nodes in the image and mix the R and G of 'Sample Texture 2D' into your shader.
     
    slushieboy99 likes this.
  6. slushieboy99

    slushieboy99

    Joined:
    Aug 29, 2014
    Posts:
    74
    Oh duh! My bad, works like a charm now, thank you!
     
  7. Deeprod

    Deeprod

    Joined:
    May 23, 2022
    Posts:
    2
    I have purchased the shader from the unity asset store and it looks great! I have been playing with the demo scene and this is exactly what I was after. However, I can't seem to reproduce the effect on my own scenes. I have copied across the SSCC script on my main camera, but I obtain an ugly effect:
    upload_2023-1-27_23-8-12.png
    Those are my camera settings:
    upload_2023-1-27_23-8-24.png

    upload_2023-1-27_23-10-20.png

    I am using the built-in render pipeline and the standard shader:
    upload_2023-1-27_23-10-39.png

    Is there anything else that I need to set up to be able to reproduce the effect as in the demo scene?
     
  8. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Answered you in email.
     
  9. royhathaway

    royhathaway

    Joined:
    Sep 7, 2018
    Posts:
    2
    Hi there, hoping you would be able to help give me a hand on what would be best to solve an issue I'm seeing. I absolutely love the cavity shading effect, however it appears any foliage that renders in front of an object with the shader renders these lines from the curvature pixel radius. I really want to keep the curvature pixel radius because it blends my styles nicely. I tried changing the normals source to reconstructed from depth, but that creates bands of lines across objects.
    upload_2023-1-28_19-55-58.png This is the foliage issue.

    upload_2023-1-28_19-56-27.png This is the reconstructed from depth issue.

    Any ideas on how I might solve one or the other haha?

    Thank you!
     
  10. Deeprod

    Deeprod

    Joined:
    May 23, 2022
    Posts:
    2
    Thanks heaps Jolly, it all works as expected now. For reference, below is your response to my email:
    It seems it's due to the part of the objects that is in the negative (<0) near clipping plane not receiving very much precision in the generated Depth and Normals textures due to the way Unity encodes them.
    So this issue seems to be kind of Unity related, and there's not much I can do to help it. The effect relies on precision in the Depth and Normals textures, but it's not getting it.
    It seems like even some of the built-in Unity things don't handle being in the negative clipping plane very well, for example I noticed some vertices shaking (due to lack of precision again probably).
    The only solution I can recommend is to move the objects into the positive (>0) near-clipping-plane range.

    upload_2023-1-29_13-8-33.png
     
  11. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi,
    The problem with the first screenshot is probably due to your leaves shader not writing to Normals/Depth with alpha clipping, so it writes a normal for the entire quad of the leaf and so you're seeing the effect kind of working on the edges of the quads instead of the edges of the leaves texture. Switch the debug to "view normals" to see it this is the case. To solve this the underlying shader needs to be modified to alpha clip() when writing to normals.

    The problem with the second screenshot is just that Unity sadly doesn't provide enough precision in the Depth texture, so you sometimes get artifacts like this with Reconstruct From Depth.
    In ScreenSpaceCavityCurvature/Shaders/Shared.cginc line 148
    if (abs(normal_diff) <= 0.1) return 0;

    You can try playing around with the 0.1 value of this low pass filter, see if anything changes for you. It's quite scene dependent.
     
    Last edited: Jan 29, 2023
  12. royhathaway

    royhathaway

    Joined:
    Sep 7, 2018
    Posts:
    2
    Thank you JollyTheory,

    When you pointed out that the shader needs to be modified to alpha clip that made all the difference! I am still learning all the intricacies of shaders and sometimes balancing all these areas of "expertise" one must master can be overwhelming.

    I really appreciate you taking the time to thoroughly explain, thank you!

    Roy
     
    JollyTheory likes this.
  13. mm1982

    mm1982

    Joined:
    Apr 28, 2015
    Posts:
    35
    Hi,

    wondering if anyone has gotten this to work with GPU animated meshes, I'm specifically trying to use this package, Mesh Animator (http://jacobschieck.com/projects/meshanimator/documentation/documentation.html), as in the mesh's animations are baked to textures, and is a regular meshrenderer (no longer a skinned mesh)

    I'm using Forward render, Built-in render pipeline, and "Camera" normals source.
    From SSCC's readme, it says
    "Use View Normals debug mode to see what objects are contributing their normals data to the effect,
    if you have a custom shader and it does not show up in this view, you'll need to either add a Depth pass to it and use Reconstructed normals, or add a DepthNormals pass to it."​
    which is the problem I'm having. As I understand it, the DepthNormals pass is done via the ShadowCaster pass, and the MeshAnimator shaders do have this pass.

    I can get it to work using "Reconstructed normals" source, but that has artifacts and does not work as well as the Camera normals source.
     
  14. AlexplayDev

    AlexplayDev

    Joined:
    Sep 30, 2021
    Posts:
    1
    Can it work without post-processing?
     
  15. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    In URP it uses the Volume system, you could just have a Volume with no other post processing effects, if that's what you mean.
     
  16. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Somebody asked me how to use _SSCCTexture with a custom Amplify Shader Editor shader, here's an example:
     
  17. unity_QJ7RazXzghZCzA

    unity_QJ7RazXzghZCzA

    Joined:
    Jul 9, 2021
    Posts:
    100
    Hello!
    Is it still supported? There is no releases for a half-year. Also how it mobile friendly?
     
  18. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hello, very much still supported.

    Mobile is not /officially/ supported as there is too many phones out there, but many people had perfect success with using this on mobile.
     
  19. unity_QJ7RazXzghZCzA

    unity_QJ7RazXzghZCzA

    Joined:
    Jul 9, 2021
    Posts:
    100
    Thanks.
    What about performance side on mobile?
     
  20. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    The effect is similar to SSAO in performance.
     
  21. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Just submitted version 1.1.4: Better Unity 2022.3 support, 2023.1 support.
    Should be live as soon as the asset store team approves it. Thank you.
     
  22. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,869
    I saw the update note "control per object." Before I fetch the update, does that involve a significant amount of work to integrate? I would like to disable it for some portal objects, for example.
     
  23. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    In that mode it writes the effect to a texture instead of directly to the screen, then your shaders sample that texture to apply the effect to themselves, a copy of URP Lit shader with sampling code is included in the package, if the objects you want to receive the effect do not use the URP Lit shader then you'll have to modify those shaders to receive the effect (just a couple of lines of shader code, all documented inside the included URP Lit shader).
     
  24. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,869
    Ah, I was afraid of that. Effects which require everything in a scene to use custom shaders are just not worth it to me. It's like curved world systems, the issues just pile up after a while.

    Appreciate the note, and happy you implemented that new feature, but it won't work for me, where a very few rare items want to suppress the effect.
     
  25. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    75
    Can this be combined with your soft shadows effect as well? Could you share a picture of both running at the same time?
     
  26. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    They can be combined.
     
    Finijumper likes this.
  27. ntquang1999

    ntquang1999

    Joined:
    May 25, 2021
    Posts:
    4
    Does this work well with mobile? Does this cost performance?
     
  28. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, mobile is not officially supported as there's just too many devices out there to claim things, but since this is just a straightforward post processing effect many people had success with using it on mobile. Performance cost is similar to SSAO on low setting.
     
  29. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    60
    Nice effect. But I can't get it to work with MSAA. The screen turns beige and console gets flooded with this:

    A multisampled texture being bound to a non-multisampled sampler. Disabling in order to avoid undefined behavior. Please use Texture2DMS in the shader.
     
  30. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, i tried MSAA in 2021, 2022, 2023, and could not reproduce your issue.
    Could you please email me (jollytheorygames at gmail.com) with what pipeline you're using, your unity version, whether this is in build or in editor, and whether you're on DirectX/Metal or Vulkan, thank you.
     
  31. AliasPol

    AliasPol

    Joined:
    Jan 26, 2017
    Posts:
    12
    Hi. I have a litle problem with this effect and i dont know how to fix it.
    The problem occur with Micro splat type of material. In editor evrythink works fine and good, but when i build the game the material looks transparent
    upload_2023-8-7_9-45-2.png

    But in editor is not:
    upload_2023-8-7_10-0-46.png

    Micro splat settings:

    upload_2023-8-7_10-10-15.png
    upload_2023-8-7_10-10-35.png

    Model settings:
    upload_2023-8-7_10-12-25.png

    I dont really know what a problem is thx for all help in advance.
     
  32. AliasPol

    AliasPol

    Joined:
    Jan 26, 2017
    Posts:
    12
    SSCC settings:
    upload_2023-8-7_10-17-18.png
     
  33. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, I played around with MicroSplat and there seems to be some bug with the VertexMesh shader type and any kind of post processing effect that requires DepthNormals. Even URP SSAO bugs out for me. So it seems just some general bug in MicroSplat. Setting the rendering to Deferred seems to avoid some of these bugs though, so as a quick fix you could try that.
     
  34. TechNose

    TechNose

    Joined:
    Dec 23, 2022
    Posts:
    1
    I bought this asset and truly love what it is capable of doing. Really makes everything pop so to speak.

    But, I am developing a VR Game on the Oculus Quest 2. My initial go with this seemed promising l, but the moment I built my game and tested it, the game was very laggy and the effect covered the screen as if it was cranked up to 100%. Lol.

    Do you have any recommended settings to get working?
     
  35. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, VR is not officially supported with this asset. Do you have any other post processing effects enabled? If this is your first post processing effect enabled requiring DepthNormals it might affect performance a bit, but that would be the case with any other post effect like SSAO and shouldn't affect it to the post of feeling 'laggy'. Any errors in the build log? Could you send me some more info about your project/scene via email (jollytheorygames at gmail com)? I reply there faster. Thanks.
     
  36. Chris7899

    Chris7899

    Joined:
    Jul 19, 2020
    Posts:
    4
    Hi, bought this yesterday and tried to get it running (Unity 2022.3.2f1 LTS) and URP 14.0.8.
    Adding the SSCC Render Feature to the URP Renderer shows the effect initially in the scene view, but if I hit play, I receive an error:

    NullReferenceException: Object reference not set to an instance of an object
    ScreenSpaceCavityCurvature.Universal.SSCCRendererFeature.AddRenderPasses (UnityEngine.Rendering.Universal.ScriptableRenderer renderer, UnityEngine.Rendering.Universal.RenderingData& renderingData) (at Assets/Screen Space Cavity Curvature/SRP/URP/Runtime/SSCCRendererFeature.cs:324)
    UnityEngine.Rendering.Universal.ScriptableRenderer.AddRenderPasses (UnityEngine.Rendering.Universal.RenderingData& renderingData) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/ScriptableRenderer.cs:1368)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderSingleCamera (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.CameraData& cameraData, System.Boolean anyPostProcessingEnabled) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/UniversalRenderPipeline.cs:637)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderCameraStack (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera baseCamera) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/UniversalRenderPipeline.cs:816)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/UniversalRenderPipeline.cs:362)
    UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) (at <c2d036c16ca64e0eb93703a3b13e733a>:0)
    UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, UnityEngine.Object renderRequest, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <c2d036c16ca64e0eb93703a3b13e733a>:0)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)

    And the scene view and game view go black. Even after stopping play, the camera views stay grey until I remove the Render Feature from the URP Renderer.

    The URP demo scene works however, it's my own scene that has some trouble with it.
    Any idea what might be wrong?
     
  37. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, never encountered anyone having a problem like this. Did the SSCC.shader import properly? Try right click -> Reimport the whole SSCC folder.
    It is weird to be having a NullReferenceException in AddRenderPasses(), as all other parameters in there are provided by Unity and I can't really see them ever being null. If it works in one scene but not the other, disabling things that are different between the two scenes one by one until you find the culprit might hopefully narrow it down.
     
  38. Chris7899

    Chris7899

    Joined:
    Jul 19, 2020
    Posts:
    4
    Thanks, I think I found the culprit. The package apparently has issues with URP Crest Ocean System. In Crest there is a system to capture ocean depth cache. If this component is active at hitting play and SSCC is also active the error happens. If the ocean depth cache is activated a bit later manually, no error happens.
    The the ocean depth cache is running apparently a scan at startup and my guess is, that both, the ocean depth cache and the SSCC are using/manipulating some depth cam stuff at the same time, which creates a conflict.
     
  39. Shieltn

    Shieltn

    Joined:
    Oct 26, 2017
    Posts:
    1
    Hi, are there any plans to add SSCCTexture support for HDRP in the near future? Nice plugin :) Thx
     
  40. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    So I'm using SRP and OVRCameraRig. I've placed the script onto the centerEye Camera and made adjustments to my liking. When I build and test in the Quest 2 it's not working correctly. Anyone have specific settings or steps that will make it work? I've seen comments saying it works...
     
  41. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, unfortunately HDRP doesn't provide an injection point to support a feature like _SSCCTexture output. There could be a way to make it work in the future with something called "Custom Pass Volume" but it would be clanky and require a lot of setup/support from me. So for now no plans to add that, sorry. HDRP custom post processing is kind of a mess.
     
  42. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, >>I've placed the script onto the centerEye Camera.
    In URP make sure you're adding the effect to your Volume, not a MonoBehaviour on your camera. The MonoBehaviour is for the built-in pipeline.
    Is there no effect visible on screen, or is it weirdly shifted/duplicated?
    Thanks.
     
    Last edited: Oct 11, 2023
  43. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hey all,
    Just wanted to post an example of sampling _SSCCTexture output mode with shadergraph:
    Turn off 'exposed' checkbox on the texture property.
     
  44. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I am using Built In (SRP) and the MonoBehaviour on the camera. I'm getting one eye with all the objects grey and odd looking, while the other eye has colored object as normal, but both are very pixelated and laggy.
     
  45. notprashanth

    notprashanth

    Joined:
    Mar 6, 2015
    Posts:
    2
    Unity 2022.3.10 URP // Mobile Game

    We used this globally and noticed a significant frame rate drop on build when enabled (it's fine on unity editor) We tried testing the same on an empty scene and noticed that the frame rate was still getting capped at 20fps for some reason. I understand the package is not optimized for mobile but would you know why the frame rate drop is significant and oddly constant even on an empty scene? We eventually wanted to apply this per object but seeing the performance on empty scene, we're wondering if there's some other issue behind this.

    Enabled.jpg Disabled.jpg
     
  46. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, Answered your email version of your message.

    Hi, VR is not officially supported by this asset. But i think some other people had success with disabling/enabling stereo rendering.
     
    Last edited: Oct 16, 2023
    Proto-G likes this.
  47. Tu-Dinh

    Tu-Dinh

    Joined:
    Dec 12, 2012
    Posts:
    9
    Does this assets compatible with WebGL platform? Thanks
     
  48. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, WebGL is not officially supported but I just checked and it worked with Built-In and URP both.