Deprecate CustomShader
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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>):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);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class FunkinShader extends FlxRuntimeShader implements IHScriptCustomBehaviour {
|
||||
public var onGLUpdate:FlxTypedSignal<Void->Void> = new FlxTypedSignal<Void->Void>();
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user