diff options
author | knolax <1339802534.kk@gmail.com> | 2017-03-01 10:51:50 -0500 |
---|---|---|
committer | knolax <1339802534.kk@gmail.com> | 2017-03-01 10:51:50 -0500 |
commit | 50462167289384ba8c546331a71d8d8558f06c80 (patch) | |
tree | 655c34c43889c47e86a8d9f5159af8850158c08c | |
parent | cf3f284a5f24bd02006e9ff929cc29d10c428a3e (diff) |
changed the elevation texture and switched the diffuse/reflect value positions
-rw-r--r-- | example/fragmentshader.glsl | 17 | ||||
-rwxr-xr-x | example/main | bin | 54072 -> 54184 bytes | |||
-rw-r--r-- | example/main.cpp | 13 | ||||
-rw-r--r-- | example/main.o | bin | 4824 -> 5152 bytes | |||
-rw-r--r-- | example/textures/elev.bmp | bin | 4000138 -> 262282 bytes | |||
-rw-r--r-- | glgfx.cpp | 4 | ||||
-rw-r--r-- | glgfx.h | 2 | ||||
-rw-r--r-- | glgfx.o | bin | 60880 -> 62104 bytes | |||
-rw-r--r-- | 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 Binary files differindex 14fd1e1..248dc85 100755 --- a/example/main +++ b/example/main 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 Binary files differindex adf6955..0a41d2f 100644 --- a/example/main.o +++ b/example/main.o diff --git a/example/textures/elev.bmp b/example/textures/elev.bmp Binary files differindex cb9fec6..6ec48f8 100644 --- a/example/textures/elev.bmp +++ b/example/textures/elev.bmp @@ -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)); @@ -11,7 +11,7 @@ #include <glm/gtc/type_ptr.hpp> 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(); Binary files differBinary files differ |