Skip to content

Commit 6dd4058

Browse files
committed
Deprecate CustomShader
1 parent b447031 commit 6dd4058

3 files changed

Lines changed: 26 additions & 46 deletions

File tree

source/funkin/backend/scripting/Script.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Script extends FlxBasic implements IFlxDestroyable {
8989
"Paths" => funkin.backend.assets.Paths,
9090
"Conductor" => funkin.backend.system.Conductor,
9191
"FunkinShader" => funkin.backend.shaders.FunkinShader,
92-
"CustomShader" => funkin.backend.shaders.CustomShader,
92+
"CustomShader" => funkin.backend.shaders.CustomShader, // deprecated
9393
"FunkinText" => funkin.backend.FunkinText,
9494
"FlxAnimate" => animate.FlxAnimate,
9595
"FunkinSprite" => funkin.backend.FunkinSprite,

source/funkin/backend/shaders/CustomShader.hx

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,15 @@ package funkin.backend.shaders;
22

33
import openfl.Assets;
44

5-
/**
6-
* Class for custom shaders.
7-
*
8-
* To create one, create a `shaders` folder in your assets/mod folder, then add a file named `my-shader.frag` or/and `my-shader.vert`.
9-
*
10-
* Non-existent shaders will only load the default one, and throw a warning in the console.
11-
*
12-
* To access the shader's uniform variables, use `shader.variable`
13-
*/
5+
@:deprecated("Use funkin.backend.shaders.FunkinShader.fromFile instead.")
146
class CustomShader extends FunkinShader {
15-
public var path:String = "";
7+
@:isVar
8+
public var path(get, set):String;
9+
inline function get_path():String return path != null ? path : _fragmentFilePath + _vertexFilePath;
10+
inline function set_path(v:Null<String>):String return path = cast v;
1611

17-
/**
18-
* Creates a new custom shader
19-
* @param name Name of the frag and vert files.
20-
* @param glslVersion GLSL version to use. Defaults to `120`.
21-
*/
22-
public function new(name:String, glslVersion:String = null) {
23-
if (glslVersion == null) glslVersion = Flags.DEFAULT_GLSL_VERSION;
24-
var fragShaderPath = Paths.fragShader(name);
25-
var vertShaderPath = Paths.vertShader(name);
26-
var fragCode = Assets.exists(fragShaderPath) ? Assets.getText(fragShaderPath) : null;
27-
var vertCode = Assets.exists(vertShaderPath) ? Assets.getText(vertShaderPath) : null;
28-
29-
fileName = name;
30-
fragFileName = fragShaderPath;
31-
vertFileName = vertShaderPath;
32-
33-
path = fragShaderPath+vertShaderPath;
34-
35-
if (fragCode == null && vertCode == null)
36-
Logs.error('Shader "$name" couldn\'t be found.');
37-
38-
super(fragCode, vertCode, glslVersion);
12+
public function new(name:String, ?glslVersion:String) {
13+
super();
14+
loadShaderFile(Paths.fragShader(name), Paths.vertShader(name), glslVersion);
3915
}
4016
}

source/funkin/backend/shaders/FunkinShader.hx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour {
3030
public var onGLUpdate:FlxTypedSignal<Void->Void> = new FlxTypedSignal<Void->Void>();
3131

3232
public function new(?fragmentSource:String, ?vertexSource:String, ?version:String) {
33-
super(fragmentSource, vertexSource, version);
33+
super(fragmentSource, vertexSource, version ?? (fragmentSource != null || vertexSource != null ? Flags.DEFAULT_GLSL_VERSION : null));
3434
}
3535

3636
public static function fromFile(fragmentPath:String, ?vertexPath:String, ?version:String):FunkinShader {
@@ -44,7 +44,9 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour {
4444
else vertexPath = fragmentPath.substr(0, idx);
4545
}
4646

47-
_fromFile(FlxRuntimeShader._getPath(fragmentPath, false), FlxRuntimeShader._getPath(vertexPath, true), version);
47+
fragmentPath = FlxRuntimeShader._getPath(fragmentPath, false);
48+
vertexPath = FlxRuntimeShader._getPath(vertexPath, true);
49+
_fromFile(fragmentPath, vertexPath, version ?? (fragmentPath != null || vertexPath != null ? Flags.DEFAULT_GLSL_VERSION : null));
4850

4951
return this;
5052
}
@@ -156,6 +158,18 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour {
156158
private static var FRAGMENT_SHADER = 0;
157159
private static var VERTEX_SHADER = 1;
158160

161+
public var fileName(get, set):String;
162+
inline function get_fileName():String return _fragmentFilePath ?? _vertexFilePath ?? "FunkinShader";
163+
inline function set_fileName(v:String):String return _fragmentFilePath = _vertexFilePath = v;
164+
165+
public var fragFileName(get, set):String;
166+
inline function get_fragFileName():String return _fragmentFilePath ?? "FunkinShader";
167+
inline function set_fragFileName(v:String):String return _fragmentFilePath = v;
168+
169+
public var vertFileName(get, set):String;
170+
inline function get_vertFileName():String return _vertexFilePath ?? "FunkinShader";
171+
inline function set_vertFileName(v:String):String return _vertexFilePath = v;
172+
159173
public var glslVer(get, set):String;
160174
inline function get_glslVer():String return glVersion;
161175
inline function set_glslVer(v:String):String return glVersion = v;
@@ -168,17 +182,7 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour {
168182
inline function get_glRawVertexSource():String return __glVertexSourceRaw;
169183
inline function set_glRawVertexSource(v:String):String return __glVertexSourceRaw = v;
170184

171-
public var fileName(get, set):String;
172-
inline function get_fileName():String return _fragmentFilePath ?? _vertexFilePath ?? "FunkinShader";
173-
inline function set_fileName(v:String):String return _fragmentFilePath = _vertexFilePath = v;
174-
175-
public var fragFileName(get, set):String;
176-
inline function get_fragFileName():String return _fragmentFilePath ?? "FunkinShader";
177-
inline function set_fragFileName(v:String):String return _fragmentFilePath = v;
178-
179-
public var vertFileName(get, set):String;
180-
inline function get_vertFileName():String return _vertexFilePath ?? "FunkinShader";
181-
inline function set_vertFileName(v:String):String return _vertexFilePath = v;
185+
function thisHasField(v:String):Bool return __thisHasField(v);
182186

183187
function registerParameter(name:String, type:String, isUniform:Bool) {
184188
__registerParameter(name, Shader.getParameterTypeFromGLSL(type, false), StringTools.startsWith(type, "sampler"), 1, null, isUniform, null);

0 commit comments

Comments
 (0)