quick backup
authorEleni Maria Stea <elene.mst@gmail.com>
Tue, 25 Jul 2017 14:34:45 +0000 (17:34 +0300)
committerEleni Maria Stea <elene.mst@gmail.com>
Tue, 25 Jul 2017 14:34:45 +0000 (17:34 +0300)
+added the default shader files

gl_shaders/default.f.glsl [new file with mode: 0644]
gl_shaders/default.v.glsl [new file with mode: 0644]

diff --git a/gl_shaders/default.f.glsl b/gl_shaders/default.f.glsl
new file mode 100644 (file)
index 0000000..388ba76
--- /dev/null
@@ -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 (file)
index 0000000..59db728
--- /dev/null
@@ -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;
+}