summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2020-01-08 12:15:46 +0300
committerGitHub <noreply@github.com>2020-01-08 12:15:46 +0300
commited22a4c4542a09584e8268276f30ef2687fa1a94 (patch)
tree528c10a65b11816c057002dd36913e8574008460 /scene/resources
parent5edd1a27d2230f771d887114191ce397bddfb5de (diff)
parent7abb09ecf4d1ad6b6b1c0fc446986410abf71236 (diff)
Merge pull request #33817 from Chaosus/vs_fresnel
Make Fresnel node in visual shaders to use default NORMAL/VIEW
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/visual_shader_nodes.cpp27
-rw-r--r--scene/resources/visual_shader_nodes.h1
2 files changed, 25 insertions, 3 deletions
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 0035a138d7..f46fba3b5b 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -3685,12 +3685,33 @@ String VisualShaderNodeFresnel::get_output_port_name(int p_port) const {
}
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 {
- return "\t" + p_output_vars[0] + " = " + p_input_vars[2] + " ? (pow(clamp(dot(" + p_input_vars[0] + ", " + p_input_vars[1] + "), 0.0, 1.0), " + p_input_vars[3] + ")) : (pow(1.0 - clamp(dot(" + p_input_vars[0] + ", " + p_input_vars[1] + "), 0.0, 1.0), " + p_input_vars[3] + "));";
+
+ String normal;
+ String view;
+ if (p_input_vars[0] == String()) {
+ normal = "NORMAL";
+ } else {
+ normal = p_input_vars[0];
+ }
+ if (p_input_vars[1] == String()) {
+ view = "VIEW";
+ } else {
+ 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] + "));";
+}
+
+String VisualShaderNodeFresnel::get_input_port_default_hint(int p_port) const {
+ if (p_port == 0) {
+ return "default";
+ } else if (p_port == 1) {
+ return "default";
+ }
+ return "";
}
VisualShaderNodeFresnel::VisualShaderNodeFresnel() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0));
set_input_port_default_value(2, false);
set_input_port_default_value(3, 1.0);
}
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index 99b4c01d53..0f428088e0 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -1579,6 +1579,7 @@ public:
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
+ virtual String get_input_port_default_hint(int p_port) const;
virtual String 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 = false) const;
VisualShaderNodeFresnel();