From 6dd4058ac66e5cfefb83112f1e2ffccade4cc764 Mon Sep 17 00:00:00 2001 From: Ralty <78720179+Raltyro@users.noreply.github.com> Date: Sun, 29 Mar 2026 10:04:19 +0700 Subject: [PATCH] Deprecate CustomShader --- source/funkin/backend/scripting/Script.hx | 2 +- source/funkin/backend/shaders/CustomShader.hx | 40 ++++--------------- source/funkin/backend/shaders/FunkinShader.hx | 30 ++++++++------ 3 files changed, 26 insertions(+), 46 deletions(-) diff --git a/source/funkin/backend/scripting/Script.hx b/source/funkin/backend/scripting/Script.hx index 4a03275f..9db6dcb5 100644 --- a/source/funkin/backend/scripting/Script.hx +++ b/source/funkin/backend/scripting/Script.hx @@ -89,7 +89,7 @@ class Script extends FlxBasic implements IFlxDestroyable { "Paths" => funkin.backend.assets.Paths, "Conductor" => funkin.backend.system.Conductor, "FunkinShader" => funkin.backend.shaders.FunkinShader, - "CustomShader" => funkin.backend.shaders.CustomShader, + "CustomShader" => funkin.backend.shaders.CustomShader, // deprecated "FunkinText" => funkin.backend.FunkinText, "FlxAnimate" => animate.FlxAnimate, "FunkinSprite" => funkin.backend.FunkinSprite, diff --git a/source/funkin/backend/shaders/CustomShader.hx b/source/funkin/backend/shaders/CustomShader.hx index 62308e69..61066575 100644 --- a/source/funkin/backend/shaders/CustomShader.hx +++ b/source/funkin/backend/shaders/CustomShader.hx @@ -2,39 +2,15 @@ package funkin.backend.shaders; import openfl.Assets; -/** - * Class for custom shaders. - * - * 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`. - * - * Non-existent shaders will only load the default one, and throw a warning in the console. - * - * To access the shader's uniform variables, use `shader.variable` - */ +@:deprecated("Use funkin.backend.shaders.FunkinShader.fromFile instead.") class CustomShader extends FunkinShader { - public var path:String = ""; + @:isVar + public var path(get, set):String; + inline function get_path():String return path != null ? path : _fragmentFilePath + _vertexFilePath; + inline function set_path(v:Null):String return path = cast v; - /** - * Creates a new custom shader - * @param name Name of the frag and vert files. - * @param glslVersion GLSL version to use. Defaults to `120`. - */ - public function new(name:String, glslVersion:String = null) { - if (glslVersion == null) glslVersion = Flags.DEFAULT_GLSL_VERSION; - var fragShaderPath = Paths.fragShader(name); - var vertShaderPath = Paths.vertShader(name); - var fragCode = Assets.exists(fragShaderPath) ? Assets.getText(fragShaderPath) : null; - var vertCode = Assets.exists(vertShaderPath) ? Assets.getText(vertShaderPath) : null; - - fileName = name; - fragFileName = fragShaderPath; - vertFileName = vertShaderPath; - - path = fragShaderPath+vertShaderPath; - - if (fragCode == null && vertCode == null) - Logs.error('Shader "$name" couldn\'t be found.'); - - super(fragCode, vertCode, glslVersion); + public function new(name:String, ?glslVersion:String) { + super(); + loadShaderFile(Paths.fragShader(name), Paths.vertShader(name), glslVersion); } } \ No newline at end of file diff --git a/source/funkin/backend/shaders/FunkinShader.hx b/source/funkin/backend/shaders/FunkinShader.hx index 7a943e18..1003dee4 100644 --- a/source/funkin/backend/shaders/FunkinShader.hx +++ b/source/funkin/backend/shaders/FunkinShader.hx @@ -30,7 +30,7 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour { public var onGLUpdate:FlxTypedSignalVoid> = new FlxTypedSignalVoid>(); public function new(?fragmentSource:String, ?vertexSource:String, ?version:String) { - super(fragmentSource, vertexSource, version); + super(fragmentSource, vertexSource, version ?? (fragmentSource != null || vertexSource != null ? Flags.DEFAULT_GLSL_VERSION : null)); } public static function fromFile(fragmentPath:String, ?vertexPath:String, ?version:String):FunkinShader { @@ -44,7 +44,9 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour { else vertexPath = fragmentPath.substr(0, idx); } - _fromFile(FlxRuntimeShader._getPath(fragmentPath, false), FlxRuntimeShader._getPath(vertexPath, true), version); + fragmentPath = FlxRuntimeShader._getPath(fragmentPath, false); + vertexPath = FlxRuntimeShader._getPath(vertexPath, true); + _fromFile(fragmentPath, vertexPath, version ?? (fragmentPath != null || vertexPath != null ? Flags.DEFAULT_GLSL_VERSION : null)); return this; } @@ -156,6 +158,18 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour { private static var FRAGMENT_SHADER = 0; private static var VERTEX_SHADER = 1; + public var fileName(get, set):String; + inline function get_fileName():String return _fragmentFilePath ?? _vertexFilePath ?? "FunkinShader"; + inline function set_fileName(v:String):String return _fragmentFilePath = _vertexFilePath = v; + + public var fragFileName(get, set):String; + inline function get_fragFileName():String return _fragmentFilePath ?? "FunkinShader"; + inline function set_fragFileName(v:String):String return _fragmentFilePath = v; + + public var vertFileName(get, set):String; + inline function get_vertFileName():String return _vertexFilePath ?? "FunkinShader"; + inline function set_vertFileName(v:String):String return _vertexFilePath = v; + public var glslVer(get, set):String; inline function get_glslVer():String return glVersion; inline function set_glslVer(v:String):String return glVersion = v; @@ -168,17 +182,7 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour { inline function get_glRawVertexSource():String return __glVertexSourceRaw; inline function set_glRawVertexSource(v:String):String return __glVertexSourceRaw = v; - public var fileName(get, set):String; - inline function get_fileName():String return _fragmentFilePath ?? _vertexFilePath ?? "FunkinShader"; - inline function set_fileName(v:String):String return _fragmentFilePath = _vertexFilePath = v; - - public var fragFileName(get, set):String; - inline function get_fragFileName():String return _fragmentFilePath ?? "FunkinShader"; - inline function set_fragFileName(v:String):String return _fragmentFilePath = v; - - public var vertFileName(get, set):String; - inline function get_vertFileName():String return _vertexFilePath ?? "FunkinShader"; - inline function set_vertFileName(v:String):String return _vertexFilePath = v; + function thisHasField(v:String):Bool return __thisHasField(v); function registerParameter(name:String, type:String, isUniform:Bool) { __registerParameter(name, Shader.getParameterTypeFromGLSL(type, false), StringTools.startsWith(type, "sampler"), 1, null, isUniform, null);