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

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

Discussion in 'Made With Unity' started by AlexVillalba, Jun 6, 2021.

  1. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    344
    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:

    E1tDdXqXsAMZZk3.jpg

    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.

    upload_2021-6-6_0-31-1.png

    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.

    upload_2021-6-6_0-42-38.png

    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.

    upload_2021-6-6_0-47-47.png

    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):

    upload_2021-6-6_1-47-24.png



    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:
    https://github.com/QThund/Graphics/...a75f0e1c86cdf6b13f88af8d77f04301e9&diff=split

    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:
     
  2. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Nice. Thank you for sharing.