Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Decal Projector Performance

Discussion in 'High Definition Render Pipeline' started by Liderangel, Sep 7, 2020.

  1. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101
    Hi there, we need some help with the performance using the Decal Projectors in HDRP.

    Basically if you shoot an enemy, blood comes out, and then it paints the floor red. That works perfectly using the decal projector. But the performance drops massively from each shot, which is quite weird considering I read that some people made tests with 500 decal projectors and saw basically no drop in FPS. Sadly this isn't our case, we start with about 130 FPS and after a couple of shots (10-20 decal projectors) and end up with 80 FPS on a 1080 Ti.
    I wrote a coroutine to delete the decals after 10 - 20 seconds, and that works, but feels like a cheap solution to a clearly much bigger issue (if in the timespan of the 10-20 seconds the Player rams the entire level then he would be at 0 FPS lol, of course I could clamp the max decals but where's the fun in that).

    This are the settings on the HDRP asset:



    We tried using the default Unity Shader and then made a custom one using Amplify Shader Editor, performance was the same.
    The texture used for the blood was compressed to basically pixel art just for testing in the import settings (32x32 on high compression) and no change in FPS.


    We are using Unity 2019.4.1f1 with HDRP 7.3.1 (the one that's 2019.4 verified).


    Thanks!
     
  2. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101
    Okey, I found the cause of the problem, but now I need a solution to a new issue.

    When a blood decal spawns, we create a new material to it based on the one that the decal projector has, and re-apply it, so we can change its color, size (a noise inside the shader to make it look like its "spreading"), and other cool effects.
    Sadly by only doing the new material part Unity dies in performance (I assume that it makes super performance optimizations since all of the decals share the same material).
    Of course we can't really skip this part since if we change 1 of the blood properties all of the others get changed equally (blood that was disappearing now reappears due to a new one getting spawned since they are sharing the material).

    How can we edit the properties of the decal material without having to create an instance of it each time we spawn a new one?


    I'm thinking of Material Block Property but I can't find a way to use that on a Decal Projector.
     
    Last edited: Sep 7, 2020
  3. MylesLambert

    MylesLambert

    Joined:
    Dec 31, 2012
    Posts:
    61
    Did you find a solution for this? There's a lot of cases where being able to modify the material property block for decals would be useful!
     
  4. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101

    We haven't and at the moment we've stopped trying. The blood is functional at the moment and the only effect we added is a global one that acts on the shared material. If anyone finds a solution we are still listening!
     
  5. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    267
    Last edited: Nov 16, 2021
  6. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
  7. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    267
    Yes, it will be backported in both 2021.2 and 2020.3
     
  8. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101

    That's excellent to hear! Thanks! We are actually planning on perhaps moving to URP to support the Nintendo Switch, and seeing the title of the PR makes me wonder if same performance issue happens there since this fix applies only to HDRP.
     
    hippocoder likes this.
  9. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    267
    That shouldn't be needed for URP as they are using another kind of system for decals
     
    Liderangel likes this.
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Wow now that's what I call a result! 13.39->2.60 ms!
     
  11. Danielsantalla

    Danielsantalla

    Joined:
    Jan 7, 2015
    Posts:
    75
    Si just to be clear, we can’t use property blocks on decals right? Any workaround?