From 5ca47579de51342ac3e8ecda2cbb9be2f8b4643a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 5 Jun 2020 00:04:53 +0300 Subject: [PATCH] Add a new, better structured Phong shader --- shaderlib/common.glsl | 94 +++++++++++++++++++++++++++ shaderlib/msp_interface.glsl | 2 +- shaderlib/phong.glsl | 120 +++++++++++++++++++++++++++++++++++ shaderlib/shadow.glsl | 21 ++++++ shaderlib/singlepass.glsl | 3 +- 5 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 shaderlib/common.glsl create mode 100644 shaderlib/phong.glsl create mode 100644 shaderlib/shadow.glsl 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