This repository has been archived on 2023-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
PainterlyUNO/Matrix App/PregeneratedMods/Rain.cs

60 lines
1.6 KiB
C#
Raw Normal View History

2021-06-09 16:43:27 +00:00
using System;
using System.Collections.Generic;
using System.Text;
namespace Matrix_App.PregeneratedMods
{
public sealed class Rain : MatrixGifGenerator
{
2021-06-11 11:36:55 +00:00
private static float Fract(float x)
2021-06-09 16:43:27 +00:00
{
return x - MathF.Floor(x);
}
2021-06-11 11:36:55 +00:00
private static float Step(float x, float y)
2021-06-09 16:43:27 +00:00
{
return y > x ? 1.0f : 0.0f;
}
2021-06-11 11:36:55 +00:00
private static float Shower(float u, float v, float x, float y, float t, float frame)
2021-06-09 16:43:27 +00:00
{
2021-06-11 11:36:55 +00:00
var movY = Fract(v - frame * t + y + MathF.Sin(u * 5.0f) * 0.3f);
2021-06-09 16:43:27 +00:00
2021-06-11 11:36:55 +00:00
var opacityX = Step(0.7f, Fract((u + x) * 93.0f));
var opacityY = Step(0.6f, movY);
2021-06-09 16:43:27 +00:00
2021-06-11 11:36:55 +00:00
var drop = MathF.Pow(movY, 6.0f);
2021-06-09 16:43:27 +00:00
return opacityX * opacityY * drop;
}
protected override void ColorFragment(in int x, in int y, in float u, in float v, in int frame, out float r, out float g, out float b)
{
2021-06-11 11:36:55 +00:00
var time = frame / (totalFrames * 0.5f);
2021-06-09 16:43:27 +00:00
2021-06-11 11:36:55 +00:00
var s1 = Shower(u, v, 0.00f, 0.0f, 1.0f, time);
var s2 = Shower(u, v, 3.11f, 0.5f, 1.0f, time);
var s3 = Shower(u, v, 3.40f, 0.2f, 0.6f, time);
var s4 = Shower(u, v, 3.20f, 0.7f, 0.6f, time);
2021-06-09 16:43:27 +00:00
2021-06-11 11:36:55 +00:00
var skyLight = (Fract(MathF.Sin(u * v + v) * 67128.0f + time) * 0.3f + 0.7f) * (1.3f - v);
2021-06-09 16:43:27 +00:00
r = skyLight * 0.1f;
g = skyLight * 0.2f;
b = skyLight * 0.3f;
g += 0.5f * s1;
b += s1;
g += 0.4f * s2;
b += s2;
g += 0.2f * s3;
b += 0.3f * s3;
g += 0.1f * s4;
b += 0.2f * s4;
}
}
}