diff options
author | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-23 14:25:59 -0600 |
---|---|---|
committer | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-23 14:25:59 -0600 |
commit | e3a07ab4ccf65ddf052b483cf879f6a9bdd97720 (patch) | |
tree | f2806f605ec7d607813cb325c889307af379bab6 /shaders | |
parent | 4d62a6d631fb9703d818654c5b9722e747cfe190 (diff) | |
parent | 4319bad3c312545e56c236a0515d1c1e9cdbf03d (diff) | |
download | terralloc-e3a07ab4ccf65ddf052b483cf879f6a9bdd97720.tar.gz terralloc-e3a07ab4ccf65ddf052b483cf879f6a9bdd97720.tar.bz2 terralloc-e3a07ab4ccf65ddf052b483cf879f6a9bdd97720.zip |
Merge branch 'sun'
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/sky.frag | 20 | ||||
-rw-r--r-- | shaders/sky.vert | 3 | ||||
-rw-r--r-- | shaders/water.frag | 20 | ||||
-rw-r--r-- | shaders/water.tes | 9 |
4 files changed, 43 insertions, 9 deletions
diff --git a/shaders/sky.frag b/shaders/sky.frag index a2c2ecd..6d47adb 100644 --- a/shaders/sky.frag +++ b/shaders/sky.frag @@ -5,13 +5,29 @@ layout(location = 0) out vec4 frag_color ; layout(location = 1) uniform vec4 globalAmbient ; +uniform vec4 lightpos ; + uniform sampler2D texture ; uniform sampler2D night_tex ; + in vec2 texcoord; +in vec4 position ; -void main() { +float exp1( float x ) { + return 2 / (1+exp(-x))-1; +} +void main() { + // the sun + + vec3 lighttofrag = vec3(position*10000000 - lightpos) ; + vec3 lighttocamera = vec3(lightpos) ; + float coef = 1 - dot(normalize(lighttocamera), normalize(lighttofrag)); + vec4 mul = vec4(vec3( pow(0.0005 / coef,0.8)), 1) ; + mul *= vec4(1.0,0.85,0.5,1.0) ; frag_color = mix(texture2D(night_tex,texcoord) * (1-globalAmbient.a), texture2D(texture,texcoord) * vec4(normalize(globalAmbient.xyz),1), - (globalAmbient.a + 1) / 2) ; + (globalAmbient.a + 1) / 2) * 1.8 ; + frag_color = frag_color + mul ; + } diff --git a/shaders/sky.vert b/shaders/sky.vert index 87d919b..5609bec 100644 --- a/shaders/sky.vert +++ b/shaders/sky.vert @@ -11,8 +11,9 @@ uniform mat4 mvMatrix ; uniform mat4 pjMatrix ; out vec2 texcoord ; +out vec4 position ; void main() { - gl_Position = pjMatrix * mvMatrix * vec4(in_position,1.0); + gl_Position = pjMatrix * (position = mvMatrix * vec4(in_position,1.0)); texcoord = in_texcoord ; } diff --git a/shaders/water.frag b/shaders/water.frag index 2d6b7da..6c2aa2b 100644 --- a/shaders/water.frag +++ b/shaders/water.frag @@ -6,10 +6,12 @@ layout(location = 0) out vec4 frag_color ; layout(location = 8) uniform vec4 lightPos ; layout(location = 9) uniform float time ; layout(location = 10) uniform vec4 globalAmbient ; +layout(location = 5) uniform mat4 mvMatrix ; - uniform sampler2D texture ; - uniform sampler2D skytex ; - uniform sampler2D skynight ; +uniform sampler2D texture ; +uniform sampler2D skytex ; +uniform sampler2D skynight ; +uniform vec4 lightpos ; in vec3 normal ; in vec4 position ; @@ -42,6 +44,16 @@ vec3 calNormChange( vec3 norm, vec3 down, vec3 right ) { in vec3 original_x ; in vec3 original_z ; +in vec3 tmpnormal ; + +vec4 specular( vec3 a_normal ) { + vec3 difpos = -normalize(vec3(0,0,0) - vec3(position)) ; + difpos = reflect( difpos, a_normal ) ; + vec3 lightpos2 = reflect( reflect( vec3(lightPos), original_x ), original_z ); + vec3 diflight = normalize(vec3(lightpos2) - vec3(position)) ; + float d = pow(max(dot( normalize(difpos), -normalize(diflight) ), 0.0 ),100.0); + return vec4(vec3(d),1) ; +} void main() { vec3 down = vec3( 0, -1, 0 ) ; vec3 right = normalize(cross( normal, down )) ; @@ -59,6 +71,8 @@ void main() { mix(texture2D(skynight,tmpcoord) * (1-globalAmbient.a), texture2D(skytex,tmpcoord) * vec4(normalize(globalAmbient.xyz),1), (globalAmbient.a + 1) / 2) ; + vec3 nlightpos = reflect( vec3(lightPos), vec3(mvMatrix * vec4(0,1,0,1)) ) ; + refcolor += specular( newNorm ) ; float coef = dot( normalize(vec3(lightPos) - vec3(position)), normalize(normal) ) * 0.5 + 0.5 ; diff --git a/shaders/water.tes b/shaders/water.tes index 0c5c1a5..56f998a 100644 --- a/shaders/water.tes +++ b/shaders/water.tes @@ -23,13 +23,14 @@ out vec2 texpos ; out vec3 original_x ; out vec3 original_z ; +out vec3 tmpnormal ; vec2 skew( float t ) { return vec2(0.8*sin(t-time)+t,sin(t-time) / 5) ; } vec2 dskew( float t ) { - return vec2(0.8*(cos( time - t )+ 1), cos(time - t) / 5) ; + return vec2(-cos(time-t),5*(0.8*cos(time-t)+1)) ; } vec2 xripple( float t ) { @@ -37,7 +38,7 @@ vec2 xripple( float t ) { } vec2 dxripple( float t ) { - return vec2(1,-cos(time-t)/5.0) ; + return vec2(cos(time-t)/5.0,-1); } void main () { @@ -56,10 +57,12 @@ void main () { vec2 xr = xripple(pos.x) ; vec2 dxr = dxripple(pos.x) ; pos = vec3( xr.x, pos.y + sk.y + xr.y, sk.x); - vec3 normal_ = vec3(dxr.x, dsk.y+dxr.y, dsk.x) ; + vec3 normal_ = vec3(dxr.x, (dsk.y+dxr.y)/2, dsk.x) ; normal = - normalMatrix * normal_; // cross( p0 - p1, p0 - p2 ); + tmpnormal = normalize(normal_) ; } else { normal = - normalMatrix * vec3(0,1,0) ; + tmpnormal = vec3(0,1,0); } texpos = pos.xz / 20.0 ; gl_Position = pjMatrix * (position = mvMatrix * vec4(pos, 1.0)); |