ultraflame4 / MSO_RecycleRight

0 stars 0 forks source link

Cleanable Contaminants Grime / Dirt Effect #78

Closed ultraflame4 closed 2 months ago

ultraflame4 commented 2 months ago

Some contaminants are cleanable (eg. bottles, tupper-ware containers). To indicate how dirty they currently are, we can introduce a "grime" effect. This will essentially be another sprite overlayed on top of the main contaminant sprite in unity (Some masking might be needed).

Image

The above image shows the various stages of the grime from left to right (ignoring the first frame) as it gets from very dirty to less dirty. The grime is represented be the black spots and the contaminant NPC is represented by the red circle.

Essentially, as contaminant gets cleaned, the dirt slowly dissapears until it completely dissappears, when that happens the contaminant should become a recyclable.

ultraflame4 commented 2 months ago

Creating grime using texture + shadergraph(perlin noise) honestly doesn't look that good. Will manually create each grime stage instead. And maybe use shadergraph to mask it. See commit: c9e30a471444ce73688c81b4bdde4b3b89a08704

ultraflame4 commented 2 months ago

I found a component call sprite mask which masks sprite, however it still need to be updated every frame. Created new component at Assets/Scripts/Others/SpriteRendererMask.cs to update the sprite mask's sprite using the sprite from the sprite renderer. This will essentially link the sprite renderer and sprite mask together and make sprite masks also work for animations.

Using sprite mask and sprite renderer together: image

SpriteRendererMask code:

using UnityEngine;

/// <summary>
/// This component updates the SpriteMask's sprite to match the SpriteRenderer's sprite.
/// </summary>
public class SpriteRendererMask : MonoBehaviour {
    [Tooltip("The SpriteRenderer to get the source sprite from.")]
    public SpriteRenderer spriteRenderer;
    [Tooltip("The SpriteMask to update the sprite of.")]
    public SpriteMask spriteMask;

    void LateUpdate() {
        spriteMask.sprite = spriteRenderer.sprite;
    }
}
ultraflame4 commented 2 months ago

Also created the sprites for the various sprite stages. (Grime progression is left to right) image

ultraflame4 commented 2 months ago

Using the new sprites as the grime overlay (with a little bit of color tinting) image Also had to use Sorting Groups to ensure that the Sprite Mask worked properly (the grime was leaking into other sprites) ![Uploading image.png…]()

ultraflame4 commented 2 months ago

Experimented again using shader graph and i think it looks better. Also more dynamic too. At 10% grime image

At 50% grime image 100% grime image

Shadergraph: image This method uses a combination of perlin noise and simplex noise and composites them to generate the pattern.

Will switch to this.

ultraflame4 commented 2 months ago

Created GrimeController.cs to control the material. image