commit f280b5b3936c8122383b1fa90f49db4ec8e34266 parent d48a75a2452429f1e2c1f5bd3019c603a707ff97 Author: Michael Savage <mikejsavage@gmail.com> Date: Tue May 16 03:29:35 +0300 Fix shadow rendering Diffstat:
renderer.cc | | | 5 | ++--- |
renderer.h | | | 8 | ++++---- |
shadow_map.cc | | | 15 | +++++++++------ |
diff --git a/renderer.cc b/renderer.cc @@ -301,12 +301,11 @@ Shader renderer_new_shader( ShaderConfig config ) { return INVALID_SHADER; } - const char * ubo_names[] = { "v_hot", "v_cold", "f_hot", "f_cold" }; - const u32 ubo_bindings[] = { UB_VS_HOT, UB_VS_COLD, UB_FS_HOT, UB_FS_COLD }; + const char * ubo_names[] = { "v_hot", "v_cold", "f_hot", "f_cold", "view", "model", "light_view" }; for( size_t i = 0; i < ARRAY_COUNT( ubo_names ); i++ ) { GLuint idx = glGetUniformBlockIndex( program, ubo_names[ i ] ); if( idx != GL_INVALID_INDEX ) { - glUniformBlockBinding( program, idx, ubo_bindings[ i ] ); + glUniformBlockBinding( program, idx, i ); } } diff --git a/renderer.h b/renderer.h @@ -23,6 +23,10 @@ const u32 UB_VIEW = 4; const u32 UB_MODEL = 5; const u32 UB_LIGHT_VIEW = 6; +#define RENDERER_MAX_TEXTURES 4 +#define RENDERER_MAX_TEXTURE_BUFFERS 4 +#define RENDERER_MAX_UBS 8 + const u32 INVALID_SHADER = 0; enum CullFace { @@ -54,10 +58,6 @@ struct FB { Texture texture; }; -#define RENDERER_MAX_TEXTURES 4 -#define RENDERER_MAX_TEXTURE_BUFFERS 4 -#define RENDERER_MAX_UBS 4 - struct RenderState { UB ubs[ RENDERER_MAX_UBS ] = { }; Texture textures[ RENDERER_MAX_TEXTURES ] = { }; diff --git a/shadow_map.cc b/shadow_map.cc @@ -17,6 +17,7 @@ static Mesh square; static UB ub_model; static UB ub_light_view; static UB ub_view; +static UB ub_light_pos_bias; static FB shadow_fb; static Mesh tree_mesh; @@ -79,6 +80,7 @@ extern "C" GAME_INIT( game_init ) { ub_model = renderer_new_ub(); ub_light_view = renderer_new_ub(); ub_view = renderer_new_ub(); + ub_light_pos_bias = renderer_new_ub(); { TextureConfig config; @@ -217,14 +219,15 @@ extern "C" GAME_FRAME( game_frame ) { bias += ( input->keys[ KEY_EQUALS ] - input->keys[ KEY_MINUS ] ) * 0.00001; bias = max( bias, 0.0f ); { + renderer_ub_easy( ub_light_pos_bias, light_pos, bias ); + RenderState render_state; - // render_state.shader = get_shader( SHADER_SHADOWED_VERTEX_COLOURS ); - render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); + render_state.shader = get_shader( SHADER_SHADOWED_VERTEX_COLOURS ); + render_state.ubs[ UB_VS_COLD ] = ub_light_pos_bias; render_state.ubs[ UB_MODEL ] = ub_model; - // render_state.ubs[ UB_VIEW ] = ub_view; - render_state.ubs[ UB_VS_HOT ] = ub_view; - // render_state.ubs[ UB_LIGHT_VIEW ] = ub_light_view; - // render_state.textures[ 0 ] = shadow_fb.texture; + render_state.ubs[ UB_VIEW ] = ub_view; + render_state.ubs[ UB_LIGHT_VIEW ] = ub_light_view; + render_state.textures[ 0 ] = shadow_fb.texture; // glUniform3f( shadow_un_lightpos, light_pos.x, light_pos.y, light_pos.z ); // glUniform1f( shadow_un_bias, bias );