Skip to content

Commit bfee99a

Browse files
da shaders update
1 parent 9e41c6a commit bfee99a

File tree

12 files changed

+108
-125
lines changed

12 files changed

+108
-125
lines changed

assets/shaders/noteRGB.frag

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma header
2+
3+
uniform vec3 r;
4+
uniform vec3 g;
5+
uniform vec3 b;
6+
uniform float mult;
7+
8+
vec4 flixel_texture2DCustom(sampler2D bitmap, vec2 coord) {
9+
vec4 color = flixel_texture2D(bitmap, coord);
10+
if (!hasTransform || color.a == 0.0 || mult == 0.0) {
11+
return color;
12+
}
13+
14+
vec4 newColor = color;
15+
newColor.rgb = min(color.r * r + color.g * g + color.b * b, vec3(1.0));
16+
newColor.a = color.a;
17+
18+
color = mix(color, newColor, mult);
19+
20+
if(color.a > 0.0) {
21+
return vec4(color.rgb, color.a);
22+
}
23+
return vec4(0.0, 0.0, 0.0, 0.0);
24+
}
25+
26+
void main() {
27+
gl_FragColor = flixel_texture2DCustom(bitmap, openfl_TextureCoordv);
28+
}

source/core/macros/ImportsMacro.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ class ImportsMacro
9595
#end
9696

9797
'funkin.visuals.objects',
98+
'funkin.visuals.shaders',
9899
'funkin.states',
99-
'funkin.substates',
100-
//'funkin.editors'
100+
'funkin.substates'
101101
];
102102

103103
for (pack in packs)

source/funkin/visuals/ALECamera.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package funkin.visuals;
22

3+
import flixel.addons.display.FlxRuntimeShader;
34
import flixel.system.FlxAssets.FlxShader;
45
import flixel.graphics.frames.FlxFrame;
56
import flixel.math.FlxMatrix;
67

8+
import openfl.filters.ShaderFilter;
79
import openfl.geom.ColorTransform;
810
import openfl.display.BitmapData;
911
import openfl.display.BlendMode;
@@ -38,4 +40,7 @@ class ALECamera extends FlxCamera
3840

3941
super.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader);
4042
}
43+
44+
public function setShaders(shaders:Array<FlxRuntimeShader>):Void
45+
filters = [for (shader in shaders) new ShaderFilter(shader)];
4146
}

