You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Use mix for vector types in switch node in the visual shader
This commit is contained in:
@@ -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 {
|
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;
|
String code;
|
||||||
code += " if(" + p_input_vars[0] + ")\n";
|
if (use_mix) {
|
||||||
code += " {\n";
|
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 += " " + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
|
||||||
code += " }\n";
|
code += " } else {\n";
|
||||||
code += " else\n";
|
|
||||||
code += " {\n";
|
|
||||||
code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
|
code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
|
||||||
code += " }\n";
|
code += " }\n";
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user