From bda9501ed2f18c42c361499ec8f234f2e576ab7e Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:33:17 +1000 Subject: pass shadow texture through to pbr function --- src/new_render/render.c | 12 ++++-------- src/new_render/shadows.c | 4 ++-- src/new_render/shadows.h | 3 ++- 3 files changed, 8 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/new_render/render.c b/src/new_render/render.c index 386a356..eea9ad1 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -146,14 +146,10 @@ void Render_RenderEntities(RenderEnt* entities, size_t entity_count) { Renderer* ren = get_renderer(); RenderScene scene = ren->scene; - // TODO: -- Shadows - // f32 near_plane = 1.0, far_plane = 10.0; - // Mat4 light_projection = mat4_orthographic(-10.0, 10.0, -10.0, 10.0, near_plane, far_plane); - // Vec3 pos = vec3_negate(scene.sun.direction); - // Mat4 light_view = mat4_look_at(pos, VEC3_ZERO, VEC3_Y); - // Mat4 light_space_matrix = mat4_mult(light_view, light_projection); - // Shadow_ShadowmapExecute(ren->shadows, light_space_matrix, entities, entity_count); - PBR_Execute(ren->pbr, scene.camera, INVALID_TEX_HANDLE, entities, entity_count); + Shadow_Storage* shadow_storage = Render_GetShadowStorage(); + TextureHandle depthmap = shadow_storage->enabled ? Shadow_GetShadowMapTexture(shadow_storage) : INVALID_TEX_HANDLE; + + PBR_Execute(ren->pbr, scene.camera, depthmap, entities, entity_count); } TextureData TextureDataLoad(const char* path, bool invert_y) { diff --git a/src/new_render/shadows.c b/src/new_render/shadows.c index 758a969..df25e05 100644 --- a/src/new_render/shadows.c +++ b/src/new_render/shadows.c @@ -209,6 +209,6 @@ void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform GPU_CmdEncoder_EndRender(&shadow_encoder); // end renderpass } -Handle Shadow_GetShadowMapTexture(Shadow_Storage* storage) { - return (Handle){ .raw = storage->depth_texture.raw }; +TextureHandle Shadow_GetShadowMapTexture(Shadow_Storage* storage) { + return storage->depth_texture; } diff --git a/src/new_render/shadows.h b/src/new_render/shadows.h index 82439d4..0482d10 100644 --- a/src/new_render/shadows.h +++ b/src/new_render/shadows.h @@ -9,6 +9,7 @@ #include "render_types.h" typedef struct Shadow_Storage { + bool enabled; GPU_Renderpass* shadowmap_pass; GPU_Pipeline* shadowmap_pipeline; TextureHandle depth_texture; @@ -37,7 +38,7 @@ PUB void Shadow_Run(RenderEnt* entities, size_t entity_count); PUB void Shadow_DrawDebugQuad(); /** @brief Get the shadow texture generated from shadowmap pass */ -PUB Handle Shadow_GetShadowMapTexture(Shadow_Storage* storage); +PUB TextureHandle Shadow_GetShadowMapTexture(Shadow_Storage* storage); // --- Internal GPU_Renderpass* Shadow_RPassCreate(); // Creates the render pass -- cgit v1.2.3-70-g09d2