summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/fragmentshader.glsl6
-rw-r--r--example/fragmentshadowshader.glsl49
-rwxr-xr-xexample/mainbin54360 -> 54872 bytes
-rw-r--r--example/main.cpp9
-rw-r--r--example/main.obin5904 -> 7256 bytes
-rw-r--r--example/vertexshadowshader.glsl19
6 files changed, 80 insertions, 3 deletions
diff --git a/example/fragmentshader.glsl b/example/fragmentshader.glsl
index fc7b4c8..064dad6 100644
--- a/example/fragmentshader.glsl
+++ b/example/fragmentshader.glsl
@@ -36,9 +36,9 @@ void main()
dist = 1.0;
}
dist = 1 - pow(dist, 4.0);
- float lightr = (elevpix.b) * 1.0 * lightattrib.r * reflect + elevpix.a * 1.0 * dist * diffuse;
- float lightg = (elevpix.b) * 1.0 * lightattrib.g * reflect + elevpix.a * 1.0 * dist * diffuse;
- float lightb = (elevpix.b) * 1.0 * lightattrib.b * reflect + elevpix.a * 1.0 * dist * diffuse;
+ float lightr = (elevpix.b) * 0.5 * lightattrib.r * reflect + elevpix.a * 0.5 * dist * diffuse;
+ float lightg = (elevpix.b) * 0.5 * lightattrib.g * reflect + elevpix.a * 0.5 * dist * diffuse;
+ float lightb = (elevpix.b) * 0.5 * lightattrib.b * reflect + elevpix.a * 0.5 * dist * diffuse;
vec4 texpix = texture(tex, fragtexcoord);
//this should be the vertex in camera space without the w value
//outpix = gl_FragCoord;
diff --git a/example/fragmentshadowshader.glsl b/example/fragmentshadowshader.glsl
new file mode 100644
index 0000000..4e551c4
--- /dev/null
+++ b/example/fragmentshadowshader.glsl
@@ -0,0 +1,49 @@
+#version 130
+out vec4 outpix;
+uniform vec3 campos;
+uniform vec3 lightpos;
+uniform vec4 lightattrib;
+uniform sampler2D tex;
+uniform sampler2D elev;
+//varing blends them it is transformed to world space
+varying vec4 fragpos;
+varying vec4 fragnormal;
+varying vec2 fragtexcoord;
+void main()
+{
+ vec4 elevpix = texture(elev, fragtexcoord);
+ //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;
+ } else {
+ }
+ vec3 camnormal = normalize(campos - refpos);
+ lightnormal = normalize((refpos - lightpos)); // this time it is an incoming vector
+ vec3 refnormal = lightnormal - (2 * dot(lightnormal, fragnormal.xyz) * fragnormal.xyz);
+ float reflect = dot(camnormal, refnormal);
+ if (reflect < 0.0) {
+ reflect = 0.0;
+ } else {
+ }
+ diffuse = pow(diffuse, 2.0);
+ reflect = pow(reflect, 2.0);
+ float dist = abs(length(difpos - lightpos)) / lightattrib.a;
+ if (dist > 1.0) {
+ dist = 1.0;
+ }
+ dist = 1 - pow(dist, 4.0);
+ float lightr = (elevpix.b) * 0.5 * lightattrib.r * reflect + elevpix.a * 0.5 * dist * diffuse;
+ float lightg = (elevpix.b) * 1.0 * lightattrib.g * reflect + elevpix.a * 1.0 * dist * diffuse;
+ float lightb = (elevpix.b) * 0.5 * lightattrib.b * reflect + elevpix.a * 0.5 * dist * diffuse;
+ vec4 texpix = texture(tex, fragtexcoord);
+ //this should be the vertex in camera space without the w value
+ //outpix = gl_FragCoord;
+ outpix = vec4(lightr * texpix.r, lightg * texpix.g, lightb * texpix.b, texpix.a);
+ //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 9f2411e..84014cc 100755
--- a/example/main
+++ b/example/main
Binary files differ
diff --git a/example/main.cpp b/example/main.cpp
index 6b7975c..476f4d7 100644
--- a/example/main.cpp
+++ b/example/main.cpp
@@ -40,14 +40,23 @@ int main (int argc, char * argv[]) {
}
switch (rot) {
case 0:
+ useregshaders();
+ setlight(2.0,10.0,3.0, 1.0, 0.5, 0.5, 15.0);
+ setcam(0.0,0.0,1.0, 0.0,0.0,0.0, 0.0,1.0,0.0);
drawmodel(0.0f, 0.0f, -2.0f, dir, 0.0f, 0.0f, 1.0, 1.0, 1.0);
drawmodel(0.5f, 3.0f, -10.0f, dir, 0.0f, 0.0f, 1.0, 1.0, 1.0);
break;
case 1:
+ useshadowshaders();
+ setlight(2.0,10.0,3.0, 1.0, 0.5, 0.5, 15.0);
+ setcam(0.0,0.0,1.0, 0.0,0.0,0.0, 0.0,1.0,0.0);
drawmodel(0.0f, 0.0f, -2.0f, 0.0f, dir, 0.0f, 1.0, 1.0, 1.0);
drawmodel(0.5f, 3.0f, -10.0f, 0.0f, dir, 0.0f, 1.0, 1.0, 1.0);
break;
case 2:
+ useregshaders();
+ setlight(2.0,10.0,3.0, 1.0, 0.5, 0.5, 15.0);
+ setcam(0.0,0.0,1.0, 0.0,0.0,0.0, 0.0,1.0,0.0);
drawmodel(0.0f, 0.0f, -2.0f, 0.0f, 0.0f, dir, 1.0, 1.0, 1.0);
drawmodel(0.5f, 3.0f, -10.0f, 0.0f, 0.0f, dir, 1.0, 1.0, 1.0);
break;
diff --git a/example/main.o b/example/main.o
index c6267ba..dd10363 100644
--- a/example/main.o
+++ b/example/main.o
Binary files differ
diff --git a/example/vertexshadowshader.glsl b/example/vertexshadowshader.glsl
new file mode 100644
index 0000000..8ba8228
--- /dev/null
+++ b/example/vertexshadowshader.glsl
@@ -0,0 +1,19 @@
+#version 130
+uniform mat4 proj;
+uniform mat4 tran;
+uniform mat4 cam;
+uniform mat4 rot;
+in vec3 position;
+in vec3 vnormal;
+in vec3 texcoord;
+varying vec4 fragpos;
+varying vec4 fragnormal; // if this needs to not be blended jsut have all vertexes in a poly be the same
+varying vec2 fragtexcoord;
+void main()
+{
+ //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));
+ fragtexcoord = texcoord.xy;
+}