Skip to content

Index Map #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Classes/ShaderLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,31 @@ static func create_ui_for_shader_uniforms(
) -> void:
var code := shader.code.split("\n")
var uniforms: PackedStringArray = []
var description: String = ""
var descriprion_began := false
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"):
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:
# Example uniform:
# uniform float parameter_name : hint_range(0, 255) = 100.0;
Expand Down
18 changes: 18 additions & 0 deletions src/Shaders/Effects/IndexMap.gdshader
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/UI/Timeline/LayerEffects/LayerEffectsSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var effects: Array[LayerEffect] = [
LayerEffect.new("Pixelize", preload("res://src/Shaders/Effects/Pixelize.gdshader")),
LayerEffect.new("Posterize", preload("res://src/Shaders/Effects/Posterize.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
Expand Down