Fix y billboard shear when rotating camera
Fixes shear effect with `BILLBOARD_FIXED_Y` when the camera is rotated around the z-axis by rotating the mesh correctly into view space. Also removes shearing effects that occur when rotating the mesh by excluding the model rotation and scale from the billboard matrix.
This commit is contained in:
parent
00268e37a0
commit
d3850a0954
1 changed files with 2 additions and 4 deletions
|
@ -790,12 +790,10 @@ void BaseMaterial3D::_update_shader() {
|
|||
}
|
||||
} break;
|
||||
case BILLBOARD_FIXED_Y: {
|
||||
code += " MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],WORLD_MATRIX[1],vec4(normalize(cross(CAMERA_MATRIX[0].xyz,WORLD_MATRIX[1].xyz)), 0.0),WORLD_MATRIX[3]);\n";
|
||||
code += " MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(vec4(normalize(cross(vec3(0.0, 1.0, 0.0), CAMERA_MATRIX[2].xyz)),0.0),vec4(0.0, 1.0, 0.0, 0.0),vec4(normalize(cross(CAMERA_MATRIX[0].xyz, vec3(0.0, 1.0, 0.0))),0.0),WORLD_MATRIX[3]);\n";
|
||||
|
||||
if (flags[FLAG_BILLBOARD_KEEP_SCALE]) {
|
||||
code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, 1.0, 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
|
||||
} else {
|
||||
code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(1.0, 0.0, 0.0, 0.0),vec4(0.0, 1.0/length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0 ,1.0));\n";
|
||||
code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n";
|
||||
}
|
||||
} break;
|
||||
case BILLBOARD_PARTICLES: {
|
||||
|
|
Loading…
Reference in a new issue