1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00
* Index Map

* Formatting

* improve description a bit.
This commit is contained in:
Variable 2024-08-31 04:53:27 +05:00 committed by GitHub
parent 4fa8981590
commit a7f1486ec3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 0 deletions

View file

@ -15,10 +15,31 @@ static func create_ui_for_shader_uniforms(
) -> void: ) -> void:
var code := shader.code.split("\n") var code := shader.code.split("\n")
var uniforms: PackedStringArray = [] var uniforms: PackedStringArray = []
var description: String = ""
var descriprion_began := false
for line in code: for line in code:
## Management of "end" tags
if line.begins_with("// (end DESCRIPTION)"):
descriprion_began = false
if descriprion_began:
description += "\n" + line.strip_edges()
## Detection of uniforms
if line.begins_with("uniform"): if line.begins_with("uniform"):
uniforms.append(line) uniforms.append(line)
## Management of "begin" tags
elif line.begins_with("// (begin DESCRIPTION)"):
descriprion_began = true
## Validation of begin/end tags
if descriprion_began == true: ## Description started but never ended. treat it as an error
print("Shader description started but never finished. Assuming empty description")
description = ""
if not description.is_empty():
parent_node.tooltip_text = str(
"Description:\n", description.replace("//", "").strip_edges()
)
for uniform in uniforms: for uniform in uniforms:
# Example uniform: # Example uniform:
# uniform float parameter_name : hint_range(0, 255) = 100.0; # uniform float parameter_name : hint_range(0, 255) = 100.0;

View file

@ -0,0 +1,18 @@
// Authored by Variable (6 May 2022)
shader_type canvas_item;
render_mode unshaded;
uniform sampler2D map_texture : filter_nearest; // The map texture
// (begin DESCRIPTION)
// The Red and Green values (0-255) of tool color will be treated as an x and y position
// respectively instead of color components.
// When you draw, color will be taken from the x-y position in the "Map Texture".
// (end DESCRIPTION)
void fragment(){
vec4 col = texture(TEXTURE, UV);
vec2 map_size = vec2(textureSize(map_texture, 0));
vec2 lookup_uv = vec2(round(col.x * 255.0)/(map_size.x), round(col.y * 255.0)/(map_size.y));
vec4 index_color = texture(map_texture, lookup_uv);
COLOR = index_color;
}

View file

@ -23,6 +23,7 @@ var effects: Array[LayerEffect] = [
LayerEffect.new("Pixelize", preload("res://src/Shaders/Effects/Pixelize.gdshader")), LayerEffect.new("Pixelize", preload("res://src/Shaders/Effects/Pixelize.gdshader")),
LayerEffect.new("Posterize", preload("res://src/Shaders/Effects/Posterize.gdshader")), LayerEffect.new("Posterize", preload("res://src/Shaders/Effects/Posterize.gdshader")),
LayerEffect.new("Gradient Map", preload("res://src/Shaders/Effects/GradientMap.gdshader")), LayerEffect.new("Gradient Map", preload("res://src/Shaders/Effects/GradientMap.gdshader")),
LayerEffect.new("Index Map", preload("res://src/Shaders/Effects/IndexMap.gdshader")),
] ]
@onready var enabled_button: CheckButton = $VBoxContainer/HBoxContainer/EnabledButton @onready var enabled_button: CheckButton = $VBoxContainer/HBoxContainer/EnabledButton