v4k-git-backup/engine/art/shaders/vs_323444143_16_3322_model....

46 lines
1.4 KiB
GLSL

#include "model_vs.glsl"
// lights
#include "light.glsl"
void main() {
vec3 objPos = get_object_pos();
v_normal_ws = normalize(vec3(att_instanced_matrix * vec4(v_normal, 0.))); // normal to world/model space
v_normal = normalize(v_normal);
v_position = att_position;
v_texcoord = att_texcoord;
v_texcoord2 = att_texcoord2;
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;
setup_billboards(modelView, l_model);
v_position_ws = (l_model * vec4( objPos, 1.0 )).xyz;
v_tangent = normalize(mat3(att_instanced_matrix) * att_tangent.xyz);
#if 0
// compute tangent T and bitangent B
vec3 Q1 = dFdx(att_position);
vec3 Q2 = dFdy(att_position);
vec2 st1 = dFdx(att_texcoord);
vec2 st2 = dFdy(att_texcoord);
vec3 T = normalize(Q1*st2.t - Q2*st1.t);
vec3 B = normalize(-Q1*st2.s + Q2*st1.s);
vec3 binormal = B;
#else
vec3 binormal = cross(att_normal, att_tangent.xyz) * att_tangent.w;
#endif
v_binormal = normalize(mat3(att_instanced_matrix) * binormal);
vec4 finalPos = modelView * vec4( objPos, 1.0 );
vec3 to_camera = normalize( -finalPos.xyz );
v_to_camera = mat3( inv_view ) * to_camera;
v_vertcolor = lighting();
gl_Position = P * finalPos;
do_shadow();
}