using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SnowFall: MonoBehaviour
{
    public Shader snowFallShader;
    Material snowFallMat;
    MeshRenderer meshRenderer;
    [Range(0.001f, 0.1f)]
    public float snowFlakeAmount = 0.1f;
    [Range(0f, 1f)]
    public float snowFlakeOpacity = 1;
    // Start is called before the first frame update
    void Start()
    {
        meshRenderer = GetComponent<MeshRenderer>();
        snowFallMat = new Material(snowFallShader);
    }

    // Update is called once per frame
    void Update()
    {
        snowFallMat.SetFloat("_FlakeAmount", snowFlakeAmount);
        snowFallMat.SetFloat("_FlakeOpacity", snowFlakeOpacity);
        RenderTexture snow = (RenderTexture)meshRenderer.material.GetTexture("_Splat");
        RenderTexture tmp = RenderTexture.GetTemporary(snow.width, snow.height, 0, RenderTextureFormat.ARGBFloat);
        Graphics.Blit(snow,tmp, snowFallMat);
        Graphics.Blit(tmp, snow);
        meshRenderer.material.SetTexture("_Splat", snow);
        RenderTexture.ReleaseTemporary(tmp);
    }
}
