medfall

A super great game engine
Log | Files | Refs

commit cdee4d20a131f8d8231256cdf9d1898f8ebf49ce
parent ebc725d507ae1ac1d8b4ee7fb38ae1b62a97c183
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Wed Aug 30 16:58:54 +0100

Blue noise dithering in the terrain renderer too

Diffstat:
make.lua | 4++--
shaders.cc | 1+
shaders/terrain.glsl | 4+++-
terrain_manager.cc | 4++++
terrain_manager.h | 1+
5 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/make.lua b/make.lua @@ -1,7 +1,7 @@ require( "scripts.gen_makefile" ) local common_objs = { "memory_arena", "log", "ggformat", "strlcpy", "strlcat", "strtonum", "profiler", "stats", "rng/well512", "breakbools" } -local game_objs = { "work_queue", "renderer", "shaders", "gl", "glad", "immediate", "text_renderer", "obj", common_objs } +local game_objs = { "work_queue", "renderer", "shaders", "gl", "glad", "immediate", "text_renderer", "obj", "blue_noise", common_objs } local game_libs = { "glfw", "lodepng", "stb_truetype", "tinyobjloader" } if OS ~= "windows" then @@ -45,7 +45,7 @@ require( "libs/squish" ) bin( "bsp", { "main", "bsp", "bsp_renderer", game_objs }, { game_libs } ) -- TODO: fix btt build -- bin( "btt", { "main", "mod_btt", "btt", "heightmap", "skybox", "lz4", game_objs }, { "stb_image", game_libs } ) -bin( "sm", { "main", "shadow_map", "blue_noise", game_objs }, { game_libs } ) +bin( "sm", { "main", "shadow_map", game_objs }, { game_libs } ) msvc_bin_ldflags( "bsp", "opengl32.lib gdi32.lib" ) gcc_bin_ldflags( "bsp", game_ldflags ) diff --git a/shaders.cc b/shaders.cc @@ -53,6 +53,7 @@ void shaders_init() { shaders[ SHADER_TERRAIN ].path = "shaders/terrain.glsl"; shaders[ SHADER_TERRAIN ].texture_uniform_names[ 0 ] = "normals"; shaders[ SHADER_TERRAIN ].texture_uniform_names[ 1 ] = "horizons"; + shaders[ SHADER_TERRAIN ].texture_uniform_names[ 2 ] = "blue_noise"; shaders[ SHADER_TERRAIN ].texture_buffer_uniform_names[ 0 ] = "point_light_origins"; shaders[ SHADER_TERRAIN ].texture_buffer_uniform_names[ 1 ] = "point_light_colours"; diff --git a/shaders/terrain.glsl b/shaders/terrain.glsl @@ -31,6 +31,7 @@ layout( std140 ) uniform sun { uniform sampler2D normals; uniform sampler2D horizons; +uniform sampler2D blue_noise; // uniform usamplerBuffer point_light_counts_and_offsets; // uniform usamplerBuffer point_light_indices; @@ -93,7 +94,8 @@ void main() { float fog_distance_bias = 100.0; float fog_t = 1.0 - exp( -fog_strength * max( ( length( v2f.view_position ) - fog_distance_bias ), 0.0 ) ); - vec3 dither_noise = alu_noise( gl_FragCoord.xy ); + vec3 dither_noise = texture( blue_noise, gl_FragCoord.xy / textureSize( blue_noise, 0 ) ).xxx; + dither_noise = ( dither_noise - vec3( 0.5 ) ) / 128.0; colour = vec4( mix( c, fog_colour, fog_t ) + dither_noise, 1.0 ); } diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -16,6 +16,8 @@ #include "profiler.h" #include "renderer.h" #include "shaders.h" +#include "blue_noise.h" +#include "obj.h" #include "libs/lodepng/lodepng.h" @@ -216,6 +218,7 @@ void terrain_init( } } + tm->blue_noise = load_png_memory( blue_noise_png, blue_noise_png_len, TEXFMT_R_U8NORM, 1, false ); tm->ub_view = renderer_new_ub(); tm->ub_sun = renderer_new_ub(); tm->point_light_origins = renderer_new_tb( TEXFMT_RGB_FLOAT ); @@ -355,6 +358,7 @@ void terrain_render( TerrainManager * tm, const m4 & V, const m4 & P, float sun_ RenderState render_state; render_state.shader = get_shader( SHADER_TERRAIN ); + render_state.textures[ 2 ] = tm->blue_noise; render_state.ubs[ UB_VIEW ] = tm->ub_view; render_state.ubs[ UB_SUN ] = tm->ub_sun; render_state.tbs[ 0 ] = tm->point_light_origins; diff --git a/terrain_manager.h b/terrain_manager.h @@ -52,6 +52,7 @@ struct TerrainManager { u32 width, height; + Texture blue_noise; UB ub_view; UB ub_sun; TB point_light_origins;