diff options
author | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-18 22:19:36 -0600 |
---|---|---|
committer | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-18 22:19:36 -0600 |
commit | 0f408f531f8b569fe89fbd5d953833d9271e7764 (patch) | |
tree | 382c77e4754f00cf96b0da92adf407dcbd810512 /shaders | |
parent | 9d0f1393c2ceba0cd1e236adf7e88c30b9547490 (diff) | |
download | terralloc-0f408f531f8b569fe89fbd5d953833d9271e7764.tar.gz terralloc-0f408f531f8b569fe89fbd5d953833d9271e7764.tar.bz2 terralloc-0f408f531f8b569fe89fbd5d953833d9271e7764.zip |
ready upload
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/sky.frag | 1 | ||||
-rw-r--r-- | shaders/water.frag | 16 | ||||
-rw-r--r-- | shaders/water.tcs | 28 | ||||
-rw-r--r-- | shaders/water.tes | 69 |
4 files changed, 108 insertions, 6 deletions
diff --git a/shaders/sky.frag b/shaders/sky.frag index 743f538..a2c2ecd 100644 --- a/shaders/sky.frag +++ b/shaders/sky.frag @@ -10,7 +10,6 @@ uniform sampler2D night_tex ; in vec2 texcoord; void main() { - vec3 color2 = texture2D(texture,texcoord).xyz ; frag_color = mix(texture2D(night_tex,texcoord) * (1-globalAmbient.a), texture2D(texture,texcoord) * vec4(normalize(globalAmbient.xyz),1), diff --git a/shaders/water.frag b/shaders/water.frag index fffae31..2d6b7da 100644 --- a/shaders/water.frag +++ b/shaders/water.frag @@ -9,6 +9,7 @@ layout(location = 10) uniform vec4 globalAmbient ; uniform sampler2D texture ; uniform sampler2D skytex ; + uniform sampler2D skynight ; in vec3 normal ; in vec4 position ; @@ -50,15 +51,20 @@ void main() { vec3 camVector = vec3(position) - vec3(0,0,0); vec3 ref = reflect( normalize(camVector), newNorm ) ; - float tex_x = (dot( ref, original_x ) + 1) / 2; - float tex_y = (dot( ref, original_z ) + 1) / 2; - vec4 refcolor = texture2D(skytex, vec2(tex_x,tex_y)); + float tex_x = (abs(dot( ref, original_x )) + 1) / 2; + float tex_y = (abs(dot( ref, original_z )) + 1) / 2; + // vec4 refcolor = texture2D(skytex, vec2(tex_x,tex_y)); + vec2 tmpcoord = vec2(tex_x,tex_y) ; + vec4 refcolor = + mix(texture2D(skynight,tmpcoord) * (1-globalAmbient.a), + texture2D(skytex,tmpcoord) * vec4(normalize(globalAmbient.xyz),1), + (globalAmbient.a + 1) / 2) ; float coef = dot( normalize(vec3(lightPos) - vec3(position)), normalize(normal) ) * 0.5 + 0.5 ; - frag_color = vec4( 0,0,1, 1.0 ); + // frag_color = vec4( 0,0,1, 1.0 ); // frag_color = vec4(tex_x,tex_y,0,1.0) ; // vec4 color = sample(0,0); - // frag_color = vec4(vec3(refcolor * coef) * vec3(0.6,0.8,1.0),0.8) * vec4(normalize(globalAmbient.xyz),1.0); + frag_color = vec4(vec3(refcolor) * vec3(0.6,0.8,1.0),0.95) * vec4(normalize(globalAmbient.xyz),1.0); // frag_color = vec4(0,0,1,0.8) ; } diff --git a/shaders/water.tcs b/shaders/water.tcs new file mode 100644 index 0000000..22b7a49 --- /dev/null +++ b/shaders/water.tcs @@ -0,0 +1,28 @@ +#version 430 + +// number of CPs in patch +layout (vertices = 4) out; + +// from VS (use empty modifier [] so we can say anything) +in vec3 controlpoint[]; + +// to evluation shader. will be used to guide positioning of generated points +out vec3 evaluationpoint[]; + +float tessLevelInner = 30.0; // controlled by keyboard buttons +float tessLevelOuter = 30.0; // controlled by keyboard buttons + +void main () { + evaluationpoint[gl_InvocationID] = controlpoint[gl_InvocationID]; + + // Calculate the tessellation levels + + if ( gl_InvocationID == 0 ) { + gl_TessLevelInner[0] = tessLevelInner; // number of nested primitives to generate + gl_TessLevelInner[1] = tessLevelInner; // number of nested primitives to generate + gl_TessLevelOuter[0] = tessLevelOuter; // times to subdivide first side + gl_TessLevelOuter[1] = tessLevelOuter; // times to subdivide second side + gl_TessLevelOuter[2] = tessLevelOuter; // times to subdivide second side + gl_TessLevelOuter[3] = tessLevelOuter; // times to subdivide second side + } +} diff --git a/shaders/water.tes b/shaders/water.tes new file mode 100644 index 0000000..0c5c1a5 --- /dev/null +++ b/shaders/water.tes @@ -0,0 +1,69 @@ +#version 430 + +// triangles, quads, or isolines +layout (quads, fractional_odd_spacing, ccw) in; +in vec3 evaluationpoint[]; + +// could use a displacement map here + +uniform mat4 viewmat; +uniform mat4 projmat; + +// gl_TessCoord is location within the patch +// (barycentric for triangles, UV for quads) +// +layout(location = 4) uniform mat4 pjMatrix ; +layout(location = 5) uniform mat4 mvMatrix ; +layout(location = 7) uniform mat3 normalMatrix ; +layout(location = 9) uniform float time ; + +out vec3 normal ; +out vec4 position ; +out vec2 texpos ; + +out vec3 original_x ; +out vec3 original_z ; + +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) ; +} + +vec2 xripple( float t ) { + return vec2(t,sin(t-time)/5.0) ; +} + +vec2 dxripple( float t ) { + return vec2(1,-cos(time-t)/5.0) ; +} + +void main () { + float u = gl_TessCoord.x; + float v = gl_TessCoord.y; + + vec3 a = mix(evaluationpoint[1], evaluationpoint[0], u); + vec3 b = mix(evaluationpoint[2], evaluationpoint[3], u); + vec3 pos = mix(a, b, v); + + // Bolt down the two edges to ensure the end of the + // polygon does not show itself + if( u != 0 && u != 1 ) { + vec2 sk = skew(pos.z) ; + vec2 dsk = dskew(pos.z) ; + 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) ; + normal = - normalMatrix * normal_; // cross( p0 - p1, p0 - p2 ); + } else { + normal = - normalMatrix * vec3(0,1,0) ; + } + texpos = pos.xz / 20.0 ; + gl_Position = pjMatrix * (position = mvMatrix * vec4(pos, 1.0)); + + original_x = normalize(- normalMatrix * vec3(1,0,0)) ; + original_z = normalize(- normalMatrix * vec3(0,0,1)) ; +} |