X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=render.h;h=aa738425422d0365720b881ee6272ab7e01805a2;hb=168eb5c363f510d60703498e01ffcdb52bf9fd07;hp=8285317aaf5106f757979b2ca70600e753efecc0;hpb=ecc4dfbfb3adf91d2dfc03ba0ec9a821fcc2390c;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/render.h b/render.h index 8285317..aa73842 100644 --- a/render.h +++ b/render.h @@ -16,21 +16,61 @@ static struct pipeline struct ub_world_lighting { /* v3f (padded) */ - v4f g_directional, - g_sun_colour, - g_shadow_colour; + v4f g_light_colours[3], + g_light_directions[3], + g_ambient_colour; v4f g_water_plane, g_depth_bounds; + float g_water_fog; + int g_light_count; + int g_light_preview; } ub_world_lighting; + struct light_widget + { + int enabled; + v2f dir; + v3f colour; + } + widgets[3]; + + float shadow_spread, shadow_length; + GLuint fb_depthmap, rgb_depthmap; GLuint ubo_world_lighting, ubo_world; } -gpipeline; +gpipeline = +{ + .widgets = + { + { + .enabled = 1, + .colour = { 1.36f, 1.35f, 1.01f }, + .dir = { 0.63f, -0.08f } + }, + { + .enabled = 1, + .colour = { 0.33f, 0.56f, 0.64f }, + .dir = { -2.60f, -0.13f } + }, + { + .enabled = 1, + .colour = { 0.05f, 0.05f, 0.23f }, + .dir = { 2.60f, -0.84f } + } + }, + .shadow_spread = 0.65f, + .shadow_length = 9.50f, + + .ub_world_lighting = + { + .g_ambient_colour = { 0.09f, 0.03f, 0.07f } + } +}; static void render_water_texture( m4x3f camera ); static void render_water_surface( m4x4f pv, m4x3f camera ); @@ -84,8 +124,32 @@ static void shader_link_standard_ub( GLuint shader, int texture_id ) static void render_update_lighting_ub(void) { - glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting ); + struct ub_world_lighting *winf = &gpipeline.ub_world_lighting; + int c = 0; + for( int i=0; i<3; i++ ) + { + struct light_widget *lw = &gpipeline.widgets[i]; + + if( lw->enabled ) + { + float pitch = lw->dir[0], + yaw = lw->dir[1], + xz = cosf( pitch ); + + v3_copy( (v3f){ xz*cosf(yaw), sinf(pitch), xz*sinf(yaw) }, + winf->g_light_directions[c] ); + v3_copy( lw->colour, winf->g_light_colours[c] ); + + c ++; + } + } + + winf->g_light_count = c; + winf->g_light_directions[0][3] = gpipeline.shadow_length; + winf->g_light_colours[0][3] = gpipeline.shadow_spread; + + glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting ); glBufferSubData( GL_UNIFORM_BUFFER, 0, sizeof(struct ub_world_lighting), &gpipeline.ub_world_lighting ); }