Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPUParticles3D: Zero modelview matrix of billboard materials when model matrix is zeroes #75090

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scene/resources/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,10 @@ void BaseMaterial3D::_update_shader() {

if (flags[FLAG_BILLBOARD_KEEP_SCALE]) {
code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
} else {
// Do not render if model affine matrix has an exactly zero first column: a completely 0 model matrix is used by particle system to indicate an inactive particle
code += " float col_sum = abs(MODEL_MATRIX[0][0]) + abs(MODEL_MATRIX[0][1]) + abs(MODEL_MATRIX[0][2]);\n";
code += " if (col_sum == 0.0) { MODELVIEW_MATRIX = mat4(0.0); }\n";
}
code += " MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);\n";
} break;
Expand All @@ -958,6 +962,10 @@ void BaseMaterial3D::_update_shader() {

if (flags[FLAG_BILLBOARD_KEEP_SCALE]) {
code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
} else {
// Do not render if model affine matrix has an exactly zero first column: a completely 0 model matrix is used by particle system to indicate an inactive particle
code += " float col_sum = abs(MODEL_MATRIX[0][0]) + abs(MODEL_MATRIX[0][1]) + abs(MODEL_MATRIX[0][2]);\n";
code += " if (col_sum == 0.0) { MODELVIEW_MATRIX = mat4(0.0); }\n";
}
code += " MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);\n";
} break;
Expand All @@ -970,6 +978,10 @@ void BaseMaterial3D::_update_shader() {
code += " MODELVIEW_MATRIX = VIEW_MATRIX * mat_world;\n";
if (flags[FLAG_BILLBOARD_KEEP_SCALE]) {
code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
} else {
// Do not render if model affine matrix has an exactly zero first column: a completely 0 model matrix is used by particle system to indicate an inactive particle
code += " float col_sum = abs(MODEL_MATRIX[0][0]) + abs(MODEL_MATRIX[0][1]) + abs(MODEL_MATRIX[0][2]);\n";
code += " if (col_sum == 0.0) { MODELVIEW_MATRIX = mat4(0.0); }\n";
}
//set modelview normal
code += " MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);\n";
Expand Down