Search Unity

Feature Request Features I implemented in my URP fork and I wish they were in the engine

Discussion in '2D Experimental Preview' started by ThundThund, Jun 14, 2021.

  1. ThundThund


    Feb 7, 2017
    (I've re-posted this thread as I cannot move it, I think this is a better place for it)

    I forked the Github repository of the URP and spent around 1 week, in total, to implement several features in the 2D Renderer that were required for Silicon Heart to look visually acceptable. As a first step, I stopped using Shadergraph and converted all shaders to HLSL/Cg.

    Multiple render targets

    In order to be able to achieve some post-processing FXs, I needed 2 additional render targets to which to write for all the sprites in the scene. I modified the ScriptableRenderer, Renderer2D and Renderer2DData classes.

    Now I can specify additional render targets using the inspector:


    Emissive colors

    This is implemented in the shaders. If the Unlit checkbox is checked, I ignore the light textures and use colors of the main texture of the sprite directly; if it's unchecked, then I mix the main color, the light color and the colors coming from a secondary texture (chosen in the Sprite editor). The emissive color depends also on a power multiplier and a color that affects all emissive pixels.


    Additionally, emissive pixels are written to the Bloom render target.

    Bloom FX limited to emissive colors

    One thing I didn't like of the official implementation of the Bloom FX in Unity is that it affected everything. This may be desirable sometimes, though. I wanted that only shiny things were affected so I added another render target to write to, and passed that texture to the existing post-processing FX (PostProcessPass class), in the Renderer2D class.


    Configurable alpha blending

    Sometimes you need to change how colors are blended. A common case is when creating energy or fire VFX. I added this possibility to my shaders and used a custom shader inspector to display the options in a friendly way. This is a built-in feature for normal URP Shadergraph shaders, but does not exist for the 2D Renderer.


    Custom post-processing FXs

    I created new post-processing FXs (which is not possible with the 2D Renderer at the moment) by modifying the Renderer2D class and copying and reducing the PostProcessPass class.
    For example, I used displacement maps (to simulate shockwave FXs) written when the sprites are rendered and the used that texture in a post-processing FX to calculate the colors:

    Here you can see 2 of them combined (vignette with texture and distortion):


    Revived Freeform lights Falloff offset in v2021

    The Falloff offset feature of the 2D lights was removed in version 2021. I need it in my project so in order to be able to upgrade the editor, I revived it. If you need it, you can take the commit from here:

    Light volume textures

    I wanted to fake the visual effect of the light on an illusory mass of smoke. To achieve this, I modified the 2D lights (Light2D, RendererLighting and Light2DEditor classes, and the Volumetric versions of the Light2D shaders). Now I can add animated textures to the lights and combine them as needed to simulate whatever I want:

    Shadow rendering optimization

    Do you use ShadowCaster2Ds and want the performance of your game drastically boosted? I wanted that too.
    I created a class derived from ShadowCaster2D that takes all the meshes of the ShadowCaster2Ds in the child objects and blends them together into one. Then all the ShadowCaster2Ds are disabled or destroyed. So when the shadows are to be rendered, there is only 1 draw call instead of 1 per shadow caster (which, in fact, produces many more than 1). It's like what I would have expected from the CompositeShadowCaster2D, a way to group shadow casters.
    I got a boost of +50% of performance in some cases, although it depends on the scene setup.
    Here is the demonstration:


    That's all for now!
    Other things I shared with the community that you may find useful:
    Last edited: Jul 4, 2021
    Lo-renzo, MarekUnity, JoNax97 and 3 others like this.
  2. GliderGuy


    Dec 14, 2018
    I realize that the 2D URP team is ridiculously understaffed — however, I still find it disturbing that in one week you implemented features that the community have wanted for an entire year. :eek:

    Amazing job, @ThundThund. ;)
    Maybe one day 2D URP will be open source and you can be the person to maintain it for us? :p
  3. ThundThund


    Feb 7, 2017
    Thank you @GliderGuy . If they pay me for that, we can start talking :D
    GliderGuy likes this.
  4. ThundThund


    Feb 7, 2017
    Shadow softening

    Many people complain about the aliasing of the 2D shadows. I have applied gaussian blur to the light texture before it is blended so they now look as soft as I want (I get the best result by blurring them just a little). This does not affect the volume of the lights as they are rendered in a different way that does not allow me to apply the same technique.

    Reducing 2D Light volume banding

    If you have using 2D lights with volume opacity > 0, you may have seen the ugly banding effect in the gradients. You can mitigate this by applying some dithering. It darkens the light a bit but it's worth.

  5. pahe


    May 10, 2011
    Man, awesome work. I hope those things get merged into the master at some point!
    ThundThund and GliderGuy like this.
  6. ThundThund


    Feb 7, 2017
    Thank you pahe! I hope Unity guys decide to add these features officially in the near future, as they are not hard to do (if you know the codebase). I think they just need a bit of pressure by the dev community, currently they don't see the 2D Renderer as a priority.
    pahe and GliderGuy like this.