mirror of
https://github.com/godotengine/godot
synced 2024-09-05 07:18:49 +00:00
Merge pull request #72436 from Chaosus/vs_switch_improvement
This commit is contained in:
commit
0810ecaafd
|
@ -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 a new issue