polyadvent

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

commit a9081c066f8af9aeaa6110a220d6a3bb1d900b41
parent 0ff60c40ac67f3bd0b9daa70cafa7b37328dbfdd
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 29 Oct 2018 02:14:03 -0700

progress

Diffstat:
Mdata/models/pirate-officer.blend | 0
Mdata/models/pirate-officer.ply | 20++++++++++----------
Metc/shaders/terrain.glsl | 19++++---------------
Metc/shaders/test.f.glsl | 4+---
Metc/shaders/vertex-color.glsl | 22+++++++---------------
Msrc/game.c | 10+++++-----
Msrc/render.c | 4++--
Msrc/update.c | 18+++++++++++-------
8 files changed, 40 insertions(+), 57 deletions(-)

diff --git a/data/models/pirate-officer.blend b/data/models/pirate-officer.blend Binary files differ. diff --git a/data/models/pirate-officer.ply b/data/models/pirate-officer.ply @@ -765,10 +765,10 @@ end_header -0.252000 0.107957 1.169280 -0.000000 0.000000 1.000000 0.000000 -5.667024 161 194 218 -0.389860 0.107957 1.169280 -0.000000 0.000000 1.000000 7.236743 -5.667024 161 194 218 -0.389860 -0.107957 1.169280 0.000000 -0.000000 1.000000 7.236743 5.667024 161 194 218 --0.252000 0.104278 0.855711 0.000000 0.258819 -0.965926 0.000000 2.555619 161 194 218 --0.252000 -0.104278 0.799829 0.000000 0.258819 -0.965926 0.000000 -8.778428 161 194 218 --0.467914 -0.104278 0.799829 0.000000 0.258819 -0.965926 11.334050 -8.778428 161 194 218 --0.467914 0.104278 0.855711 0.000000 0.258819 -0.965926 11.334050 2.555619 161 194 218 +-0.252000 0.104278 0.855711 0.000000 -0.258819 0.965926 0.000000 2.555619 161 194 218 +-0.467914 -0.104278 0.799829 0.000000 -0.258819 0.965926 11.334050 -8.778428 161 194 218 +-0.252000 -0.104278 0.799829 0.000000 -0.258819 0.965926 0.000000 -8.778428 161 194 218 +-0.467914 0.104278 0.855711 0.000000 -0.258819 0.965926 11.334050 2.555619 161 194 218 -0.252000 0.104278 0.855711 0.000000 0.999931 -0.011730 0.000000 -10.489870 161 194 218 -0.467914 0.104278 0.855711 0.000000 0.999931 -0.011730 11.334050 -10.489870 161 194 218 -0.389860 0.107957 1.169280 0.000000 0.999931 -0.011730 7.236743 5.971582 161 194 218 @@ -899,10 +899,10 @@ end_header 0.467914 -0.104835 0.855711 -0.000000 -0.999950 -0.009956 11.334050 -10.499500 161 194 218 0.252000 -0.107957 1.169280 0.000000 -0.999950 -0.009956 0.000000 5.961641 161 194 218 0.389860 -0.107957 1.169280 0.000000 -0.999950 -0.009956 7.236743 5.961641 161 194 218 -0.467914 0.104278 0.855711 0.000000 0.258819 -0.965926 -11.334050 2.555619 161 194 218 -0.467914 -0.104278 0.799829 0.000000 0.258819 -0.965926 -11.334050 -8.778428 161 194 218 -0.252000 -0.104278 0.799829 0.000000 0.258819 -0.965926 -0.000000 -8.778428 161 194 218 -0.252000 0.104278 0.855711 0.000000 0.258819 -0.965926 -0.000000 2.555619 161 194 218 +0.467914 0.104278 0.855711 0.000000 -0.258819 0.965926 -11.334050 2.555619 161 194 218 +0.252000 -0.104278 0.799829 0.000000 -0.258819 0.965926 -0.000000 -8.778428 161 194 218 +0.467914 -0.104278 0.799829 0.000000 -0.258819 0.965926 -11.334050 -8.778428 161 194 218 +0.252000 0.104278 0.855711 0.000000 -0.258819 0.965926 -0.000000 2.555619 161 194 218 0.467914 0.104278 0.855711 0.000000 0.999931 -0.011730 -11.334050 -10.489870 161 194 218 0.252000 0.104278 0.855711 0.000000 0.999931 -0.011730 -0.000000 -10.489870 161 194 218 0.252000 0.107957 1.169280 0.000000 0.999931 -0.011730 -0.000000 5.971582 161 194 218 @@ -1304,7 +1304,7 @@ end_header 3 745 746 747 3 747 748 745 3 749 750 751 -3 751 752 749 +3 750 749 752 3 753 754 755 3 755 756 753 3 757 758 759 @@ -1370,6 +1370,6 @@ end_header 3 880 881 878 3 880 882 881 3 883 884 885 -3 885 886 883 +3 884 883 886 3 887 888 889 3 889 890 887 diff --git a/etc/shaders/terrain.glsl b/etc/shaders/terrain.glsl @@ -25,22 +25,12 @@ vec3 standard_light(vec3 color) { vec4 v4_normal = vec4(normal , 1); vec4 trans_normal = normal_matrix * v4_normal; - float light = dot(trans_normal.xyz, normalize(light_dir)) ; - return color * light; -} - -vec3 hemispherical(vec3 color) { - vec4 v4_normal = vec4(normal , 1); - vec4 trans_normal = normal_matrix * v4_normal; - vec3 L = light_dir; vec3 N = normalize(trans_normal.xyz); - float costheta = dot(L,N); + float costheta = clamp(dot(L,N), 0.1, 1.0); - float a = 0.5 + (0.5 * costheta); - return a * light_intensity * color - + (1.0-a) * vec3(0.0, 0.0, 0.0) * color; + return color * costheta; } vec3 gamma_correct(vec3 color) { @@ -71,10 +61,9 @@ void main() 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; + // vec3 color = vec3(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_color = hemispherical(color); + v_color = standard_light(color); v_ray = camera_position - (world * v4_pos).xyz; } diff --git a/etc/shaders/test.f.glsl b/etc/shaders/test.f.glsl @@ -48,12 +48,10 @@ void main() { else color = frag; - float bias = 0.0009; float shadow_map_z = texture(shadow_map, shadow_coord.xy).z; - if (light_dir.z > 0.0 && shadow_map_z < shadow_coord.z - bias) { + if (light_dir.z > 0.0 && shadow_map_z < shadow_coord.z ) { float factor = 1.0/dot(light_dir, vec3(0.0, 0.0, 1.0)); visibility = clamp(0.2 * factor, 0.5, 1.0); - } color = color * visibility; diff --git a/etc/shaders/vertex-color.glsl b/etc/shaders/vertex-color.glsl @@ -25,26 +25,18 @@ out vec4 shadow_coord; // TODO: includes // #include "lighting.glsl" -vec3 standard_light(vec3 color) { - vec4 v4_normal = vec4(normal, 1); - vec4 trans_normal = normal_matrix * v4_normal; - float light = dot(trans_normal.xyz, normalize(light_dir)); - return color * light; -} -vec3 hemispherical(vec3 color) { - vec4 v4_normal = vec4(normal, 1); - vec4 trans_normal = normal_matrix * v4_normal; +vec3 standard_light(vec3 color) { + vec4 v4_normal = vec4(normal , 1); + vec4 trans_normal = normal_matrix * v4_normal; - vec3 L = normalize(light_dir); + vec3 L = light_dir; vec3 N = normalize(trans_normal.xyz); - float costheta = dot(L,N); + float costheta = clamp(dot(L,N), 0.1, 1.0); - float a = 0.5 + (0.5 * costheta); - return a * light_intensity * color - + (1.0-a) * vec3(0.0, 0.0, 0.0) * color; + return color * costheta; } vec3 gamma_correct(vec3 color) { @@ -58,7 +50,7 @@ void main() gl_Position = mvp * v4_pos; shadow_coord = depth_mvp * v4_pos; - v_color = hemispherical(color); + v_color = standard_light(color); // v_normal = trans_normal.xyz; v_ray = camera_position - (world * v4_pos).xyz; } diff --git a/src/game.c b/src/game.c @@ -55,13 +55,13 @@ void game_init(struct game *game, int width, int height) { .scale = 1.0 }; - int shadowmap_scale = 1.0; + static const int shadowmap_scale = 1.0; // default ortho screenspace projection - mat4_ortho(-width/2.0 * shadowmap_scale, // left - width/2.0 * shadowmap_scale, // right - -height/2.0 * shadowmap_scale, // bottom - height/2.0 * shadowmap_scale, // top + mat4_ortho(-100.0, // left + 100.0, // right + -100.0, // bottom + 100.0, // top -10000.0, // near 10000.0, // far res->proj_ortho diff --git a/src/render.c b/src/render.c @@ -242,8 +242,8 @@ void render (struct game *game, struct render_config *config) { check_gl(); } - if (config->draw_ui) - render_ui(&game->ui, view); + /* if (config->draw_ui) */ + /* render_ui(&game->ui, view); */ //player // y tho diff --git a/src/update.c b/src/update.c @@ -226,11 +226,13 @@ void resize_fbos(struct game *game, int width, int height) { // TODO: match based on some real concept of time static void day_night_cycle(float n, struct resources *res) { - float darkest = 0.25; - float val = n; + float darkest = 0.2; + float val = n*200.0; float roots = vec3_dot(res->light_dir, V3(0.0, 0.0, 1.0)); - float intensity = 1.0;//clamp(roots, darkest, 1.0); + float intensity = clamp(roots, darkest, 1.0); float light_pos[3]; + float tmp[3] +; /* float intensity = angle <= 0.5 */ /* ? clamp(roots, darkest, 1.0) */ @@ -241,11 +243,13 @@ static void day_night_cycle(float n, struct resources *res) { res->light_intensity[2] = intensity; res->light_dir[0] = 0.0; - res->light_dir[1] = sin(val); - res->light_dir[2] = cos(val); + res->light_dir[1] = -sin(val); + res->light_dir[2] = -cos(val); - /* printf("intensity %f(%f) n %f light_dir %f %f\n", roots, intensity, */ - /* n, res->light_dir[0], res->light_dir[1]); */ + vec3_normalize(res->light_dir, res->light_dir); + + printf("intensity %f(%f) n %f light_dir %f %f\n", roots, intensity, + n, res->light_dir[1], res->light_dir[2]); vec3_add(&res->player.node.mat[M_X], res->light_dir, light_pos);