summaryrefslogtreecommitdiff
path: root/src/shadow.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shadow.c')
-rw-r--r--src/shadow.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/shadow.c b/src/shadow.c
index 2967674..469a3bf 100644
--- a/src/shadow.c
+++ b/src/shadow.c
@@ -28,6 +28,7 @@
SDL_GPUTexture *ta_shadow_texture;
SDL_GPUSampler *ta_shadow_sampler;
+SDL_GPUSampler *ta_shadow_depth_sampler;
float ta_shadow_light_direction[TA_SHADOW_DIMENSION] = { -0.45f, 0.75f, 0.55f };
@@ -35,6 +36,8 @@ float ta_shadow_normal_offset = 0.03f;
float ta_shadow_minimum_bias = 0.0005f;
float ta_shadow_maximum_bias = 0.003f;
float ta_shadow_strength = 1.0f;
+float ta_shadow_light_size = 0.04f;
+float ta_shadow_penumbra_scale;
static float ta_shadow_dot(const float *left, const float *right) {
return left[0] * right[0] + left[1] * right[1] + left[2] * right[2];
@@ -56,6 +59,8 @@ static void ta_shadow_normalize(float *vector) {
}
void ta_shadow_init(void) {
+ ta_shadow_penumbra_scale = ta_shadow_light_size * (TA_SHADOW_FAR - TA_SHADOW_NEAR) / (2.0f * TA_SHADOW_EXTENT);
+
SDL_GPUTextureCreateInfo texture_info = {
.type = SDL_GPU_TEXTURETYPE_2D,
.format = TA_SHADOW_FORMAT,
@@ -79,6 +84,16 @@ void ta_shadow_init(void) {
.enable_compare = true,
};
ta_shadow_sampler = ta_sdl_create_gpu_sampler(ta_gpu_device, &sampler_info);
+
+ SDL_GPUSamplerCreateInfo depth_sampler_info = {
+ .min_filter = SDL_GPU_FILTER_NEAREST,
+ .mag_filter = SDL_GPU_FILTER_NEAREST,
+ .mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST,
+ .address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
+ .address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
+ .address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
+ };
+ ta_shadow_depth_sampler = ta_sdl_create_gpu_sampler(ta_gpu_device, &depth_sampler_info);
}
void ta_shadow_get_light_view_projection(float *matrix) {
@@ -145,8 +160,10 @@ SDL_GPURenderPass *ta_shadow_begin_render_pass(SDL_GPUCommandBuffer *command_buf
}
void ta_shadow_shutdown(void) {
+ SDL_ReleaseGPUSampler(ta_gpu_device, ta_shadow_depth_sampler);
SDL_ReleaseGPUSampler(ta_gpu_device, ta_shadow_sampler);
SDL_ReleaseGPUTexture(ta_gpu_device, ta_shadow_texture);
+ ta_shadow_depth_sampler = NULL;
ta_shadow_sampler = NULL;
ta_shadow_texture = NULL;
} \ No newline at end of file