From: Mikko Rasa Date: Thu, 4 Jun 2020 21:04:53 +0000 (+0300) Subject: Add a new, better structured Phong shader X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5ca47579de51342ac3e8ecda2cbb9be2f8b4643a;p=libs%2Fgl.git Add a new, better structured Phong shader --- diff --git a/shaderlib/common.glsl b/shaderlib/common.glsl new file mode 100644 index 00000000..7222b00f --- /dev/null +++ b/shaderlib/common.glsl @@ -0,0 +1,94 @@ +import msp_interface; +import shadow; + +const bool use_normal_map = false; + +#pragma MSP stage(vertex) +vec4 get_vertex_position() +{ + return vertex; +} + +vec3 get_vertex_normal() +{ + return normal; +} + +vec4 transform_position(vec4 pos) +{ + return eye_obj_matrix*pos; +} + +vec3 transform_normal(vec3 nor) +{ + return eye_obj_normal_matrix*nor; +} + +void standard_transform() +{ + out vec4 eye_vertex = transform_position(get_vertex_position()); + gl_Position = projection_matrix*eye_vertex; + + out vec3 eye_normal = transform_normal(get_vertex_normal()); + vec3 eye_tangent = transform_normal(tangent); + vec3 eye_binormal = transform_normal(binormal); + out mat3 eye_tbn_matrix = mat3(eye_tangent, eye_binormal, eye_normal); + + out vec3 eye_look_dir = normalize(eye_vertex.xyz); + out vec3 tbn_look_dir = eye_look_dir*eye_tbn_matrix; + + out vec3 eye_light_dir = normalize(light_sources[0].position.xyz-eye_vertex.xyz*light_sources[0].position.w); + out vec3 tbn_light_dir = eye_light_dir*eye_tbn_matrix; + + out vec3 eye_halfway_dir = normalize(eye_light_dir-eye_look_dir); + out vec3 tbn_halfway_dir = eye_halfway_dir*eye_tbn_matrix; + + out vec3 tbn_zenith_dir = eye_zenith_dir*eye_tbn_matrix; + out vec3 shadow_coord = (shd_eye_matrix*eye_vertex).xyz; + out float fog_coord = eye_vertex.z; + + for(int i=0; i