polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 6fe6faadff7853075e85d1b044eb4c0b2f36036e
parent 93ecb2074962988698bda78eeb1a7dc87dbbda25
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 23 Sep 2018 18:11:00 -0700

refactor terrain shader

Diffstat:
Metc/shaders/test.f.glsl | 2+-
Metc/shaders/test.v.glsl | 41+++++++++++++++++++++++++----------------
2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/etc/shaders/test.f.glsl b/etc/shaders/test.f.glsl @@ -14,7 +14,7 @@ uniform bool diffuse_on; uniform mat4 normal_matrix; vec3 apply_fog(in vec3 rgb, in float distance, in vec3 ray_orig, in vec3 ray_dir) { - const float b = 0.00036; + const float b = 0.00026; const float v = 1.0; const float zs = 1.0; diff --git a/etc/shaders/test.v.glsl b/etc/shaders/test.v.glsl @@ -17,6 +17,17 @@ flat out vec3 v_color; flat out vec3 v_normal; out vec3 v_ray; +const int nlands = 6; + +const vec4 land[nlands] = vec4[]( + vec4(0.0, 0.5, 0.79, 0.0), // 0 - water + vec4(0.9176, 0.8156, 0.6588, 1.0), // 1 - sand + vec4(0.6274, 0.749, 0.156, 2.0), // 2 - grass + vec4(0.4627, 0.3333, 0.1686, 20.0), // 3 - dirt + vec4(0.5, 0.5, 0.5, 80.0), // 4 - stone + vec4(1.0, 1.0, 1.0, 380.0) // 5 - snow +); + void main() { @@ -24,22 +35,20 @@ void main() vec4 trans_normal = normal_matrix * v4_normal; vec4 v4_pos = vec4(position, 1.0); gl_Position = mvp * v4_pos; - v_light = dot(normal, normalize(light_dir)); - - // if (position.z <= 1.0) - // v_color = vec3(0.0, 0.5, 0.79); - // else if (position.z <= 2.0) - // v_color = vec3(0.9176, 0.8156, 0.6588); - // else if (position.z <= 20.0) - // v_color = vec3(0.6274, 0.749, 0.156); - // else if (position.z <= 60.0) - // v_color = vec3(0.8784, 0.8784, 0.7); - // else if (position.z <= 100.0) - // v_color = vec3(0.5, 0.5, 0.5)9 - // else - // v_color = vec3(1.0, 1.0, 1.0) * 0.9; - - v_color = vec3(0.2 + position.z*0.05, position.z*0.005, position.z*0.0001) * 0.5; + v_light = dot(normal, normalize(light_dir)) ; + + v_color = land[0].xyz; + + for (int i = 0; i < nlands-1; i++) { + v_color = + mix(v_color, + land[i+1].xyz, + smoothstep(land[i].w, land[i+1].w, position.z)); + } + + // v_color = vec3(0.2 + position.z*0.05, position.z*0.0095, position.z*0.0001) * 0.5; + + // v_color = vec3(position.z, position.z, position.z) * 0.005; v_normal = trans_normal.xyz; v_ray = camera_position - (world * v4_pos).xyz;