Use mix for vector types in switch node in the visual shader
This commit is contained in:
parent
e9de988020
commit
bcecb4fe37
|
@ -6923,15 +6923,34 @@ void VisualShaderNodeSwitch::_bind_methods() { // static
|
|||
}
|
||||
|
||||
String VisualShaderNodeSwitch::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 {
|
||||
bool use_mix = false;
|
||||
switch (op_type) {
|
||||
case OP_TYPE_FLOAT: {
|
||||
use_mix = true;
|
||||
} break;
|
||||
case OP_TYPE_VECTOR_2D: {
|
||||
use_mix = true;
|
||||
} break;
|
||||
case OP_TYPE_VECTOR_3D: {
|
||||
use_mix = true;
|
||||
} break;
|
||||
case OP_TYPE_VECTOR_4D: {
|
||||
use_mix = true;
|
||||
} break;
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
|
||||
String code;
|
||||
code += " if(" + p_input_vars[0] + ")\n";
|
||||
code += " {\n";
|
||||
code += " " + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
|
||||
code += " }\n";
|
||||
code += " else\n";
|
||||
code += " {\n";
|
||||
code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
|
||||
code += " }\n";
|
||||
if (use_mix) {
|
||||
code += " " + p_output_vars[0] + " = mix(" + p_input_vars[2] + ", " + p_input_vars[1] + ", float(" + p_input_vars[0] + "));\n";
|
||||
} else {
|
||||
code += " if (" + p_input_vars[0] + ") {\n";
|
||||
code += " " + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
|
||||
code += " } else {\n";
|
||||
code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
|
||||
code += " }\n";
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue