From: Mikko Rasa Date: Mon, 12 Apr 2021 14:32:06 +0000 (+0300) Subject: Refactor vertex transformations in the common shader X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0ae56cb38a715c36c279a4f07ff4562830176dec;p=libs%2Fgl.git Refactor vertex transformations in the common shader It makes more sense to have virtual accessors for the transformation matrices so the returned matrix can be used multiple times. --- diff --git a/shaderlib/common.glsl b/shaderlib/common.glsl index 849d97c9..54d66e60 100644 --- a/shaderlib/common.glsl +++ b/shaderlib/common.glsl @@ -22,24 +22,27 @@ virtual vec3 get_vertex_normal() return normal; } -virtual vec4 transform_position(vec4 pos) +virtual mat4 get_vertex_transform() { - return eye_obj_matrix*pos; + return eye_obj_matrix; } -virtual vec3 transform_normal(vec3 nor) +virtual mat3 get_normal_transform() { - return eye_obj_normal_matrix*nor; + return eye_obj_normal_matrix; } void standard_transform() { - out vec4 eye_vertex = transform_position(get_vertex_position()); + mat4 vertex_tf = get_vertex_transform(); + mat3 normal_tf = get_normal_transform(); + + out vec4 eye_vertex = vertex_tf*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 vec3 eye_normal = normal_tf*get_vertex_normal(); + vec3 eye_tangent = normal_tf*tangent; + vec3 eye_binormal = normal_tf*binormal; out mat3 eye_tbn_matrix = mat3(eye_tangent, eye_binormal, eye_normal); out vec3 eye_look_dir = normalize(eye_vertex.xyz);