From d03d86eb8489e7ab4c5460cea5ee265b0c1ee487 Mon Sep 17 00:00:00 2001 From: Eleni Maria Stea Date: Tue, 25 Jul 2017 17:34:45 +0300 Subject: [PATCH] quick backup +added the default shader files --- gl_shaders/default.f.glsl | 29 +++++++++++++++++++++++++++++ gl_shaders/default.v.glsl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 gl_shaders/default.f.glsl create mode 100644 gl_shaders/default.v.glsl diff --git a/gl_shaders/default.f.glsl b/gl_shaders/default.f.glsl new file mode 100644 index 0000000..388ba76 --- /dev/null +++ b/gl_shaders/default.f.glsl @@ -0,0 +1,29 @@ +#version 450 + +uniform sampler2D tex; + +uniform vec4 diffuse; +uniform vec4 specular; +uniform float shininess; + +varying vec3 pos; +varying vec3 normal; +varying vec3 ldir; +varying vec3 tex_coord; + +layout(location = 0) out vec4 color; + +void main() +{ + vec3 p = normalize(pos); + vec3 n = normalize(normal); + vec3 l = normalize(ldir); + + vec3 r = normalize(-reflect(l, n)); + vec3 vdir = normalize(-p); + + float cdiff = max(dot(l, n), 0.0); + float cspec = pow(max(dot(r, vdir), 0.0), shininess); + + color = diffuse * cdiff * texture2D(tex, tex_coord.xy) + specular * cspec; +} diff --git a/gl_shaders/default.v.glsl b/gl_shaders/default.v.glsl new file mode 100644 index 0000000..59db728 --- /dev/null +++ b/gl_shaders/default.v.glsl @@ -0,0 +1,30 @@ +#version 450 +//#extension GL_ARB_separate_shader_objects : enable + +uniform mat4 mview; +uniform mat4 mproj; + +varying vec3 pos; +varying vec3 normal; +varying vec3 ldir; +varying vec3 tex_coord; + +const vec3 lpos = vec3(0.0, 100.0, 0.0); + +/* attributes */ +layout(location = 1) in vec3 attr_pos; +layout(location = 2) in vec3 attr_normal; +layout(location = 3) in vec3 attr_tex; + +void main() +{ + mat4 modelview_projection_matrix = mproj * mview; + gl_Position = modelview_projection_matrix * vec4(attr_pos, 1.0); + + pos = (mview * vec4(attr_pos, 1.0)).xyz; + ldir = (mview * vec4(lpos, 1.0)).xyz; + + mat3 normal_matrix = mat3(mview); + normal = normal_matrix * attr_normal; + tex_coord = attr_tex; +} -- 1.7.10.4