polyadvent

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

commit 8b6b181467911bda729d905edae458b4e1a0e7b9
parent 4ff8ef1c69872a1e856c043da2fe826cee28431b
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  4 Jul 2019 23:37:53 -0700

various tweaks

Diffstat:
Metc/shaders/lighting.glsl | 2--
Metc/shaders/pbr.glsl | 6+++++-
Metc/shaders/terrain.v.glsl | 22+++++++++++-----------
Metc/shaders/test.f.glsl | 8++++----
Msrc/ply.c | 6+-----
Msrc/scene.c | 12++++++------
Msrc/terrain.c | 4++--
7 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/etc/shaders/lighting.glsl b/etc/shaders/lighting.glsl @@ -78,8 +78,6 @@ vec3 standard_light(vec3 color, vec4 position, vec4 normal) { vec3 final = (ambient + diffuse + specular) * color; // tone mapping - // final = final / (vec3(1.0) - final * exposure); - // final = final / (vec3(1.0) + color); // final = uncharted_tonemap(final); return final; diff --git a/etc/shaders/pbr.glsl b/etc/shaders/pbr.glsl @@ -42,8 +42,9 @@ vec3 fresnel_schlick(float cos_theta, vec3 F0) vec3 pbr(vec3 albedo, vec3 V, vec3 normal) { const float ao = 12.0; const float metallic = 0.6; + const float exposure = 0.05; const float roughness = 0.6; - vec3 radiance = sun_color * light_intensity * 4.0; + vec3 radiance = sun_color * light_intensity * 2.5; // radiance += texture(skybox, vec3(0.0, 0.0, 1.0)).rgb; vec3 N = normalize(normal); vec3 L = normalize(light_dir); @@ -84,6 +85,9 @@ vec3 pbr(vec3 albedo, vec3 V, vec3 normal) { vec3 ambient = vec3(0.03) * albedo * ao; vec3 color = ambient + Lo; // color = uncharted_tonemap(color); + + // color = color / (vec3(1.0) - color * exposure); + // final = final / (vec3(1.0) + color); // color = color / (vec3(1.0) + color); return color; diff --git a/etc/shaders/terrain.v.glsl b/etc/shaders/terrain.v.glsl @@ -13,22 +13,22 @@ out shader_data { void main() { - const int nlands = 2; - - const vec4 land[nlands] = vec4[]( - vec4(0.9176, 0.8156, 0.6588, 1.0), // 1 - sand - vec4(0.4627, 0.3333, 0.1686, 20.0) // 3 - dirt - ); + 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.7, 0.7, 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 + // vec4(0.4627, 0.3333, 0.1686, 20.0) // 3 - dirt // ); + 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.7, 0.7, 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 + ); + vec3 color = land[0].xyz; for (int i = 0; i < nlands-1; i++) { color = diff --git a/etc/shaders/test.f.glsl b/etc/shaders/test.f.glsl @@ -40,10 +40,10 @@ void main() { // vec3 color = reflect_env(vertex.position); vec3 color = pbr(vertex.color, normalize(V), vertex.normal); - // if (fog_on) { - // vec3 fog = apply_fog(color, vertex.position, length(V), camera_position, V); - // color = fog; - // } + if (fog_on) { + vec3 fog = apply_fog(color, vertex.position, length(V), camera_position, V); + color = fog; + } color *= shadow_strength(v4_pos, v4_normal, vertex.shadow_coord); diff --git a/src/ply.c b/src/ply.c @@ -93,11 +93,7 @@ static int parse_header(const char **cursor, int *nverts, int *ninds) { ok = parse_element(cursor, "face", ninds); if (ok) return 1; - ok = parse_element(cursor, "face", ninds); - if (ok) return 1; - - - return ok; + return 0; } static int parse_magic(const char **cursor) { diff --git a/src/scene.c b/src/scene.c @@ -31,7 +31,6 @@ void default_scene(struct game *game) { struct entity *tower = new_entity(NULL); struct node *tnode = get_node(&tower->node_id); - struct node *pnode = get_node(&player->node_id); assert(tnode); tower->model_id = get_static_model(model_tower, NULL); @@ -54,19 +53,20 @@ void entity_test_scene(struct game *game) struct entity *player = get_player(&game->test_resources); struct terrain *terrain = &game->terrain; player->model_id = get_static_model(model_pirate_officer, NULL); - model_id proc_id; - init_model_id(&proc_id); - struct model *pmodel = new_model(&proc_id); assert(pmodel); + model_id rock_model; + init_model_id(&rock_model); + + /* model_id rock_model = get_static_model(model_tower, NULL); */ + struct model *pmodel = new_model(&rock_model); assert(pmodel); struct geometry *geom = get_geometry(&pmodel->geom_id); assert(geom); proc_sphere(geom); - pmodel->shading = SHADING_VERT_COLOR; for (int i = 0; i < terrain->size*0.2; i++) { struct entity *ent = new_entity(NULL); struct node *node = get_node(&ent->node_id); - ent->model_id = proc_id; + ent->model_id = rock_model; double x = rand_0to1() * terrain->size; double y = rand_0to1() * terrain->size; diff --git a/src/terrain.c b/src/terrain.c @@ -275,8 +275,8 @@ void update_terrain(struct terrain *terrain) { /* ts.o1 = fabs(cos(n*0.2) * 0.5); */ /* ts.o2s = fabs(cos(n+2) * 0.5); */ /* ts.o2 = fabs(sin(n*0.02) * 2); */ - ts->freq = scale * 0.05; - ts->amplitude = 50.0; + ts->freq = scale * 0.08; + ts->amplitude = 70.0; /* if (terrain->fn) */ /* destroy_terrain(terrain); */