Skip to content

Instantly share code, notes, and snippets.

/map.frag Secret

Created October 18, 2017 06:31
Show Gist options
  • Save anonymous/7c0421a6c23a45d2e9d7ecfe44eaa59f to your computer and use it in GitHub Desktop.
Save anonymous/7c0421a6c23a45d2e9d7ecfe44eaa59f to your computer and use it in GitHub Desktop.
Shaders
#version 330
in vec2 v_tex_pos;
in vec3 v_light_dir_tansp;
out vec4 color;
uniform sampler2D tex;
uniform sampler2D normal_map;
void main() {
vec3 norm = texture(normal_map, v_tex_pos).rgb * 2.0 - 1.0;
float diffuse = dot(normalize(norm), normalize(v_light_dir_tansp));
diffuse = clamp(diffuse, 0.0, 1.0);
color = texture(tex, v_tex_pos) * diffuse;
}
#version 330
in vec4 pos;
in vec3 norm;
in vec2 tex_pos;
in vec3 tangent;
out vec2 v_tex_pos;
out vec3 v_light_dir_tansp;
uniform mat4 view;
uniform mat4 view_projection;
const vec3 light_pos = vec3(50.0, 25.0, 50.0);
void main() {
vec3 norm_viewsp = mat3(view) * normalize(norm);
vec3 tangent_viewsp = mat3(view) * normalize(tangent);
vec3 bitangent_viewsp = cross(tangent_viewsp, norm_viewsp);
mat3 tbn = transpose(mat3(tangent_viewsp, bitangent_viewsp, norm_viewsp));
vec3 light_dir = light_pos - pos.xyz;
vec3 light_dir_viewsp = mat3(view) * light_dir;
v_tex_pos = tex_pos;
v_light_dir_tansp = tbn * light_dir_viewsp;
gl_Position = view_projection * pos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment