summaryrefslogtreecommitdiff
path: root/scene/resources/visual_shader_sdf_nodes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/visual_shader_sdf_nodes.cpp')
-rw-r--r--scene/resources/visual_shader_sdf_nodes.cpp58
1 files changed, 29 insertions, 29 deletions
diff --git a/scene/resources/visual_shader_sdf_nodes.cpp b/scene/resources/visual_shader_sdf_nodes.cpp
index d25e32b070..14c655b129 100644
--- a/scene/resources/visual_shader_sdf_nodes.cpp
+++ b/scene/resources/visual_shader_sdf_nodes.cpp
@@ -61,7 +61,7 @@ String VisualShaderNodeSDFToScreenUV::get_output_port_name(int p_port) const {
}
String VisualShaderNodeSDFToScreenUV::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return "\t" + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
}
VisualShaderNodeSDFToScreenUV::VisualShaderNodeSDFToScreenUV() {
@@ -105,7 +105,7 @@ String VisualShaderNodeScreenUVToSDF::get_input_port_default_hint(int p_port) co
}
String VisualShaderNodeScreenUVToSDF::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return "\t" + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0] == String() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0] == String() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
}
VisualShaderNodeScreenUVToSDF::VisualShaderNodeScreenUVToSDF() {
@@ -142,7 +142,7 @@ String VisualShaderNodeTextureSDF::get_output_port_name(int p_port) const {
}
String VisualShaderNodeTextureSDF::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return "\t" + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n";
+ return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n";
}
VisualShaderNodeTextureSDF::VisualShaderNodeTextureSDF() {
@@ -179,7 +179,7 @@ String VisualShaderNodeTextureSDFNormal::get_output_port_name(int p_port) const
}
String VisualShaderNodeTextureSDFNormal::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return "\t" + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
}
VisualShaderNodeTextureSDFNormal::VisualShaderNodeTextureSDFNormal() {
@@ -240,40 +240,40 @@ String VisualShaderNodeSDFRaymarch::get_output_port_name(int p_port) const {
String VisualShaderNodeSDFRaymarch::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
String code;
- code += "\t{\n";
+ code += " {\n";
if (p_input_vars[0] == String()) {
- code += "\t\tvec2 __from_pos = vec2(0.0f);\n";
+ code += " vec2 __from_pos = vec2(0.0f);\n";
} else {
- code += "\t\tvec2 __from_pos = " + p_input_vars[0] + ".xy;\n";
+ code += " vec2 __from_pos = " + p_input_vars[0] + ".xy;\n";
}
if (p_input_vars[1] == String()) {
- code += "\t\tvec2 __to_pos = vec2(0.0f);\n";
+ code += " vec2 __to_pos = vec2(0.0f);\n";
} else {
- code += "\t\tvec2 __to_pos = " + p_input_vars[1] + ".xy;\n";
+ code += " vec2 __to_pos = " + p_input_vars[1] + ".xy;\n";
}
- code += "\n\t\tvec2 __at = __from_pos;\n";
- code += "\t\tfloat __max_dist = distance(__from_pos, __to_pos);\n";
- code += "\t\tvec2 __dir = normalize(__to_pos - __from_pos);\n\n";
-
- code += "\t\tfloat __accum = 0.0f;\n";
- code += "\t\twhile(__accum < __max_dist) {\n";
- code += "\t\t\tfloat __d = texture_sdf(__at);\n";
- code += "\t\t\t__accum += __d;\n";
- code += "\t\t\tif (__d < 0.01f) {\n";
- code += "\t\t\t\tbreak;\n";
- code += "\t\t\t}\n";
- code += "\t\t\t__at += __d * __dir;\n";
- code += "\t\t}\n";
-
- code += "\t\tfloat __dist = min(__max_dist, __accum);\n";
- code += "\t\t" + p_output_vars[0] + " = __dist;\n";
- code += "\t\t" + p_output_vars[1] + " = __accum < __max_dist;\n";
- code += "\t\t" + p_output_vars[2] + " = vec3(__from_pos + __dir * __dist, 0.0f);\n";
-
- code += "\t}\n";
+ code += "\n vec2 __at = __from_pos;\n";
+ code += " float __max_dist = distance(__from_pos, __to_pos);\n";
+ code += " vec2 __dir = normalize(__to_pos - __from_pos);\n\n";
+
+ code += " float __accum = 0.0f;\n";
+ code += " while(__accum < __max_dist) {\n";
+ code += " float __d = texture_sdf(__at);\n";
+ code += " __accum += __d;\n";
+ code += " if (__d < 0.01f) {\n";
+ code += " break;\n";
+ code += " }\n";
+ code += " __at += __d * __dir;\n";
+ code += " }\n";
+
+ code += " float __dist = min(__max_dist, __accum);\n";
+ code += " " + p_output_vars[0] + " = __dist;\n";
+ code += " " + p_output_vars[1] + " = __accum < __max_dist;\n";
+ code += " " + p_output_vars[2] + " = vec3(__from_pos + __dir * __dist, 0.0f);\n";
+
+ code += " }\n";
return code;
}