From c7bdd6fcae58e09597071405c1449df64e084c51 Mon Sep 17 00:00:00 2001 From: knolax <1339802534.kk@gmail.com> Date: Wed, 22 Feb 2017 20:43:47 -0500 Subject: implemented phoung shading and surrounding infrastructure, gen.cpp compiles a simple program that creates raw vertex data from vertexes in a way that surppassess the limitations of opengl's native elements[] protocol. next step is to allow for z distance based override and multi draw; --- example/fragmentshader.glsl | 21 ++++++++++++++++++++- example/main | Bin 49192 -> 49488 bytes example/main.cpp | 2 ++ example/main.o | Bin 4424 -> 4752 bytes example/vertexshader.glsl | 10 ++++++++-- 5 files changed, 30 insertions(+), 3 deletions(-) (limited to 'example') 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 Binary files a/example/main and b/example/main 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 Binary files a/example/main.o and b/example/main.o 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)); } -- cgit v1.1