shader uniform editor window
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
|
||||
(method &override :Void create []
|
||||
(super.create)
|
||||
(set shader (new kiss_flixel.shaders.CheckerBoard))
|
||||
(set shader (new kiss_flixel.shaders.CheckerBoard "checkers.json"))
|
||||
(set shader.data.color1FlxColor FlxColor.WHITE)
|
||||
(set shader.data.color2FlxColor FlxColor.BLACK)
|
||||
(set shader.checkSizeFloat 64.0)
|
||||
@@ -21,5 +21,5 @@
|
||||
|
||||
(method &override :Void update [:Float elapsed]
|
||||
(super.update elapsed)
|
||||
(+= FlxG.camera.scroll.x 0.05)
|
||||
(+= FlxG.camera.scroll.y 0.05))
|
||||
**(+= FlxG.camera.scroll.x 0.05)
|
||||
**(+= FlxG.camera.scroll.y 0.05))
|
@@ -15,7 +15,7 @@
|
||||
|
||||
(method &override :Void create []
|
||||
(super.create)
|
||||
(set shader (new kiss_flixel.shaders.GodRays))
|
||||
(set shader (new kiss_flixel.shaders.GodRays "godRays.json"))
|
||||
(set sprite (new FlxSprite 0 0 "assets/images/flymanEdited.png"))
|
||||
(add sprite)
|
||||
|
||||
|
@@ -17,7 +17,7 @@
|
||||
(bg.screenCenter)
|
||||
(set bg.alpha 0.5)
|
||||
(add bg))
|
||||
(set shader (new kiss_flixel.shaders.Invert))
|
||||
(set shader (new kiss_flixel.shaders.Invert "invert.json"))
|
||||
(kiss_flixel.CameraTools.addShaderFilter FlxG.camera (array FlxShader shader)))
|
||||
|
||||
(method &override :Void update [:Float elapsed]
|
||||
|
@@ -32,7 +32,7 @@
|
||||
(set sprite.cameras [fgCamera])
|
||||
(add sprite)
|
||||
|
||||
(set shader (new kiss_flixel.shaders.Shadow))
|
||||
(set shader (new kiss_flixel.shaders.Shadow "shadow.json"))
|
||||
(kiss_flixel.CameraTools.addShaderFilter fgCamera (array FlxShader shader)))
|
||||
|
||||
(method &override :Void update [:Float elapsed]
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma header
|
||||
|
||||
uniform vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
uniform vec4 color2 = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
uniform vec4 color1: hint_color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
uniform vec4 color2: hint_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
uniform float checkSize = 64.0;
|
||||
|
||||
void main()
|
||||
|
@@ -1,6 +1,10 @@
|
||||
#pragma header
|
||||
|
||||
uniform bool invert = true;
|
||||
uniform int test_int = 0;
|
||||
uniform int test_range_int: hint_range(0, 20) = 0;
|
||||
uniform int test_step_int: hint_range(0, 20, 2) = 0;
|
||||
uniform float test_step_float: hint_range(0, 1, 0.1) = 0;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@@ -9,6 +9,8 @@ import kiss_tools.JsonBool;
|
||||
import kiss_flixel.JsonFlxColor;
|
||||
import kiss_flixel.JsonFlxPoint;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.math.FlxPoint;
|
||||
import flixel.util.FlxColor;
|
||||
|
||||
class KFlxShader extends flixel.system.FlxAssets.FlxShader {
|
||||
public var uniforms(default, null):Map<String,Uniform>;
|
||||
@@ -17,6 +19,9 @@ class KFlxShader extends flixel.system.FlxAssets.FlxShader {
|
||||
|
||||
var camera:FlxCamera = null;
|
||||
|
||||
static var activeShaders:Map<String,KFlxShader> = [];
|
||||
static var chosenToEdit:String = null;
|
||||
|
||||
public function new(?camera:FlxCamera, ?jsonMapFile:String) {
|
||||
super();
|
||||
|
||||
@@ -30,6 +35,8 @@ class KFlxShader extends flixel.system.FlxAssets.FlxShader {
|
||||
data.cameraZoom.value = [1.0];
|
||||
|
||||
if (jsonMapFile != null) {
|
||||
activeShaders[jsonMapFile] = this;
|
||||
|
||||
json = new JsonMap(jsonMapFile, new JsonString(""));
|
||||
|
||||
for (name => uniform in uniforms) {
|
||||
@@ -61,6 +68,165 @@ class KFlxShader extends flixel.system.FlxAssets.FlxShader {
|
||||
data.iTime.value = [data.iTime.value[0] + flixel.FlxG.elapsed];
|
||||
data.cameraPos.value = [camera.viewLeft, camera.viewTop];
|
||||
data.cameraZoom.value = [camera.zoom];
|
||||
|
||||
#if debug
|
||||
var p = flixel.FlxG.keys.pressed;
|
||||
var jp = flixel.FlxG.keys.justPressed;
|
||||
if (chosenToEdit != null) {
|
||||
if (chosenToEdit == json.jsonPath) {
|
||||
editShaderUniforms();
|
||||
}
|
||||
} else if (p.CONTROL && p.ALT && p.S && (jp.CONTROL || jp.ALT || jp.S)) {
|
||||
if (Lambda.count(activeShaders) == 1) {
|
||||
editShaderUniforms();
|
||||
} else {
|
||||
kiss_flixel.SimpleWindow.promptForChoiceV2("Edit which shader's uniforms?", [for (k in activeShaders.keys()) k],
|
||||
jsonFile -> { chosenToEdit = jsonFile; });
|
||||
}
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
public override function __disable() {
|
||||
super.__disable();
|
||||
|
||||
if (json != null)
|
||||
activeShaders.remove(json.jsonPath);
|
||||
}
|
||||
|
||||
function editShaderUniforms() {
|
||||
var window = new SimpleWindow('Editing shader uniforms: ${json.jsonPath}', null, null, 0.9, 0.9, true);
|
||||
|
||||
function recursiveCall() {
|
||||
window.show();
|
||||
window.hide();
|
||||
editShaderUniforms();
|
||||
}
|
||||
|
||||
for (key => uniform in uniforms) {
|
||||
switch (uniform) {
|
||||
case Boolean:
|
||||
var v:Bool = Reflect.getProperty(this, key);
|
||||
window.makeTextV2('${key}: ${v}', {
|
||||
onClick: s -> {
|
||||
Reflect.setProperty(this, key, !v);
|
||||
recursiveCall();
|
||||
}
|
||||
});
|
||||
case AnyInt:
|
||||
var v:Int = Reflect.getProperty(this, key);
|
||||
window.makeTextV2('${key}: ${v}', {
|
||||
onClick: s -> {
|
||||
SimpleWindow.promptForString('Change from $v to any int:', shouldBeInt -> {
|
||||
Reflect.setProperty(this, key, Std.parseInt(shouldBeInt));
|
||||
recursiveCall();
|
||||
});
|
||||
}
|
||||
});
|
||||
case IntRange(min, max):
|
||||
var v:Int = Reflect.getProperty(this, key);
|
||||
window.makeTextV2('${key}: ${v}', {
|
||||
onClick: s -> {
|
||||
SimpleWindow.promptForChoice('Change from $v to:', [for (i in min... max+1) i], int -> {
|
||||
Reflect.setProperty(this, key, int);
|
||||
recursiveCall();
|
||||
});
|
||||
}
|
||||
});
|
||||
case IntRangeStep(min, max, step):
|
||||
var v:Int = Reflect.getProperty(this, key);
|
||||
window.makeTextV2('${key}: ${v}', {
|
||||
onClick: s -> {
|
||||
SimpleWindow.promptForChoice('Change from $v to:', [for (i in kiss.Prelude.range(min, max+1, step)) i], int -> {
|
||||
Reflect.setProperty(this, key, int);
|
||||
recursiveCall();
|
||||
});
|
||||
}
|
||||
});
|
||||
case AnyFloat:
|
||||
var v:Float = Reflect.getProperty(this, key);
|
||||
window.makeTextV2('${key}: ${v}', {
|
||||
onClick: s -> {
|
||||
SimpleWindow.promptForString('Change from $v to any float:', shouldBeFloat -> {
|
||||
Reflect.setProperty(this, key, Std.parseFloat(shouldBeFloat));
|
||||
recursiveCall();
|
||||
});
|
||||
}
|
||||
});
|
||||
case FloatRange(min, max):
|
||||
var v:Float = Reflect.getProperty(this, key);
|
||||
window.makeTextV2('${key}: ${v}', {
|
||||
onClick: s -> {
|
||||
SimpleWindow.promptForString('Change from $v to any float between $min and $max:', shouldBeFloat -> {
|
||||
var f = Std.parseFloat(shouldBeFloat);
|
||||
if (f >= min && f <= max)
|
||||
Reflect.setProperty(this, key, f);
|
||||
recursiveCall();
|
||||
});
|
||||
}
|
||||
});
|
||||
case FloatRangeStep(min, max, step):
|
||||
var v:Float = Reflect.getProperty(this, key);
|
||||
window.makeTextV2('${key}: ${v}', {
|
||||
onClick: s -> {
|
||||
var choices = [];
|
||||
var next = min;
|
||||
while (next <= max) {
|
||||
choices.push(next);
|
||||
next += step;
|
||||
}
|
||||
SimpleWindow.promptForChoice('Change from $v to:', choices, float -> {
|
||||
Reflect.setProperty(this, key, float);
|
||||
recursiveCall();
|
||||
});
|
||||
}
|
||||
});
|
||||
case ColorSolid:
|
||||
var c:FlxColor = Reflect.getProperty(this, key);
|
||||
window.makeText(key);
|
||||
window.makeTextV2(' ', {
|
||||
bgColor: c,
|
||||
onClick: _ -> {
|
||||
SimpleWindow.promptForColorV2("Choose a solid color:", color -> {
|
||||
Reflect.setProperty(this, key, color);
|
||||
recursiveCall();
|
||||
}, {
|
||||
currentColor: c
|
||||
});
|
||||
}
|
||||
});
|
||||
case ColorWithAlpha:
|
||||
var c:FlxColor = Reflect.getProperty(this, key);
|
||||
window.makeText(key);
|
||||
window.makeTextV2(' ', {
|
||||
bgColor: c,
|
||||
onClick: _ -> {
|
||||
SimpleWindow.promptForColorV2("Choose a color (transparency allowed):", color -> {
|
||||
Reflect.setProperty(this, key, color);
|
||||
recursiveCall();
|
||||
}, {
|
||||
allowAlpha: true,
|
||||
currentColor: c
|
||||
});
|
||||
}
|
||||
});
|
||||
case Vector2:
|
||||
var p:FlxPoint = Reflect.getProperty(this, key);
|
||||
window.makeTextV2('${key}: ${p}', {
|
||||
onClick: _ -> {
|
||||
SimpleWindow.promptForString('Change from $p to _,_:', str -> {
|
||||
var parts = str.split(",");
|
||||
Reflect.setProperty(this, key, FlxPoint.get(Std.parseFloat(parts[0]), Std.parseFloat(parts[1])));
|
||||
recursiveCall();
|
||||
});
|
||||
}
|
||||
});
|
||||
// TODO
|
||||
case Vector3:
|
||||
case Vector4:
|
||||
}
|
||||
}
|
||||
|
||||
window.show();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user