#include "common.h"
#include "model.h"
#include "camera.h"
+#include "world.h"
#include "shaders/blit.h"
#include "shaders/blitblur.h"
#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 );
+VG_STATIC void render_water_surface( world_instance *world, camera *cam );
+VG_STATIC void render_world( world_instance *world, camera *cam );
+VG_STATIC void render_world_depth( world_instance *world, camera *cam );
#ifndef RENDER_H
#define RENDER_H
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;
widgets[3];
float shadow_spread, shadow_length;
- GLuint ubo_world_lighting,
- ubo_world;
int ready;
}
},
.shadow_spread = 0.65f,
.shadow_length = 9.50f,
-
- .ub_world_lighting =
- {
- .g_ambient_colour = { 0.09f, 0.03f, 0.07f }
- }
};
struct framebuffer
}
}
},
- {
- /*
- * 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
{
{
"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
},
/*
* 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 },
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();
}
render_init_fs_quad();
- render_init_uniform_buffers();
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
gpipeline.ready = 1;