diff options
author | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-18 01:17:46 -0600 |
---|---|---|
committer | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-18 01:17:46 -0600 |
commit | 915cda147b565880fecefe5f82ca242bad6114fc (patch) | |
tree | d6afedd6d33bdca1601faaaebd731b89aab75431 /shaders | |
parent | 73daf65aaa31b5fb59f4a91d9185387f63c7b09f (diff) | |
download | terralloc-915cda147b565880fecefe5f82ca242bad6114fc.tar.gz terralloc-915cda147b565880fecefe5f82ca242bad6114fc.tar.bz2 terralloc-915cda147b565880fecefe5f82ca242bad6114fc.zip |
starting tesselation shader
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/.basic.frag.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | shaders/.water.frag.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | shaders/basic.frag | 2 | ||||
-rw-r--r-- | shaders/water.frag | 40 | ||||
-rw-r--r-- | shaders/water.vert | 9 |
5 files changed, 48 insertions, 3 deletions
diff --git a/shaders/.basic.frag.swp b/shaders/.basic.frag.swp Binary files differdeleted file mode 100644 index 66aabb3..0000000 --- a/shaders/.basic.frag.swp +++ /dev/null diff --git a/shaders/.water.frag.swp b/shaders/.water.frag.swp Binary files differdeleted file mode 100644 index 73b3be2..0000000 --- a/shaders/.water.frag.swp +++ /dev/null diff --git a/shaders/basic.frag b/shaders/basic.frag index 4d7683c..719137d 100644 --- a/shaders/basic.frag +++ b/shaders/basic.frag @@ -4,8 +4,8 @@ layout(location = 0) out vec4 frag_color ; layout(location = 6) uniform vec4 lightPos ; - layout(location = 8) uniform vec4 globalAmbient ; + uniform float dX ; uniform float dY ; diff --git a/shaders/water.frag b/shaders/water.frag index 8a0dd0b..9298d15 100644 --- a/shaders/water.frag +++ b/shaders/water.frag @@ -3,7 +3,45 @@ #extension GL_ARB_explicit_uniform_location : enable layout(location = 0) out vec4 frag_color ; +layout(location = 8) uniform vec4 lightPos ; + uniform sampler2D texture ; + +in vec3 normal ; +in vec4 position ; +in vec2 texpos ; + +float dX = 1 / 512.0 ; +float dY = 1 / 512.0 ; +vec4 sample(float xc,float yc) { + return texture2D(texture,texpos + vec2(xc,yc)); +} + +vec3 calNormChange( vec3 norm, vec3 down, vec3 right ) { + float x00 = 1 - length(sample(-dX, dY)) ; + float x01 = 1 - length(sample( 0, dY)) ; + float x02 = 1 - length(sample( dX, dY)) ; + + float x10 = 1 - length(sample(-dX, 0)) ; + float x11 = 1 - length(sample( 0, 0)) ; + float x12 = 1 - length(sample( dX, 0)) ; + + float x20 = 1 - length(sample(-dX,-dY)) ; + float x21 = 1 - length(sample( 0,-dY)) ; + float x22 = 1 - length(sample( dX,-dY)) ; + + down = ((x11 - x00) + (x11 - x01) + (x11 - x02) - (x11 - x20) - (x11 - x21) - (x11 - x22)) * down ; + right = ((x11 - x00) + (x11 - x10) + (x11 - x20) - (x11 - x02) - (x11 - x12) - (x11 - x22)) * right ; + + return (right*2 + down*2 + norm) / 5.0 ; +} void main() { - frag_color = vec4(0.0,0.3,0.7,0.5) ; + vec3 down = vec3( 0, -1, 0 ) ; + vec3 right = normalize(cross( normal, down )) ; + down = normalize(cross( normal, right ) ); + vec3 newNorm = calNormChange( normal, down, right ) ; + + float coef = dot( normalize(vec3(lightPos) - vec3(position)), normalize(newNorm) ) ; + vec4 color = texture2D(texture,texpos) ; + frag_color = vec4(color.xyz * vec3(0.0,0.4,0.7) * coef,0.8); } diff --git a/shaders/water.vert b/shaders/water.vert index 1db6dc5..765c1df 100644 --- a/shaders/water.vert +++ b/shaders/water.vert @@ -11,6 +11,13 @@ layout(location = 4) uniform mat4 pjMatrix ; layout(location = 5) uniform mat4 mvMatrix ; layout(location = 7) uniform mat3 normalMatrix ; +out vec3 lightPos ; +out vec3 normal ; +out vec4 position ; +out vec2 texpos ; + void main() { - gl_Position = pjMatrix * mvMatrix * vec4( in_position, 1.0 ); + gl_Position = pjMatrix * (position = mvMatrix * vec4( in_position, 1.0 )); + normal = normalMatrix * vec3(0,1,0) ; + texpos = in_position.xz / 20.0; } |