Compare commits

...

4 commits
v10.1 ... main

4 changed files with 26 additions and 8 deletions

View file

@ -62,15 +62,17 @@ Example:
//!load ... //!load ...
//!steps 5 //!steps 5
uniform int STEP; // this is mandatory! uniform int STEP;
uniform int STEPS;
void fragment() { void fragment() {
if (STEP == 0) { if (STEP == 0) {
... ...
} else if (STEP == 1) { } else if (STEP == 1) {
... ...
} else if (STEP == STEPS-1) {
...
} }
// ... and so on
} }
``` ```

View file

@ -11,7 +11,7 @@ config_version=5
[application] [application]
config/name="Fragmented" config/name="Fragmented"
config/version="v10.1" config/version="v10.2"
run/main_scene="res://src/scenes/main.tscn" run/main_scene="res://src/scenes/main.tscn"
config/features=PackedStringArray("4.4", "Mobile") config/features=PackedStringArray("4.4", "Mobile")
config/icon="res://src/assets/icon.png" config/icon="res://src/assets/icon.png"

View file

@ -13,3 +13,15 @@ vec4 alpha_blend(vec4 b, vec4 a) {
vec3 col = ((a.rgb*a.a) + ((b.rgb*b.a) * (1.0 - a.a)) / alpha); vec3 col = ((a.rgb*a.a) + ((b.rgb*b.a) * (1.0 - a.a)) / alpha);
return vec4(col.r, col.g, col.b, alpha); return vec4(col.r, col.g, col.b, alpha);
} }
/*
Rotate UV
*/
vec2 rotateUV(vec2 uv, float rotation, vec2 center) {
float cosRot = cos(rotation);
float sinRot = sin(rotation);
return vec2(
cosRot * (uv.x - center.x) + sinRot * (uv.y - center.y) + center.x,
cosRot * (uv.y - center.y) - sinRot * (uv.x - center.x) + center.y);
}

View file

@ -37,9 +37,9 @@ func validate_shader_compilation(shader: Shader) -> bool:
# test if uniform list is empty -> if it is empty, the shader compilation failed # test if uniform list is empty -> if it is empty, the shader compilation failed
return len(shader.get_shader_uniform_list()) > 0 return len(shader.get_shader_uniform_list()) > 0
func shader_has_step_uniform(shader: Shader) -> bool: func shader_has_uniform(shader: Shader, name: String, type: int) -> bool:
for u in shader.get_shader_uniform_list(): for u in shader.get_shader_uniform_list():
if u["name"] == "STEP" && u["type"] == 2: if u["name"] == name && u["type"] == type:
return true return true
return false return false
@ -55,7 +55,8 @@ func update(overwrite_image_path: String = "") -> Array: # returns error message
return ["No shader opened!"] return ["No shader opened!"]
# get number of steps & check if code has STEP uniform # get number of steps & check if code has STEP uniform
var steps: int = ShaderDirectiveParser.parse_steps_directive(shader.code) var steps: int = ShaderDirectiveParser.parse_steps_directive(shader.code)
var has_step_uniform: bool = shader_has_step_uniform(shader) var has_step_uniform: bool = shader_has_uniform(shader, "STEP", 2)
var has_steps_uniform: bool = shader_has_uniform(shader, "STEPS", 2)
# validate shader # validate shader
if not validate_shader_compilation(shader): if not validate_shader_compilation(shader):
return ["Shader compilation failed!"] return ["Shader compilation failed!"]
@ -105,6 +106,9 @@ func update(overwrite_image_path: String = "") -> Array: # returns error message
image_sprite.material = mat image_sprite.material = mat
# iterate n times # iterate n times
set_vsync(false) # speed up processing set_vsync(false) # speed up processing
if has_steps_uniform:
# set STEPS param
mat.set_shader_parameter("STEPS", steps)
for i in range(steps): for i in range(steps):
if has_step_uniform: if has_step_uniform:
# set STEP param # set STEP param