fix billboarding code
parent
13845097af
commit
d5a0dac5d4
|
@ -2905,6 +2905,13 @@ unsigned billboard;
|
|||
float *instanced_matrices;
|
||||
unsigned num_instances;
|
||||
} model_t;
|
||||
enum BILLBOARD_MODE {
|
||||
BILLBOARD_X =1,
|
||||
BILLBOARD_Y =2,
|
||||
BILLBOARD_Z =4,
|
||||
BILLBOARD_CYLINDRICAL = BILLBOARD_X|BILLBOARD_Z,
|
||||
BILLBOARD_SPHERICAL = BILLBOARD_X|BILLBOARD_Y|BILLBOARD_Z
|
||||
};
|
||||
model_t model(const char *filename, int flags);
|
||||
model_t model_from_mem(const void *mem, int sz, int flags);
|
||||
float model_animate(model_t, float curframe);
|
||||
|
|
|
@ -113,34 +113,41 @@ void main() {
|
|||
|
||||
// vec3 tangent = att_tangent.xyz;
|
||||
// vec3 bitangent = cross(att_normal, att_tangent.xyz) * att_tangent.w;
|
||||
mat4 modelView = view * att_instanced_matrix;
|
||||
if(u_billboard > 0) {
|
||||
float sx = length(vec3(modelView[0][0], modelView[1][0], modelView[2][0]));
|
||||
float sy = length(vec3(modelView[0][1], modelView[1][1], modelView[2][1]));
|
||||
float sz = length(vec3(modelView[0][2], modelView[1][2], modelView[2][2]));
|
||||
|
||||
if((u_billboard & 4) != 0) {
|
||||
modelView[0][0] = sx;
|
||||
modelView[0][1] = 0.0;
|
||||
modelView[0][2] = 0.0;
|
||||
}
|
||||
if((u_billboard & 2) != 0) {
|
||||
modelView[1][0] = 0.0;
|
||||
modelView[1][1] = sy;
|
||||
modelView[1][2] = 0.0;
|
||||
}
|
||||
if((u_billboard & 1) != 0) {
|
||||
modelView[2][0] = 0.0;
|
||||
modelView[2][1] = 0.0;
|
||||
modelView[2][2] = sz;
|
||||
}
|
||||
}
|
||||
v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.))); // normal to world/model space
|
||||
v_normal = normalize(v_normal);
|
||||
v_position_ws = (att_instanced_matrix * vec4( objPos, 1.0 )).xyz;
|
||||
v_position = att_position;
|
||||
v_texcoord = att_texcoord;
|
||||
v_color = att_color;
|
||||
mat4 modelView = view * att_instanced_matrix;
|
||||
mat4 l_model = att_instanced_matrix;
|
||||
v_position_ws = (l_model * vec4( objPos, 1.0 )).xyz;
|
||||
|
||||
if(u_billboard > 0) {
|
||||
vec3 cameraPosition = -transpose(mat3(view)) * view[3].xyz;
|
||||
vec3 lookDir = normalize(cameraPosition - v_position_ws);
|
||||
|
||||
vec3 up = vec3(view[0][1], view[1][1], view[2][1]);
|
||||
vec3 right = normalize(cross(up, lookDir));
|
||||
up = cross(lookDir, right);
|
||||
|
||||
vec3 scale;
|
||||
scale.x = length(vec3(att_instanced_matrix[0]));
|
||||
scale.y = length(vec3(att_instanced_matrix[1]));
|
||||
scale.z = length(vec3(att_instanced_matrix[2]));
|
||||
|
||||
mat4 billboardRotation = mat4(
|
||||
vec4(right * scale.x, 0.0),
|
||||
vec4(-up * scale.y, 0.0),
|
||||
vec4(-lookDir * scale.z, 0.0),
|
||||
vec4(0.0, 0.0, 0.0, 1.0)
|
||||
);
|
||||
|
||||
if((u_billboard & 0x4) != 0) l_model[0] = billboardRotation[0];
|
||||
if((u_billboard & 0x2) != 0) l_model[1] = billboardRotation[1];
|
||||
if((u_billboard & 0x1) != 0) l_model[2] = billboardRotation[2];
|
||||
modelView = view * l_model;
|
||||
}
|
||||
v_position_ws = (l_model * vec4( objPos, 1.0 )).xyz;
|
||||
gl_Position = P * modelView * vec4( objPos, 1.0 );
|
||||
do_shadow();
|
||||
}
|
|
@ -17640,6 +17640,15 @@ typedef struct model_t {
|
|||
unsigned num_instances;
|
||||
} model_t;
|
||||
|
||||
enum BILLBOARD_MODE {
|
||||
BILLBOARD_X = 0x1,
|
||||
BILLBOARD_Y = 0x2,
|
||||
BILLBOARD_Z = 0x4,
|
||||
|
||||
BILLBOARD_CYLINDRICAL = BILLBOARD_X|BILLBOARD_Z,
|
||||
BILLBOARD_SPHERICAL = BILLBOARD_X|BILLBOARD_Y|BILLBOARD_Z
|
||||
};
|
||||
|
||||
API model_t model(const char *filename, int flags);
|
||||
API model_t model_from_mem(const void *mem, int sz, int flags);
|
||||
API float model_animate(model_t, float curframe);
|
||||
|
|
|
@ -611,6 +611,15 @@ typedef struct model_t {
|
|||
unsigned num_instances;
|
||||
} model_t;
|
||||
|
||||
enum BILLBOARD_MODE {
|
||||
BILLBOARD_X = 0x1,
|
||||
BILLBOARD_Y = 0x2,
|
||||
BILLBOARD_Z = 0x4,
|
||||
|
||||
BILLBOARD_CYLINDRICAL = BILLBOARD_X|BILLBOARD_Z,
|
||||
BILLBOARD_SPHERICAL = BILLBOARD_X|BILLBOARD_Y|BILLBOARD_Z
|
||||
};
|
||||
|
||||
API model_t model(const char *filename, int flags);
|
||||
API model_t model_from_mem(const void *mem, int sz, int flags);
|
||||
API float model_animate(model_t, float curframe);
|
||||
|
|
|
@ -3707,6 +3707,15 @@ typedef struct model_t {
|
|||
unsigned num_instances;
|
||||
} model_t;
|
||||
|
||||
enum BILLBOARD_MODE {
|
||||
BILLBOARD_X = 0x1,
|
||||
BILLBOARD_Y = 0x2,
|
||||
BILLBOARD_Z = 0x4,
|
||||
|
||||
BILLBOARD_CYLINDRICAL = BILLBOARD_X|BILLBOARD_Z,
|
||||
BILLBOARD_SPHERICAL = BILLBOARD_X|BILLBOARD_Y|BILLBOARD_Z
|
||||
};
|
||||
|
||||
API model_t model(const char *filename, int flags);
|
||||
API model_t model_from_mem(const void *mem, int sz, int flags);
|
||||
API float model_animate(model_t, float curframe);
|
||||
|
|
Loading…
Reference in New Issue