From 251b611fef77533082165bab0b88eefa05b49fbe Mon Sep 17 00:00:00 2001 From: Connor Thomson Date: Sat, 12 Sep 2026 14:16:55 -0700 Subject: Add simple shadows --- include/files.h | 8 ++++++++ include/model.h | 2 ++ include/screen.h | 1 + include/screens/main_menu.h | 1 + include/shadow.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/ta_math.h | 7 +++++-- include/teapot.h | 1 + 7 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 include/shadow.h (limited to 'include') diff --git a/include/files.h b/include/files.h index 8c68d38..ebd57b4 100644 --- a/include/files.h +++ b/include/files.h @@ -55,4 +55,12 @@ extern unsigned char *file_model_wireframe_frag_slang_spv_start; extern unsigned char *file_model_wireframe_frag_slang_spv_end; extern unsigned int file_model_wireframe_frag_slang_spv_size; +extern unsigned char *file_shadow_vert_slang_spv_start; +extern unsigned char *file_shadow_vert_slang_spv_end; +extern unsigned int file_shadow_vert_slang_spv_size; + +extern unsigned char *file_shadow_frag_slang_spv_start; +extern unsigned char *file_shadow_frag_slang_spv_end; +extern unsigned int file_shadow_frag_slang_spv_size; + #endif // TA_FILES_H \ No newline at end of file diff --git a/include/model.h b/include/model.h index 47364ba..56a8c75 100644 --- a/include/model.h +++ b/include/model.h @@ -38,6 +38,7 @@ typedef struct ta_model_mesh { typedef struct ta_model { SDL_GPUGraphicsPipeline *pipeline; SDL_GPUGraphicsPipeline *wireframe_pipeline; + SDL_GPUGraphicsPipeline *shadow_pipeline; SDL_GPUBuffer *vertex_buffer; ta_model_mesh mesh; Uint32 vertex_count; @@ -51,6 +52,7 @@ void ta_model_free(ta_model_mesh *mesh); bool ta_model_init(ta_model *model, SDL_GPUDevice *device, const float positions[][3], size_t position_count, const unsigned int faces[][TA_MODEL_DIMENSION], size_t face_count, SDL_GPUTextureFormat color_format, SDL_GPUTextureFormat depth_format, SDL_GPUSampleCount sample_count); void ta_model_upload(ta_model *model, SDL_GPUCommandBuffer *command_buffer, SDL_GPUDevice *device); void ta_model_render(const ta_model *model, SDL_GPUCommandBuffer *command_buffer, SDL_GPURenderPass *render_pass, int window_width, int window_height); +void ta_model_render_shadow(const ta_model *model, SDL_GPUCommandBuffer *command_buffer, SDL_GPURenderPass *render_pass); void ta_model_destroy(ta_model *model, SDL_GPUDevice *device); #endif // TA_MODEL_H \ No newline at end of file diff --git a/include/screen.h b/include/screen.h index dffbf95..2d61a78 100644 --- a/include/screen.h +++ b/include/screen.h @@ -31,5 +31,6 @@ extern ta_screens ta_screen_current; void ta_screen_update(void); void ta_screen_upload(SDL_GPUCommandBuffer *command_buffer); void ta_screen_render(SDL_GPUCommandBuffer *command_buffer, SDL_GPURenderPass *render_pass); +void ta_screen_render_shadow(SDL_GPUCommandBuffer *command_buffer, SDL_GPURenderPass *render_pass); #endif // TA_SCREEN_H \ No newline at end of file diff --git a/include/screens/main_menu.h b/include/screens/main_menu.h index a49e8b0..7a449d7 100644 --- a/include/screens/main_menu.h +++ b/include/screens/main_menu.h @@ -24,5 +24,6 @@ void ta_screens_main_menu_update(void); void ta_screens_main_menu_upload(SDL_GPUCommandBuffer *command_buffer); void ta_screens_main_menu_render(SDL_GPUCommandBuffer *command_buffer, SDL_GPURenderPass *render_pass); +void ta_screens_main_menu_render_shadow(SDL_GPUCommandBuffer *command_buffer, SDL_GPURenderPass *render_pass); #endif // TA_SCREENS_MAIN_MENU_H \ No newline at end of file diff --git a/include/shadow.h b/include/shadow.h new file mode 100644 index 0000000..0087ef4 --- /dev/null +++ b/include/shadow.h @@ -0,0 +1,41 @@ +/* + * Tuxánci 2 - A first person shooter + * Copyright (C) 2025-2026 Connor Thomson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TA_SHADOW_H +#define TA_SHADOW_H + +#include "ta_sdl.h" + +#define TA_SHADOW_DIMENSION 3 +#define TA_SHADOW_MAP_SIZE 2048u +#define TA_SHADOW_FORMAT SDL_GPU_TEXTUREFORMAT_D32_FLOAT + +extern SDL_GPUTexture *ta_shadow_texture; +extern SDL_GPUSampler *ta_shadow_sampler; +extern float ta_shadow_light_direction[TA_SHADOW_DIMENSION]; +extern float ta_shadow_normal_offset; +extern float ta_shadow_minimum_bias; +extern float ta_shadow_maximum_bias; +extern float ta_shadow_strength; + +void ta_shadow_init(void); +void ta_shadow_get_light_view_projection(float *matrix); +SDL_GPURenderPass *ta_shadow_begin_render_pass(SDL_GPUCommandBuffer *command_buffer); +void ta_shadow_shutdown(void); + +#endif // TA_SHADOW_H diff --git a/include/ta_math.h b/include/ta_math.h index 4852fc2..58751ea 100644 --- a/include/ta_math.h +++ b/include/ta_math.h @@ -21,9 +21,12 @@ #include -#define PI 3.14159265358979323846 -#define CIRCLE_DEG 360.0 +#define PI 3.14159265358979323846 +#define CIRCLE_DEG 360.0 +#define TA_MATRIX_ELEMENTS 16 double ta_rad(double degrees); +void ta_matrix_identity(float *matrix); +void ta_matrix_multiply(float *result, const float *left, const float *right); #endif // TA_MATH_H \ No newline at end of file diff --git a/include/teapot.h b/include/teapot.h index 99be7a6..a1af76e 100644 --- a/include/teapot.h +++ b/include/teapot.h @@ -24,6 +24,7 @@ void ta_teapot_init(void); void ta_teapot_upload(SDL_GPUCommandBuffer *command_buffer); void ta_teapot_render(SDL_GPUCommandBuffer *command_buffer, SDL_GPURenderPass *render_pass); +void ta_teapot_render_shadow(SDL_GPUCommandBuffer *command_buffer, SDL_GPURenderPass *render_pass); void ta_teapot_shutdown(void); #endif // TA_TEAPOT_H \ No newline at end of file -- cgit v1.2.3