#Accumulating and fading color on a render texture

1 messages · Page 1 of 1 (latest)

lime lark
#

I'm trying to accumulate white color on a texture that is also faded over time. It paints white on the texture based on player's location.

How do I begin to do this? All I really know is that it involves a camera and render textures but I don't really know how to accumulate the color and fade it to create a trail that follows the player.

I've tried to follow somewhat-related tutorials such as snow deformation (though my use-case is NOT for snow) but they're all either:

  • Using a different render pipeline (I'm using URP)
  • Use shadergraph (I refuse to use it due to the many limitations it has and find it almost impossible to translate the shadergraphs in the video to HLSL)
  • Use out of date APIs

so I haven't really been able to gain much from them.

All I really have right now is a basic skeleton class that creates a render texture. I don't know what to do to it beyond that.

    [SerializeField] RenderTexture accumulationTexture;
    
    Camera cam;
    private void OnEnable()
    {
        cam = GetComponent<Camera>();
    }

    private void OnDisable()
    {
        ReleaseResources();
    }

    private void CreateResources()
    {
        //Create a B/W texture to store player position
        if (accumulationTexture == null)
        {
            accumulationTexture = new RenderTexture(Screen.width / 4, Screen.height / 4, 0, RenderTextureFormat.ARGB32)
            {
                enableRandomWrite = true,
                filterMode = FilterMode.Point,
                wrapMode = TextureWrapMode.Clamp
            };
            accumulationTexture.Create();
        }
        
    }

    private void ReleaseResources()
    {
        if (accumulationTexture != null)
        {
            accumulationTexture.Release();
            accumulationTexture = null;
        }
    }

    private void Update()
    {
        //Ensure resources are created
        if (accumulationTexture == null)
        {
            CreateResources();
        }
        
        //Do something to accumulate player position into the texture
    }

Would really like to be pointed in the right direction.