Advertisement
Syldarion

DiamondFractalImageEffect C#

Jan 5th, 2021
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. [ExecuteInEditMode]
  7. public class DiamondFractalImageEffect : MonoBehaviour
  8. {
  9.     public Material EffectMaterial;
  10.  
  11.     public float effectLifetime;
  12.     public AnimationCurve speedOverTime;
  13.     public AnimationCurve factorOverTime;
  14.     public AnimationCurve zoomOverTime;
  15.  
  16.     private float currentTime;
  17.     private float fractalDistance;
  18.     private float fractalFactor;
  19.     private float uvZoom;
  20.  
  21.     private void Update()
  22.     {
  23.         currentTime += Time.deltaTime;
  24.         float time = (currentTime % (effectLifetime + 2)) / effectLifetime;
  25.         fractalDistance += speedOverTime.Evaluate(time) * Time.deltaTime;
  26.         fractalFactor = factorOverTime.Evaluate(time);
  27.         uvZoom = zoomOverTime.Evaluate(time);
  28.     }
  29.  
  30.     private void OnRenderImage(RenderTexture src, RenderTexture dest)
  31.     {
  32.         EffectMaterial.SetFloat("_FractalDistance", fractalDistance);
  33.         EffectMaterial.SetFloat("_FractalFactor", fractalFactor);
  34.         EffectMaterial.SetFloat("_UvZoom", uvZoom);
  35.        
  36.         Graphics.Blit(src, dest, EffectMaterial);
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement