Search Unity

Sprite Shape Fill Tex Render Issue (inconsistent blend mode rendering)

Discussion in '2D' started by Th0re, May 10, 2022.

  1. Th0re

    Th0re

    Joined:
    Sep 4, 2015
    Posts:
    39
    This is Unity 2021.3.1f1, Sprite Shape is current 7.0.4

    TLDR: an identical sprite/texture in combination with blend mode from global 2D Light render a fill texture differently than the same as an edge texture.


    In the image attached you see two sprite shapes, one for the bushes and one for the ground shape. I use a modified version of the Lost Crypt shader with the red channel for rim light working with _MaskTex. There are two global lights 2D, one is standard/default global light, the other is set to use the R/rim channel (either overlap operations cause the issue).


    brightNoRim.png
    Image 1: Here you see it lit only with the standard global light. Note how fill texture is darker than the sprite shape edge texture.

    exaggerated.png
    Image 2: Here I switched on the rim light to an extreme intensity to show the issue. You see that the fill textures of the sprite shape blow out bright, even though they have either no mask texture (bushes) or a black tile (ground), i.e. no rim. Note also that the tree and the edge textures of the sprite shape pick up the colours correctly (or as intended/expected).

    image.png
    Image 3: And here is a less extreme, more use-case appearance I was going for. The effect is naturally not as extreme, but still unintended, that is, the fill of the sprite shape renders 2D light not how I want (or expect).

    Very often the bug sits in front of the screen, so I may be doing something wrong, however I double checked virtually everything, ticked and unticked boxes at random and cannot figure out why this happens.

    Considerations
    * if it was a problem with the shader, it would be wrong on the tree, too.
    * if it was a problem with the MaskTex, ground and bush would not have the same issue (and changing them would make a difference).

    Screenshot 2022-05-11 at 00.56.00.png
    Image 4: Another test, this time using the exact same texture for the edge and the fill. Note that, consistent with the findings above, the fill reacts to lights very differently.

    Can someone point me into the right direction?
     
    Last edited: May 11, 2022
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    I believe the issue is related to FillArea using a Texture (with TextureWrapMode required to be set to Repeat), Secondary Textures are not automatically set for them like Sprites. Please use the MaterialPropertyBlock API to set the secondary maps. A similar issue here : Resolved - Spriteshape 2D lighting - Fill does not support Normal Map - Unity Forum

    If the issue persists, could you kindly submit a bug report with a repro project ? Will take a look asap. Thanks.
     
    Th0re likes this.
  3. Th0re

    Th0re

    Joined:
    Sep 4, 2015
    Posts:
    39
    Thanks a lot! This worked with my hacky code (I'm new to MaterialProertyBlocks). :)

    I guess the easier workflow would be just using different material, and/or shader. It deviates somewhat from the usual sprite workflow, but it seems manageable to have an extra fill material alongside the spriteshape profile (unless secondary textures are turned off for this type, where all such fills could share one).