fix billboards

main
Dominik Madarász 2024-08-24 18:10:21 +02:00
parent 2eca87099a
commit c6b771056a
2 changed files with 13 additions and 2 deletions

View File

@ -116,7 +116,12 @@ vec3 get_object_pos() {
return objPos; return objPos;
} }
void setup_billboard(mat4 modelView, mat4 l_model) { struct billboard_t {
mat4 modelView;
mat4 l_model;
};
billboard_t setup_billboard(mat4 modelView, mat4 l_model) {
if(u_billboard > 0) { if(u_billboard > 0) {
vec3 cameraPosition = -transpose(mat3(view)) * view[3].xyz; vec3 cameraPosition = -transpose(mat3(view)) * view[3].xyz;
vec3 lookDir = normalize(cameraPosition - v_position_ws); vec3 lookDir = normalize(cameraPosition - v_position_ws);
@ -145,4 +150,8 @@ void setup_billboard(mat4 modelView, mat4 l_model) {
if((u_billboard & 0x1) != 0) l_model[2] = billboardRotation[2]; if((u_billboard & 0x1) != 0) l_model[2] = billboardRotation[2];
modelView = view * l_model; modelView = view * l_model;
} }
billboard_t bb;
bb.modelView = modelView;
bb.l_model = l_model;
return bb;
} }

View File

@ -16,7 +16,9 @@ void main() {
mat4 l_model = att_instanced_matrix; mat4 l_model = att_instanced_matrix;
v_position_ws = (l_model * vec4( objPos, 1.0 )).xyz; v_position_ws = (l_model * vec4( objPos, 1.0 )).xyz;
setup_billboard(modelView, l_model); billboard_t bb = setup_billboard(modelView, l_model);
modelView = bb.modelView;
l_model = bb.l_model;
v_position_ws = (l_model * vec4( objPos, 1.0 )).xyz; v_position_ws = (l_model * vec4( objPos, 1.0 )).xyz;
v_tangent = normalize(mat3(att_instanced_matrix) * att_tangent.xyz); v_tangent = normalize(mat3(att_instanced_matrix) * att_tangent.xyz);