From 50462167289384ba8c546331a71d8d8558f06c80 Mon Sep 17 00:00:00 2001 From: knolax <1339802534.kk@gmail.com> Date: Wed, 1 Mar 2017 10:51:50 -0500 Subject: changed the elevation texture and switched the diffuse/reflect value positions --- example/fragmentshader.glsl | 17 +++++++++++------ example/main | Bin 54072 -> 54184 bytes example/main.cpp | 13 +++++++------ example/main.o | Bin 4824 -> 5152 bytes example/textures/elev.bmp | Bin 4000138 -> 262282 bytes glgfx.cpp | 4 ++-- glgfx.h | 2 +- glgfx.o | Bin 60880 -> 62104 bytes libglgfx.a | Bin 65108 -> 66420 bytes 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/example/fragmentshader.glsl b/example/fragmentshader.glsl index 6e8c4c5..631ea69 100644 --- a/example/fragmentshader.glsl +++ b/example/fragmentshader.glsl @@ -11,20 +11,25 @@ varying vec2 fragtexcoord; void main() { vec4 elevpix = texture(elev, fragtexcoord); - vec3 lightnormal = normalize((lightpos - vec3(fragpos.x, fragpos.y, fragpos.z))); - float diffuse = dot(lightnormal, vec3(fragnormal.x, fragnormal.y, fragnormal.z)); + //the format is diffuse reflect and percent + vec3 difpos = vec3(fragpos.xyz) + ((elevpix.r - .5) * 2 * fragnormal.xyz); + vec3 refpos = vec3(fragpos.xyz) + ((elevpix.g - .5) * 2 * fragnormal.xyz); + vec3 lightnormal = normalize((lightpos - difpos)); + float diffuse = dot(lightnormal, fragnormal.xyz); if (diffuse < 0.0) { diffuse = 0.0; } - vec3 camnormal = normalize(campos - vec3(fragpos.x, fragpos.y, fragpos.z)); - float reflect = dot(camnormal, fragnormal.xyz); + vec3 camnormal = normalize(campos - refpos); + lightnormal = -normalize((lightpos - refpos)); // this time it is an incoming vector + vec3 refnormal = lightnormal - (2 * dot(lightnormal, fragnormal.xyz) * fragnormal.xyz); + float reflect = dot(camnormal, refnormal); diffuse = pow(diffuse, 2.0); reflect = pow(reflect, 2.0); - float light = .4 * reflect + .6 * diffuse; + float light = (elevpix.b) * reflect + elevpix.a * diffuse; vec4 texpix = texture(tex, fragtexcoord); //this should be the vertex in camera space without the w value //outpix = gl_FragCoord; - outpix = texpix; + outpix = light * texpix; //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 14fd1e1..248dc85 100755 Binary files a/example/main and b/example/main differ diff --git a/example/main.cpp b/example/main.cpp index d71322b..a92ce4b 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -40,18 +40,19 @@ int main (int argc, char * argv[]) { } switch (rot) { case 0: - drawmodel(0.0f, 0.0f, -2.0f, dir, 0.0f, 0.0f); - drawmodel(0.5f, 3.0f, -10.0f, dir, 0.0f, 0.0f); + drawmodel(0.0f, 0.0f, -2.0f, dir, 0.0f, 0.0f, 1.0); + drawmodel(0.5f, 3.0f, -10.0f, dir, 0.0f, 0.0f, 1.0); break; case 1: - drawmodel(0.0f, 0.0f, -2.0f, 0.0f, dir, 0.0f); - drawmodel(0.5f, 3.0f, -10.0f, 0.0f, dir, 0.0f); + drawmodel(0.0f, 0.0f, -2.0f, 0.0f, dir, 0.0f, 1.0); + drawmodel(0.5f, 3.0f, -10.0f, 0.0f, dir, 0.0f, 1.0); break; case 2: - drawmodel(0.0f, 0.0f, -2.0f, 0.0f, 0.0f, dir); - drawmodel(0.5f, 3.0f, -10.0f, 0.0f, 0.0f, dir); + drawmodel(0.0f, 0.0f, -2.0f, 0.0f, 0.0f, dir, 1.0); + drawmodel(0.5f, 3.0f, -10.0f, 0.0f, 0.0f, dir, 1.0); break; } + drawmodel(0.0f, -2.0, -5.0,0.0,0.0,0.0,1.0 ); updategfx(); } quitgfx(); diff --git a/example/main.o b/example/main.o index adf6955..0a41d2f 100644 Binary files a/example/main.o and b/example/main.o differ diff --git a/example/textures/elev.bmp b/example/textures/elev.bmp index cb9fec6..6ec48f8 100644 Binary files a/example/textures/elev.bmp and b/example/textures/elev.bmp differ diff --git a/glgfx.cpp b/glgfx.cpp index bed50d4..7b54254 100644 --- a/glgfx.cpp +++ b/glgfx.cpp @@ -243,7 +243,7 @@ int setlight (float x, float y, float z) { } //draws the model, setting perspective transform and position transform //done with magic numbers for now for testing purposes -int drawmodel(float x, float y, float z, float xr, float yr, float zr) { +int drawmodel(float x, float y, float z, float xr, float yr, float zr, float s) { // the transformation matrix = rotation matrix of object * scaling matrix * translaton matrix representing difference in camera and object location * -rotation matrix of the camera * perspective transform //order of application ir right to left //fov, aspect ratio, size of near and far planes distance @@ -259,12 +259,12 @@ int drawmodel(float x, float y, float z, float xr, float yr, float zr) { //); //the translation matrix, matrixes added last are applied first glm::mat4 tran; + tran = glm::scale(tran, glm::vec3(s,s,s)); tran = glm::translate(tran, glm::vec3(x,y,z)); tran = glm::rotate(tran,glm::radians(xr),glm::vec3(1,0,0)); // axis of rotation x y z tran = glm::rotate(tran,glm::radians(yr),glm::vec3(0,1,0)); tran = glm::rotate(tran,glm::radians(zr),glm::vec3(0,0,1)); glm::mat4 rot; - tran = glm::translate(tran, glm::vec3(0,0,0)); rot = glm::rotate(rot,glm::radians(xr),glm::vec3(1,0,0)); // axis of rotation x y z rot = glm::rotate(rot,glm::radians(yr),glm::vec3(0,1,0)); rot = glm::rotate(rot,glm::radians(zr),glm::vec3(0,0,1)); diff --git a/glgfx.h b/glgfx.h index 34677cf..ec40f88 100644 --- a/glgfx.h +++ b/glgfx.h @@ -11,7 +11,7 @@ #include int initglgfx(); int genshaders(); -int drawmodel(float x, float y, float z, float xr, float yr, float zr); +int drawmodel(float x, float y, float z, float xr, float yr, float zr, float s); int setcam (float cpx, float cpy, float cpz, float clx, float cly, float clz, float cux, float cuy, float cuz); int setlight (float x, float y, float z); int quitglgfx(); diff --git a/glgfx.o b/glgfx.o index 7067275..9dcb566 100644 Binary files a/glgfx.o and b/glgfx.o differ diff --git a/libglgfx.a b/libglgfx.a index 0ec416b..ed6181a 100644 Binary files a/libglgfx.a and b/libglgfx.a differ -- cgit v1.1