summaryrefslogtreecommitdiffstats
path: root/scene/resources/visual_shader_nodes.cpp
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2020-07-27 09:18:37 +0300
committerYuri Roubinsky <chaosus89@gmail.com>2020-07-27 11:35:53 +0300
commit167f033782e2a1a731ce2aa4f4ce856615db6ed4 (patch)
tree4df8d723146147b3a83c0d89ce9b404023b437e0 /scene/resources/visual_shader_nodes.cpp
parent0a7942f4bb61cba8f02f2cbe0ec83b95eefa6726 (diff)
downloadredot-engine-167f033782e2a1a731ce2aa4f4ce856615db6ed4.tar.gz
Optimize code generation for fresnel node in visual shaders
Diffstat (limited to 'scene/resources/visual_shader_nodes.cpp')
-rw-r--r--scene/resources/visual_shader_nodes.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 4cf382a933..0caa3cecd8 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -4457,6 +4457,13 @@ String VisualShaderNodeFresnel::get_output_port_name(int p_port) const {
return "result";
}
+bool VisualShaderNodeFresnel::is_generate_input_var(int p_port) const {
+ if (p_port == 2) {
+ return false;
+ }
+ return true;
+}
+
String VisualShaderNodeFresnel::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 normal;
String view;
@@ -4471,7 +4478,15 @@ String VisualShaderNodeFresnel::generate_code(Shader::Mode p_mode, VisualShader:
view = p_input_vars[1];
}
- return "\t" + p_output_vars[0] + " = " + p_input_vars[2] + " ? (pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ")) : (pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + "));\n";
+ if (is_input_port_connected(2)) {
+ return "\t" + p_output_vars[0] + " = " + p_input_vars[2] + " ? (pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ")) : (pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + "));\n";
+ } else {
+ if (get_input_port_default_value(2)) {
+ return "\t" + p_output_vars[0] + " = pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
+ } else {
+ return "\t" + p_output_vars[0] + " = pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
+ }
+ }
}
String VisualShaderNodeFresnel::get_input_port_default_hint(int p_port) const {