X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=render.h;h=f17018bb2e767006dbd6701c355a7f5e9dd5b33b;hb=9d5997f1e611b66c7220f7eb388f427032d8da79;hp=7b5b473739f7ec6c6b01083bd3448f6e73d43697;hpb=aa4c26eae2208872824e0eb5b71bc05c16d43242;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/render.h b/render.h index 7b5b473..f17018b 100644 --- a/render.h +++ b/render.h @@ -5,6 +5,7 @@ #include "common.h" #include "model.h" #include "camera.h" +#include "world.h" #include "shaders/blit.h" #include "shaders/blitblur.h" @@ -15,11 +16,12 @@ #include "shaders/vblend.h" #endif -VG_STATIC void render_water_texture( camera *cam ); -VG_STATIC void render_water_surface( camera *cam ); -VG_STATIC void render_world( camera *cam ); -VG_STATIC void shader_link_standard_ub( GLuint shader, int texture_id ); -VG_STATIC void render_world_depth( camera *cam ); +VG_STATIC void render_water_texture( world_instance *world, camera *cam, + int layer_depth ); +VG_STATIC void render_water_surface( world_instance *world, camera *cam ); +VG_STATIC void render_world( world_instance *world, camera *cam, + int layer_depth ); +VG_STATIC void render_world_depth( world_instance *world, camera *cam ); #ifndef RENDER_H #define RENDER_H @@ -35,31 +37,9 @@ VG_STATIC struct pipeline glmesh fsquad; framebuffer *fb_main, - *fb_heightmap, *fb_water_reflection, *fb_water_beneath; - /* STD140 */ - struct ub_world_lighting - { - /* v3f (padded) */ - 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; - int g_shadow_samples; - - v4f g_point_light_positions[32]; - v4f g_point_light_colours[32]; - } - ub_world_lighting; - struct light_widget { int enabled; @@ -69,8 +49,6 @@ VG_STATIC struct pipeline widgets[3]; float shadow_spread, shadow_length; - GLuint ubo_world_lighting, - ubo_world; int ready; } @@ -96,11 +74,6 @@ gpipeline = }, .shadow_spread = 0.65f, .shadow_length = 9.50f, - - .ub_world_lighting = - { - .g_ambient_colour = { 0.09f, 0.03f, 0.07f } - } }; struct framebuffer @@ -179,29 +152,6 @@ framebuffers[] = } } }, - { - /* - * A ortho projection of the world, used for shadows and ocean colouring. - * Note: it does not have a render buffer attachement because it's - * intended to be drawn to in a MAX blending mode - */ - "heightmap", - .link = &gpipeline.fb_heightmap, - .fixed_w = 1024, - .fixed_h = 1024, - - .attachments = - { - { - "depth", k_framebuffer_attachment_type_colour, - - .internalformat = GL_R32F, - .format = GL_RED, - .type = GL_FLOAT, - .attachment = GL_COLOR_ATTACHMENT0 - } - } - }, { /* * Second rendered view from the perspective of the water reflection @@ -238,8 +188,8 @@ framebuffers[] = { { "colour", k_framebuffer_attachment_type_colour, - .internalformat = GL_RGBA, - .format = GL_RGBA, + .internalformat = GL_RED, + .format = GL_RED, .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }, @@ -304,51 +254,6 @@ VG_STATIC void render_fb_bind_texture( framebuffer *fb, /* * Shaders */ -VG_STATIC void shader_link_standard_ub( GLuint shader, int texture_id ) -{ - GLuint idx = glGetUniformBlockIndex( shader, "ub_world_lighting" ); - glUniformBlockBinding( shader, idx, 0 ); - - render_fb_bind_texture( gpipeline.fb_heightmap, 0, texture_id ); - glUniform1i( glGetUniformLocation( shader, "g_world_depth" ), texture_id ); -} - -VG_STATIC void render_update_lighting_ub(void) -{ - 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; - - if( vg.quality_profile == k_quality_profile_low ) - winf->g_shadow_samples = 0; - else - winf->g_shadow_samples = 8; - - glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting ); - glBufferSubData( GL_UNIFORM_BUFFER, 0, sizeof(struct ub_world_lighting), - &gpipeline.ub_world_lighting ); -} #define FB_FORMAT_STR( E ) { E, #E }, @@ -656,21 +561,6 @@ VG_STATIC void render_init_fs_quad(void) VG_CHECK_GL_ERR(); } -VG_STATIC void render_init_uniform_buffers(void) -{ - vg_info( "[render] Allocate uniform buffer\n" ); - - glGenBuffers( 1, &gpipeline.ubo_world_lighting ); - glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting ); - glBufferData( GL_UNIFORM_BUFFER, sizeof(struct ub_world_lighting), - NULL, GL_DYNAMIC_DRAW ); - - render_update_lighting_ub(); - glBindBufferBase( GL_UNIFORM_BUFFER, 0, gpipeline.ubo_world_lighting ); - - VG_CHECK_GL_ERR(); -} - VG_STATIC void render_init(void) { shader_blit_register(); @@ -689,7 +579,6 @@ VG_STATIC void render_init(void) } render_init_fs_quad(); - render_init_uniform_buffers(); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); gpipeline.ready = 1;