diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-07-01 17:20:53 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-07-02 18:10:14 +0200 |
commit | 75a90df8bf7f38e746e021c23248e1607931132c (patch) | |
tree | df2b4f48d5157f775c719192484188a2b0b8a04a /shaders | |
parent | 90d570822f85f70c31f80789ad6791cebd904468 (diff) |
Import and render tree models.
Trees are loaded from the new trees.blend using assimp. Tree objects are
then received from the server and rendered on the given terrain
locations.
Each chunk now holds a list of objects and coordinates, which can be
used to easily add other models as well.
Also moded the GLSL fog code to its own shader which can be linked in
different programs.
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/fog_fragment.glsl | 9 | ||||
-rw-r--r-- | shaders/terrain_fragment.glsl | 7 | ||||
-rw-r--r-- | shaders/tree_fragment.glsl | 22 | ||||
-rw-r--r-- | shaders/tree_vertex.glsl | 14 |
4 files changed, 49 insertions, 3 deletions
diff --git a/shaders/fog_fragment.glsl b/shaders/fog_fragment.glsl new file mode 100644 index 0000000..90b4591 --- /dev/null +++ b/shaders/fog_fragment.glsl @@ -0,0 +1,9 @@ +#version 120 + +void foggify(vec3 player_pos, vec3 pos) { + gl_FragColor = mix(gl_FragColor, gl_Fog.color, pow(length(player_pos - pos)/100, 5)); + if(player_pos.y < 30 - 1.7) + gl_FragColor = mix(gl_FragColor, vec4(0, .3, .8, 0), .7); +} + +/* vim: set syn=glsl: */ diff --git a/shaders/terrain_fragment.glsl b/shaders/terrain_fragment.glsl index 8b966fd..d1f5892 100644 --- a/shaders/terrain_fragment.glsl +++ b/shaders/terrain_fragment.glsl @@ -7,6 +7,8 @@ uniform sampler2D marktex; uniform vec3 selpos, player_pos; uniform bool show_sel; +void foggify(vec3 player_pos, vec3 pos); + void main() { vec3 n = normalize(normal); float diffuse = max(dot(n, light_pos), 0.5); @@ -27,9 +29,8 @@ void main() { vec2 st = vec2((pos.x + 1 - selpos.x) / 2, (pos.z + 1 - selpos.z) / 2); gl_FragColor += texture2D(marktex, st); } - gl_FragColor = mix(gl_FragColor, gl_Fog.color, pow(length(player_pos - pos)/100, 5)); - if(player_pos.y < 30 - 1.7) - gl_FragColor = mix(gl_FragColor, vec4(0, .3, .8, 0), .7); + + foggify(player_pos, pos); } /* vim: set syn=glsl: */ diff --git a/shaders/tree_fragment.glsl b/shaders/tree_fragment.glsl new file mode 100644 index 0000000..382ab4e --- /dev/null +++ b/shaders/tree_fragment.glsl @@ -0,0 +1,22 @@ +#version 120 + +uniform sampler2D tex; +uniform vec3 player_pos; +varying vec3 normal, pos; + +void foggify(vec3 player_pos, vec3 pos); + +void main() { + vec4 color = texture2D(tex, gl_TexCoord[0].st); + + if(color.a < 0.7) + discard; + + gl_FragColor = color; + float n = clamp(dot(normal, vec3(0, 0, 1)) + .5, .3, 1); + gl_FragColor.rgb *= n; + + foggify(player_pos, pos); +} + +/* vim: set syn=glsl: */ diff --git a/shaders/tree_vertex.glsl b/shaders/tree_vertex.glsl new file mode 100644 index 0000000..4c06bee --- /dev/null +++ b/shaders/tree_vertex.glsl @@ -0,0 +1,14 @@ +#version 120 + +uniform vec3 tree_pos; +varying vec3 normal, pos; + +void main() { + normal = gl_Normal; + pos = gl_Vertex.xyz + tree_pos; + + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +} + +/* vim: set syn=glsl: */ |