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

Replace/improving the built-in cascaded shadow mapping shader

Discussion in 'Shaders' started by jcabeleira, Jan 3, 2011.

  1. jcabeleira

    jcabeleira

    Joined:
    Jan 3, 2011
    Posts:
    13
    Hi, I have activated the soft shadows for my directional light but they don't look good as they could be. I want to improve them with a rotation of the sampling pattern, but I'm not sure how to access Unity's built-in shadow mapping shaders.

    In the .zip file of the built-in shaders provided on the Unity website, I have found a shader called "Internal-PrePassCollectShadows.shader" which seems to be the original shader that I need to modify. However, I have no ideia how to replace the built in shader by the modified version and whether if it will work for both deferred and forward rendering.

    Could some one provide advice? Thanks in advance.
     
  2. jcabeleira

    jcabeleira

    Joined:
    Jan 3, 2011
    Posts:
    13
    Anyone?.. please?
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    to replace the built in just drop this one into the project
    as it will be handled later than the integrated one it will overwrite the integrated one (shaders are refered to by their name and you overwrite has the same as the internal one)

    thats how the terrain shaders were replaced since U2 :)
     
  4. jcabeleira

    jcabeleira

    Joined:
    Jan 3, 2011
    Posts:
    13
    Thanks for the tip, I've tried that but no matter what I do, I can't get my modified version of a built in shader to override the built in one.

    For instance, if I add the "Normal-Diffuse.shader" file to the project and modify it, the changes have no effect.

    Could you provide more instructions on how to perform the override?
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Its not about the file, its about the defined name of the shader at the beginning
     
  6. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    dreamora is not actually correct. While this trick of "drop in your own shader to replace built-in ones" works in some cases (like Terrain), it does not in other cases. At the moment you can't override the shader used for shadowmap blurring. I'll see if I can make that happen for next release.
     
  7. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    *bump*
    Any news on whether this will happen in 3.2 ?
     
  8. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Aras has said we'll be able to define a custom shadow blur shader in 3.2 (Yay!) but I don't think we'll be able to completely replace the shadowing system with shaders.
     
  9. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    That's nice, I noticed that the shadow blur filter is in the Built-in Shaders package. So I assumed that it was possible to replace it.
    But I'm trying to find a workaround for the bug that shadows, SSAO and most other shaders are broken when you use non-standard projection matrices.
    So this isn't helpful in my situation.
     
  10. ZachGriffin

    ZachGriffin

    Joined:
    Apr 1, 2010
    Posts:
    49
    Could you also expose the distances of the different cascade levels too Aras? To get crisp shadows currently, we have to set the shadow distance to be about 20-30mts when we really need them at 200mts. If we could set the first cascade level to be 5mts then it would solve most of the problems even with 4 cascade levels
     
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    assumed that it worked for all those shaders where the sources are provided by the built-in shaders as it makes not that much sense to have the source if you can't alter it at least to me, sorry for missinformation there from my end then.
     
  12. gtpdzbiz

    gtpdzbiz

    Joined:
    Mar 21, 2011
    Posts:
    53
    Bump this~ we should also get some access to a specific shadow map, maybe expose this as Light.shadowmap or some thing similar.
     
  13. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    630
    Is this possible to replace unity shadows now?
     
  14. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    No... to replace them, you'd have to replace the whole Unity's rendering process... which is what I'm working on, by the way.
     
  15. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    630
    Have you started a thread about this as I would like to follow your progress :)
     
  16. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    No.. not yet. There's not much to look at anyways as it's still quite early in development. I just made point light shadows work today. What's strange is that with comparable quality, they render three times as fast as Unity's!

    EDIT: Yep... seems like Unity is overrating the resolution a bit ;)
     
    Last edited: Aug 18, 2013
  17. WGermany

    WGermany

    Joined:
    Jun 27, 2013
    Posts:
    78
    I would like to see your progress too, this means you can add area lights too right? And you could apply ambient occlusion with the ambient light like how its supposed to be? So many possibilities I would love to see what can be done, maybe even turn it into an open source kinda thing where everyone chimes in and see what we can do to improve the quality and rendering in Unity! :grin:
     
  18. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Vast majority of things can be implemented, yes. There are several places you can apply ambient occlusion... ambient light, near lightmaps and other forms of GI is the correct place, you have to use the good old darkening if you don't have any of these. But yeah, that would definitely be an option :)

    There's still a long way full of surprises to the release, but I imagine I'd release one free (or very cheap) open-source version with only the basic stuff in it that you can modify to your hearts desire and then possibly sell it on the store and one paid version with all the fancy features.

    I'll make a thread for this once I can get the shadows to filter properly (probably going for ESSM)... turns out it's not a trivial thing to do with cubemaps.
     
  19. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    630
  20. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Well, me too! Sorry it takes so long... these days have been quite lazy for me.
     
  21. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    630
    It's fine. I can't imagine how much work it is. The day unity shadows gets an overhaul is gonna be a good day indeed. I definitely think cryengine has the best real time shadows .
     
    Last edited: Aug 24, 2013
  22. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    630
  23. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Nice find! Unfortunately, it's not just about shadows... I noticed some performance issues and I still want to get rid of light volumes and use quads instead.
     
  24. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    630
    Is that possible to change in unity?
     
    Last edited: Aug 28, 2013
  25. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    I don't think you're getting me here... I'm redoing the rendering engine... everything is possible!

    I'll write a post about it soon
     
  26. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    630
    Oh ok,sorry I guess I was confused. Can't wait for your post!
     
  27. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576