source/funkin/visuals/shaders/ALERuntimeShader.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class ALERuntimeShader extends FlxRuntimeShader
88
{
99
public var shaderName:String = '';
1010

11-
public function new (?shaderName:String, ?fragmentSource:String, ?vertexSource:String)
11+
public function new (?shaderName:String)
1212
{
1313
this.shaderName = shaderName;
1414

15-
super(fragmentSource, vertexSource);
15+
super(Paths.exists('shaders/' + shaderName + '.frag') ? Paths.getContent('shaders/' + shaderName + '.frag') : null, Paths.exists('shaders/' + shaderName + '.vert') ? Paths.getContent('shaders/' + shaderName + '.vert') : null);
1616
}
1717

1818
override function __createGLProgram(vertexSource:String, fragmentSource:String):GLProgram
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package funkin.visuals.shaders;
2+
3+
import haxe.ds.StringMap;
4+
5+
import flixel.tweens.FlxEase.EaseFunction;
6+
7+
class FXShader extends ALERuntimeShader
8+
{
9+
var _tweens:StringMap<FlxTween> = new StringMap();
10+
11+
public function cancelTween(prop:String)
12+
{
13+
if (_tweens.exists(prop))
14+
{
15+
_tweens.get(prop).cancel();
16+
17+
_tweens.remove(prop);
18+
}
19+
}
20+
21+
public function set(props:Any, value:Float)
22+
{
23+
for (prop in Reflect.fields(props))
24+
{
25+
cancelTween(prop);
26+
27+
setFloat(prop, Reflect.field(props, prop));
28+
}
29+
}
30+
31+
public function tween(props:Any, ?beats:Float, ?ease:EaseFunction)
32+
{
33+
if (!ClientPrefs.data.shaders)
34+
return;
35+
36+
for (prop in Reflect.fields(props))
37+
{
38+
cancelTween(prop);
39+
40+
_tweens.set(prop, FlxTween.num(
41+
getFloat(prop),
42+
Reflect.field(props, prop),
43+
(beats ?? 1) * 60 / Conductor.bpm,
44+
{
45+
ease: ease,
46+
onComplete: (_) -> {
47+
_tweens.remove(prop);
48+
}
49+
},
50+
(val) -> setFloat(prop, val)
51+
));
52+
}
53+
}
54+
}

source/funkin/visuals/shaders/RGBPalette.hx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@ package funkin.visuals.shaders;
22

33
import funkin.visuals.game.Note;
44

5-
class RGBPalette {
6-
public var shader(default, null):RGBPaletteShader = new RGBPaletteShader();
5+
class RGBPalette
6+
{
7+
public var shader(default, null):ALERuntimeShader = new ALERuntimeShader('noteRGB');
8+
79
public var r(default, set):FlxColor;
810
public var g(default, set):FlxColor;
911
public var b(default, set):FlxColor;
1012
public var mult(default, set):Float;
1113

1214
private function set_r(color:FlxColor) {
1315
r = color;
14-
shader.r.value = [color.redFloat, color.greenFloat, color.blueFloat];
16+
shader.setFloatArray('r', [color.redFloat, color.greenFloat, color.blueFloat]);
1517
return color;
1618
}
1719

1820
private function set_g(color:FlxColor) {
1921
g = color;
20-
shader.g.value = [color.redFloat, color.greenFloat, color.blueFloat];
22+
shader.setFloatArray('g', [color.redFloat, color.greenFloat, color.blueFloat]);
2123
return color;
2224
}
2325

2426
private function set_b(color:FlxColor) {
2527
b = color;
26-
shader.b.value = [color.redFloat, color.greenFloat, color.blueFloat];
28+
shader.setFloatArray('b', [color.redFloat, color.greenFloat, color.blueFloat]);
2729
return color;
2830
}
2931

3032
private function set_mult(value:Float) {
3133
mult = FlxMath.bound(value, 0, 1);
32-
shader.mult.value = [mult];
34+
shader.setFloatArray('mult', [mult]);
3335
return mult;
3436
}
3537

@@ -38,6 +40,7 @@ class RGBPalette {
3840
r = 0xFFFF0000;
3941
g = 0xFF00FF00;
4042
b = 0xFF0000FF;
43+
4144
mult = 1.0;
4245
}
4346
}

source/funkin/visuals/shaders/RGBPaletteShader.hx

Lines changed: 0 additions & 43 deletions
This file was deleted.

source/funkin/visuals/shaders/RGBShaderReference.hx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package funkin.visuals.shaders;
22

3-
// automatic handler for easy usability
43
class RGBShaderReference
54
{
65
public var r(default, set):FlxColor;
@@ -68,7 +67,6 @@ class RGBShaderReference
6867
parent.b = _original.b;
6968
parent.mult = _original.mult;
7069
_owner.shader = parent.shader;
71-
//trace('created new shader');
7270
}
7371
}
7472
}

source/scripting/haxe/Extensible.hx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import funkin.debug.*;
2424
import funkin.visuals.*;
2525
import funkin.visuals.game.*;
2626
import funkin.visuals.objects.*;
27-
import funkin.visuals.mobile.*;
27+
import funkin.visuals.shaders.*;
2828

2929
import ale.ui.*;
3030

@@ -60,6 +60,7 @@ class ScriptText extends FlxText implements RuleScriptedClass {}
6060
class ScriptBitmapText extends FlxBitmapText implements RuleScriptedClass {}
6161
class ScriptTextFormat extends FlxTextFormat implements RuleScriptedClass {}
6262

63+
class ScriptALERuntimeShader extends ALERuntimeShader implements RuleScriptedClass {}
6364
class ScriptCamera extends FlxCamera implements RuleScriptedClass {}
6465
class ScriptFXCamera extends FXCamera implements RuleScriptedClass {}
6566
class ScriptALECamera extends ALECamera implements RuleScriptedClass {}

source/scripting/lua/callbacks/LuaShader.hx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import scripting.lua.LuaPresetBase;
44

55
import funkin.visuals.shaders.ALERuntimeShader;
66

7+
import openfl.filters.ShaderFilter;
8+
79
class LuaShader extends LuaPresetBase
810
{
911
override public function new(lua:LuaScript)
@@ -12,19 +14,19 @@ class LuaShader extends LuaPresetBase
1214

1315
set('initLuaShader', function(tag:String, name:String)
1416
{
15-
setTag(tag, CoolUtil.createRuntimeShader(name));
17+
setTag(tag, new ALERuntimeShader(name));
1618
});
1719

1820
set('setCameraShaders', function(camera:String, shaderTags:Array<String>)
1921
{
20-
var procShaders:Array<ALERuntimeShader> = [];
22+
var procShaders:Array<ShaderFilter> = [];
2123

2224
for (tag in shaderTags)
2325
if (tagIs(tag, ALERuntimeShader))
24-
procShaders.push(getTag(tag));
26+
procShaders.push(new ShaderFilter(getTag(tag)));
2527

2628
if (tagIs(camera, FlxCamera))
27-
CoolUtil.setCameraShaders(getTag(camera), procShaders);
29+
getTag(camera).filters = procShaders;
2830
}
2931
);
3032

0 commit comments

Comments
 (0)