diff --git a/res/sh/sh_common.h b/res/sh/sh_common.h index c2b283f2..d69b44fc 100644 --- a/res/sh/sh_common.h +++ b/res/sh/sh_common.h @@ -151,7 +151,7 @@ SH_ASSERT_ROOT_CONST(struct sh_flood_constants, 8); /* Expected to match num32B * ========================== */ #define SH_SHADE_FLAG_NONE (0 << 0) -#define SH_SHADE_FLAG_LIGHTING_ENABLED (1 << 0) +#define SH_SHADE_FLAG_DISABLE_EFFECTS (1 << 0) SH_STRUCT(sh_shade_constants { /* ---------------------------------------------------- */ diff --git a/res/sh/shade.hlsl b/res/sh/shade.hlsl index b664cc4f..8ec2901b 100644 --- a/res/sh/shade.hlsl +++ b/res/sh/shade.hlsl @@ -27,7 +27,7 @@ struct cs_input { #define SAMPLES 16 #define MARCHES 16 -#define AMBIENT float3(0, 0, 0) +#define EDGE_FALLOFF 100 float rand_angle(uint2 pos, uint ray_index) { Texture3D noise_tex = g_noise_textures[SH_BLUE_NOISE_TEX_ID]; @@ -46,7 +46,7 @@ INLINE float3 get_light_in_dir(uint2 ray_start, float2 ray_dir) Texture2D flood_tex = g_textures_uint2[g_constants.emittance_flood_tex_urid]; Texture2D emittance_tex = g_textures_float4[g_constants.emittance_tex_urid]; - float3 result = AMBIENT; + float3 result = float3(0, 0, 0); float2 at_float = ray_start; uint2 at_uint = ray_start; for (uint i = 0; i < MARCHES; ++i) { @@ -54,13 +54,17 @@ INLINE float3 get_light_in_dir(uint2 ray_start, float2 ray_dir) float2 dist_vec = at_float - (float2)flood; float dist = length(dist_vec); if (dist < 1) { - result = emittance_tex[flood].rgb; + /* Scale light by distance from edge so that offscreen-lights fade in/out rather than popping in */ + float dist_x = min(abs(g_constants.tex_width - at_float.x), at_float.x); + float dist_y = min(abs(g_constants.tex_height - at_float.y), at_float.y); + float dist_scale = min(min(dist_x, dist_y) / EDGE_FALLOFF, 1); + result = emittance_tex[flood].rgb * dist_scale; break; } else { at_float += ray_dir * dist; at_uint = round(at_float); if (at_uint.x < 0 || at_uint.x >= g_constants.tex_width || at_uint.y < 0 || at_uint.y >= g_constants.tex_height) { - /* Ambient lighting (ray hit edge of screen) */ + /* Ray hit edge of screen */ break; } } @@ -100,7 +104,7 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input) color *= albedo_tex[id]; /* Apply lighting */ - if (g_constants.flags & SH_SHADE_FLAG_LIGHTING_ENABLED) { + if (!(g_constants.flags & SH_SHADE_FLAG_DISABLE_EFFECTS)) { color.rgb *= get_light_at_pos(id); } diff --git a/res/sprite/tim.ase b/res/sprite/tim.ase index fec5c35b..ef941d27 100644 --- a/res/sprite/tim.ase +++ b/res/sprite/tim.ase @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec441d678c8163a5fed2ff71d5a88589183791064748fbda0974fa05712e06a2 -size 766 +oid sha256:6d59f850dbcee5ad401c878afd15a6e00f1cddc9df4659dc883e668716fee7e3 +size 675 diff --git a/src/config.h b/src/config.h index e68e046f..4799bac6 100644 --- a/src/config.h +++ b/src/config.h @@ -23,15 +23,15 @@ #define RESOURCES_EMBEDDED (!DEVELOPER) #define RESOURCE_RELOADING (DEVELOPER && !RESOURCES_EMBEDDED) -#define DEFAULT_CAMERA_WIDTH (10.0) +#define DEFAULT_CAMERA_WIDTH (16) #define DEFAULT_CAMERA_HEIGHT (DEFAULT_CAMERA_WIDTH / (16.0 / 9.0)) /* Rendered image size will be (camera_width * pixels_per_unit) x (camera_height * pixels_per_unit) */ -#define PIXELS_PER_UNIT 64.0 +#define PIXELS_PER_UNIT 40.0 -/* Rendered texture size + extra room for off-screen lights */ -#define RENDER_WIDTH (640 + 512) -#define RENDER_HEIGHT (360 + 512) +/* Rendered texture size + extra room for off-screen light falloff */ +#define RENDER_WIDTH (640 + 200) +#define RENDER_HEIGHT (360 + 200) /* How many ticks back in time should the user thread blend between? * = * diff --git a/src/gp.h b/src/gp.h index 15f64956..81b61f2b 100644 --- a/src/gp.h +++ b/src/gp.h @@ -108,7 +108,7 @@ struct gp_render_params { struct v2i32 render_size; struct xform world_to_render_xf; struct xform render_to_ui_xf; - b32 lighting_enabled; + b32 effects_disabled; }; struct gp_render_sig *gp_render_sig_alloc(void); diff --git a/src/gp_dx12.c b/src/gp_dx12.c index c1d5595e..2bb5e48b 100644 --- a/src/gp_dx12.c +++ b/src/gp_dx12.c @@ -3194,7 +3194,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re } /* Flood pass */ - if (flood_pipeline->success && params.lighting_enabled) { + if (flood_pipeline->success && !params.effects_disabled) { __profn("Flood pass"); __profnc_dx12(cl->cq->prof, cl->cl, "Flood pass", RGB32_F(0.5, 0.2, 0.2)); @@ -3288,8 +3288,8 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re ID3D12GraphicsCommandList_SetComputeRootSignature(cl->cl, shade_pipeline->rootsig); u32 shade_flags = SH_SHADE_FLAG_NONE; - if (params.lighting_enabled) { - shade_flags |= SH_SHADE_FLAG_LIGHTING_ENABLED; + if (params.effects_disabled) { + shade_flags |= SH_SHADE_FLAG_DISABLE_EFFECTS; } /* Set constants */ diff --git a/src/sim_step.c b/src/sim_step.c index d6893432..b44e6ddb 100644 --- a/src/sim_step.c +++ b/src/sim_step.c @@ -269,7 +269,7 @@ INTERNAL void test_spawn_entities2(struct sim_ent *parent, struct v2 pos) struct sim_ent *e = sim_ent_alloc_sync_src(parent); f32 rot = 0; - struct v2 size = V2(0.1, 0.1); + struct v2 size = V2(0.125, 0.125); struct xform xf = XFORM_TRS(.t = pos, .r = rot, .s = size); sim_ent_set_xform(e, xf); diff --git a/src/user.c b/src/user.c index c0ff2d6c..2f8c4042 100644 --- a/src/user.c +++ b/src/user.c @@ -986,12 +986,12 @@ INTERNAL void user_update(struct sys_window *window) * Update world to render xform from world to ui xform * ========================== */ - b32 lighting_enabled = 1; + b32 effects_disabled = 0; G.render_size = V2(RENDER_WIDTH, RENDER_HEIGHT); if (G.debug_camera) { G.render_size = G.ui_size; - lighting_enabled = 0; + effects_disabled = 1; G.world_to_render_xf = G.world_to_ui_xf; } else { struct xform ui_to_world_xf = xform_invert(G.world_to_ui_xf); @@ -2078,7 +2078,7 @@ INTERNAL void user_update(struct sys_window *window) params.render_size = world_resolution; params.world_to_render_xf = G.world_to_render_xf; params.render_to_ui_xf = G.render_to_ui_xf; - params.lighting_enabled = lighting_enabled; + params.effects_disabled = effects_disabled; render_texture = gp_run_render(G.render_sig, params); }