1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-23 21:56:46 +00:00
Funkin/source/funkin/graphics/shaders/RuntimeRainShader.hx

153 lines
3.8 KiB
Haxe
Raw Normal View History

2023-12-19 01:49:01 +00:00
package funkin.graphics.shaders;
2023-09-11 15:10:08 +00:00
import flixel.system.FlxAssets.FlxShader;
import openfl.display.BitmapData;
import openfl.display.ShaderParameter;
import openfl.display.ShaderParameterType;
import openfl.utils.Assets;
typedef Light =
{
var position:Array<Float>;
var color:Array<Float>;
var radius:Float;
}
class RuntimeRainShader extends RuntimePostEffectShader
{
static final MAX_LIGHTS:Int = 8;
public var lights:Array<
{
position:ShaderParameter<Float>,
color:ShaderParameter<Float>,
radius:ShaderParameter<Float>,
}>;
public var time(default, set):Float = 1;
function set_time(value:Float):Float
{
this.setFloat('uTime', value);
return time = value;
}
public var spriteMode(default, set):Bool = false;
function set_spriteMode(value:Bool):Bool
{
this.setBool('uSpriteMode', value);
return spriteMode = value;
}
2023-09-13 21:28:59 +00:00
// The scale of the rain depends on the world coordinate system, so higher resolution makes
// the raindrops smaller. This parameter can be used to adjust the total scale of the scene.
// The size of the raindrops is proportional to the value of this parameter.
public var scale(default, set):Float = 1;
function set_scale(value:Float):Float
{
this.setFloat('uScale', value);
return scale = value;
}
// The intensity of the rain. Zero means no rain and one means the maximum amount of rain.
2023-09-15 13:09:59 +00:00
public var intensity(default, set):Float = 0.5;
2023-09-13 21:28:59 +00:00
function set_intensity(value:Float):Float
{
this.setFloat('uIntensity', value);
return intensity = value;
}
2023-09-19 13:31:50 +00:00
// the y coord of the puddle, used to mirror things
public var puddleY(default, set):Float = 0;
function set_puddleY(value:Float):Float
{
this.setFloat('uPuddleY', value);
return puddleY = value;
}
2023-09-25 18:28:55 +00:00
// the y scale of the puddle, the less this value the more the puddle effects squished
public var puddleScaleY(default, set):Float = 0;
function set_puddleScaleY(value:Float):Float
{
this.setFloat('uPuddleScaleY', value);
return puddleScaleY = value;
}
2023-09-23 18:59:24 +00:00
public var blurredScreen(default, set):BitmapData;
2023-09-11 15:10:08 +00:00
2023-09-23 18:59:24 +00:00
function set_blurredScreen(value:BitmapData):BitmapData
2023-09-11 15:10:08 +00:00
{
2023-09-23 18:59:24 +00:00
this.setBitmapData('uBlurredScreen', value);
return blurredScreen = value;
2023-09-11 15:10:08 +00:00
}
2023-09-15 13:09:59 +00:00
public var mask(default, set):BitmapData;
function set_mask(value:BitmapData):BitmapData
{
this.setBitmapData('uMask', value);
return mask = value;
}
2023-10-02 12:05:13 +00:00
public var lightMap(default, set):BitmapData;
function set_lightMap(value:BitmapData):BitmapData
{
this.setBitmapData('uLightMap', value);
return lightMap = value;
}
2024-02-13 08:32:20 +00:00
public var numLightsSwag(default, set):Int = 0; // swag heads, we have never been more back (needs different name purely for hashlink casting fix)
2023-09-11 15:10:08 +00:00
2024-02-13 08:32:20 +00:00
function set_numLightsSwag(value:Int):Int
2023-09-11 15:10:08 +00:00
{
this.setInt('numLights', value);
2024-02-13 08:32:20 +00:00
return numLightsSwag = value;
2023-09-11 15:10:08 +00:00
}
public function new()
{
2023-09-13 21:28:59 +00:00
super(Assets.getText(Paths.frag('rain')));
2023-09-11 15:10:08 +00:00
}
public function update(elapsed:Float):Void
{
time += elapsed;
}
override function __processGLData(source:String, storageType:String):Void
{
super.__processGLData(source, storageType);
2023-09-13 21:28:59 +00:00
if (storageType == 'uniform')
2023-09-11 15:10:08 +00:00
{
lights = [
for (i in 0...MAX_LIGHTS)
{
2023-09-13 21:28:59 +00:00
position: addFloatUniform('lights[$i].position', 2),
color: addFloatUniform('lights[$i].color', 3),
radius: addFloatUniform('lights[$i].radius', 1),
2023-09-11 15:10:08 +00:00
}
];
}
}
@:access(openfl.display.ShaderParameter)
function addFloatUniform(name:String, length:Int):ShaderParameter<Float>
{
final res = new ShaderParameter<Float>();
res.name = name;
res.type = [null, FLOAT, FLOAT2, FLOAT3, FLOAT4][length];
res.__arrayLength = 1;
res.__isFloat = true;
res.__isUniform = true;
res.__length = length;
__paramFloat.push(res);
return res;
}
}