summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/fragmentshader.glsl21
-rwxr-xr-xexample/mainbin49192 -> 49488 bytes
-rw-r--r--example/main.cpp2
-rw-r--r--example/main.obin4424 -> 4752 bytes
-rw-r--r--example/vertexshader.glsl10
5 files changed, 30 insertions, 3 deletions
diff --git a/example/fragmentshader.glsl b/example/fragmentshader.glsl
index d15860a..70c55b5 100644
--- a/example/fragmentshader.glsl
+++ b/example/fragmentshader.glsl
@@ -1,6 +1,25 @@
#version 130
out vec4 outpix;
+uniform vec3 campos;
+uniform vec3 lightpos;
+//varing blends them it is transformed to world space
+varying vec4 fragpos;
+varying vec4 fragnormal;
void main()
{
- outpix = vec4(1.0, 0.0, 0.0, 0.5);
+ vec3 lightnormal = normalize((lightpos - vec3(fragpos.x, fragpos.y, fragpos.z)));
+ float diffuse = dot(lightnormal, vec3(fragnormal.x, fragnormal.y, fragnormal.z));
+ if (diffuse < 0.0) {
+ diffuse = 0.0;
+ }
+ vec3 camnormal = normalize(campos - vec3(fragpos.x, fragpos.y, fragpos.z));
+ float reflect = dot(camnormal, fragnormal.xyz);
+ diffuse = pow(diffuse, 2.0);
+ reflect = pow(reflect, 2.0);
+ float light = .4 * reflect + .6 * diffuse;
+ //this should be the vertex in camera space without the w value
+ //outpix = gl_FragCoord;
+ outpix = vec4(light * 1.0,light * 1.0,light * 1.0, 1.0);
+ //outpix = vec4(fragpos.x ,fragpos.y ,fragpos.z, 0.5);
+ //outpix = vec4(fragnormal.x, fragnormal.y, fragnormal.z, 0.5);
}
diff --git a/example/main b/example/main
index 5d3327b..e4895a1 100755
--- a/example/main
+++ b/example/main
Binary files differ
diff --git a/example/main.cpp b/example/main.cpp
index 0748ace..05777a4 100644
--- a/example/main.cpp
+++ b/example/main.cpp
@@ -11,6 +11,8 @@ int main (int argc, char * argv[]) {
//inits program
initgfx(400,600, "rotating cube");
initglgfx();
+ setlight(0,10,10);
+ setcam(0.0,0.0,1.0, 0.0,0.0,0.0, 0.0,1.0,0.0);
//main loop, this is defined in main.h and global
loop = 1;
while(loop) {
diff --git a/example/main.o b/example/main.o
index 5b75d16..37c8220 100644
--- a/example/main.o
+++ b/example/main.o
Binary files differ
diff --git a/example/vertexshader.glsl b/example/vertexshader.glsl
index 4187969..f60ec9f 100644
--- a/example/vertexshader.glsl
+++ b/example/vertexshader.glsl
@@ -2,9 +2,15 @@
uniform mat4 proj;
uniform mat4 tran;
uniform mat4 cam;
+uniform mat4 rot;
in vec3 position;
-
+in vec3 vnormal;
+varying vec4 fragpos;
+varying vec4 fragnormal; // if this needs to not be blended jsut have all vertexes in a poly be the same
void main()
{
- gl_Position = proj * cam * tran * vec4(position, 1.0f);
+ //this is the actual position
+ gl_Position = proj * cam * tran * vec4(position, 1.0f);// - vec4(gl_Normal, 1.0f);
+ fragpos = tran * vec4(position, 1.0f);
+ fragnormal = (tran * vec4(vnormal, 1.0f)) - (tran * vec4(0.0, 0.0, 0.0, 1.0));
}