diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-04-11 22:06:54 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-04-11 22:06:54 +0200 |
commit | 0986cf8f33df8926dd8da67f98ed18f696141313 (patch) | |
tree | 755a9005aa595d48569d2ecc3a5f07eb28529614 /shaders | |
parent | 0a65213f05594cc6d70e79c87ec34ed9f9c03e13 (diff) |
Draw a selection marker on the terrain.
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/terrain_fragment.glsl | 18 | ||||
-rw-r--r-- | shaders/terrain_vertex.glsl | 5 |
2 files changed, 16 insertions, 7 deletions
diff --git a/shaders/terrain_fragment.glsl b/shaders/terrain_fragment.glsl index 2d02dc8..0925c6b 100644 --- a/shaders/terrain_fragment.glsl +++ b/shaders/terrain_fragment.glsl @@ -1,22 +1,32 @@ #version 120 -varying vec3 normal, light_pos; -varying float y; +varying vec3 normal, light_pos, pos; uniform sampler2D tex[3]; +uniform sampler2D marktex; +uniform vec3 selpos; +uniform bool show_sel; void main() { vec3 n = normalize(normal); float diffuse = max(dot(n, light_pos), 0.5); - float f1 = clamp((y-15.0) / 3.0, 0.0, 1.0); - float f2 = clamp((y-2) / 3.0, 0.0, 1.0); + float f1 = clamp((pos.y-15.0) / 3.0, 0.0, 1.0); + float f2 = clamp((pos.y-2) / 3.0, 0.0, 1.0); vec4 t0 = texture2D(tex[0], gl_TexCoord[0].st); vec4 t1 = texture2D(tex[1], gl_TexCoord[0].st); vec4 t2 = texture2D(tex[2], gl_TexCoord[0].st); gl_FragColor = mix(mix(t2, t0, f2), t1, f1) * diffuse; + + /* selection marker */ + if(show_sel && + pos.x >= selpos.x-1 && pos.x <= selpos.x+1 && + pos.z >= selpos.z-1 && pos.z <= selpos.z+1) { + vec2 st = vec2((pos.x + 1 - selpos.x) / 2, (pos.z + 1 - selpos.z) / 2); + gl_FragColor += texture2D(marktex, st); + } } /* vim: set syn=glsl: */ diff --git a/shaders/terrain_vertex.glsl b/shaders/terrain_vertex.glsl index e53c432..5fcd17b 100644 --- a/shaders/terrain_vertex.glsl +++ b/shaders/terrain_vertex.glsl @@ -1,12 +1,11 @@ #version 120 -varying vec3 normal, light_pos; -varying float y; +varying vec3 normal, light_pos, pos; void main() { normal = gl_Normal; light_pos = vec3(0, 1, 0); - y = gl_Vertex.y; + pos = gl_Vertex.xyz; gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; |