remove deprecated shadow blur postfx

main
Dominik Madarász 2024-09-02 16:28:42 +02:00
parent 567afc66d2
commit 7b998afc08
14 changed files with 9 additions and 682 deletions

View File

@ -213,7 +213,9 @@ if "%1"=="dpush" (
git push > NUL 2>&1 git push > NUL 2>&1
) )
) )
popd popd
git add depot
@REM if not "%2"=="noroot" ( @REM if not "%2"=="noroot" (
@REM git stash @REM git stash

View File

@ -1194,10 +1194,6 @@ typedef struct shadowmap_t {
int cascade_index; int cascade_index;
unsigned shadow_technique; unsigned shadow_technique;
float cascade_splits[4]; float cascade_splits[4];
bool blur_csm;
bool blur_vsm;
float csm_blur_scale;
float vsm_blur_scale;
bool skip_render; bool skip_render;
int lights_pushed; int lights_pushed;
handle fbo; handle fbo;
@ -1214,7 +1210,6 @@ typedef struct shadowmap_t {
unsigned shadow_technique; unsigned shadow_technique;
handle texture; handle texture;
handle texture_2d[4]; handle texture_2d[4];
handle blur_texture, blur_texture_2d;
float cascade_distances[4]; float cascade_distances[4];
} maps[MAX_LIGHTS]; } maps[MAX_LIGHTS];
handle saved_fb; handle saved_fb;

View File

@ -91,8 +91,6 @@ int main(int argc, char** argv) {
initialized = 1; initialized = 1;
sky = skybox(flag("--mie") ? 0 : SKY_DIRS[SKY_DIR], 0); sky = skybox(flag("--mie") ? 0 : SKY_DIRS[SKY_DIR], 0);
sm = shadowmap(512, 4096); sm = shadowmap(512, 4096);
// sm.blur_pcf = 1;
// sm.blur_scale
mdl = model(OBJ_MDLS[OBJ_MDL], 0); mdl = model(OBJ_MDLS[OBJ_MDL], 0);
shader_bind(mdl.program); shader_bind(mdl.program);
cubemap_sh_shader(&sky.cubemap); cubemap_sh_shader(&sky.cubemap);
@ -210,10 +208,6 @@ int main(int argc, char** argv) {
ui_separator(); ui_separator();
ui_lights(array_count(lights), lights); ui_lights(array_count(lights), lights);
ui_separator(); ui_separator();
ui_bool("CSM Blur", &sm.blur_csm);
ui_slider("CSM Blur Scale", &sm.csm_blur_scale);
ui_bool("VSM Blur", &sm.blur_vsm);
ui_slider("VSM Blur Scale", &sm.vsm_blur_scale);
ui_shadowmap(&sm); ui_shadowmap(&sm);
ui_panel_end(); ui_panel_end();
} }

2
depot

@ -1 +1 @@
Subproject commit 26a37542d2f24e639559af49c48b2d3eb4da42fb Subproject commit 132e0cc46f06576f580ea1202aea75fbf64ff13d

View File

@ -1,17 +0,0 @@
uniform sampler2D textureSource;
uniform vec2 ScaleU;
in vec2 uv;
out vec4 fragcolor;
void main() {
vec4 color = vec4(0.0);
color += texture( textureSource, uv.st + vec2( -3.0*ScaleU.x, -3.0*ScaleU.y ) ) * 0.015625;
color += texture( textureSource, uv.st + vec2( -2.0*ScaleU.x, -2.0*ScaleU.y ) )*0.09375;
color += texture( textureSource, uv.st + vec2( -1.0*ScaleU.x, -1.0*ScaleU.y ) )*0.234375;
color += texture( textureSource, uv.st + vec2( 0.0 , 0.0) )*0.3125;
color += texture( textureSource, uv.st + vec2( 1.0*ScaleU.x, 1.0*ScaleU.y ) )*0.234375;
color += texture( textureSource, uv.st + vec2( 2.0*ScaleU.x, 2.0*ScaleU.y ) )*0.09375;
color += texture( textureSource, uv.st + vec2( 3.0*ScaleU.x, -3.0*ScaleU.y ) ) * 0.015625;
fragcolor = vec4(color.xyz, 1.0);
}

View File

@ -1,23 +0,0 @@
in vec3 TexCoords;
out vec4 FragColor;
uniform samplerCube textureSource;
uniform vec2 ScaleU;
void main()
{
vec3 sampleDir = normalize(TexCoords);
vec3 right = normalize(cross(sampleDir, vec3(0.0, 1.0, 0.0)));
vec3 up = normalize(cross(right, sampleDir));
vec3 color = vec3(0.0);
float total = 0.0;
for (float x = -4.0; x <= 4.0; x += 1.0) {
for (float y = -4.0; y <= 4.0; y += 1.0) {
vec3 offset = right * ScaleU.x * x + up * ScaleU.y * y;
color += texture(textureSource, normalize(sampleDir + offset)).rgb;
total += 1.0;
}
}
FragColor = vec4(color / total, 1.0);
}

View File

@ -1,26 +0,0 @@
out vec2 uv;
void main() {
// Calculate vertex position based on gl_VertexID
vec2 positions[6] = vec2[6](
vec2(-1.0, 1.0), // Top-left
vec2( 1.0, 1.0), // Top-right
vec2( 1.0, -1.0), // Bottom-right
vec2( 1.0, -1.0), // Bottom-right (repeated)
vec2(-1.0, -1.0), // Bottom-left
vec2(-1.0, 1.0) // Top-left (repeated)
);
// Calculate UV coordinates based on gl_VertexID
vec2 texCoords[6] = vec2[6](
vec2(0.0, 1.0), // Top-left
vec2(1.0, 1.0), // Top-right
vec2(1.0, 0.0), // Bottom-right
vec2(1.0, 0.0), // Bottom-right (repeated)
vec2(0.0, 0.0), // Bottom-left
vec2(0.0, 1.0) // Top-left (repeated)
);
gl_Position = vec4(positions[gl_VertexID], 0.0, 1.0);
uv = texCoords[gl_VertexID];
}

View File

@ -1,31 +0,0 @@
out vec3 TexCoords;
uniform int face;
vec3 cubemapCoord(vec2 uv, int face) {
vec2 UV = 2.0 * uv - 1.0;
if (face == 0) return vec3(1.0, -UV.y, -UV.x); // +X
else if (face == 1) return vec3(-1.0, -UV.y, UV.x); // -X
else if (face == 2) return vec3(UV.x, 1.0, -UV.y); // +Y
else if (face == 3) return vec3(UV.x, -1.0, UV.y); // -Y
else if (face == 4) return vec3(UV.x, -UV.y, 1.0); // +Z
else return vec3(-UV.x, -UV.y, -1.0); // -Z
}
void main()
{
// Generate a fullscreen quad
vec2 positions[6] = vec2[6](
vec2(-1.0, -1.0),
vec2( 1.0, -1.0),
vec2(-1.0, 1.0),
vec2(-1.0, 1.0),
vec2( 1.0, -1.0),
vec2( 1.0, 1.0)
);
gl_Position = vec4(positions[gl_VertexID], 0.0, 1.0);
// Calculate texture coordinates for cubemap
vec2 texCoord = positions[gl_VertexID] * 0.5 + 0.5;
TexCoords = cubemapCoord(texCoord, face);
}

View File

@ -17329,10 +17329,6 @@ typedef struct shadowmap_t {
int cascade_index; int cascade_index;
unsigned shadow_technique; unsigned shadow_technique;
float cascade_splits[NUM_SHADOW_CASCADES]; float cascade_splits[NUM_SHADOW_CASCADES];
bool blur_csm;
bool blur_vsm;
float csm_blur_scale;
float vsm_blur_scale;
// signals // signals
bool skip_render; bool skip_render;
@ -17358,8 +17354,6 @@ typedef struct shadowmap_t {
unsigned shadow_technique; unsigned shadow_technique;
handle texture; handle texture;
handle texture_2d[NUM_SHADOW_CASCADES]; handle texture_2d[NUM_SHADOW_CASCADES];
handle blur_texture, blur_texture_2d;
// handle blur_fbo_cubemap, blur_texture_cubemap;
float cascade_distances[NUM_SHADOW_CASCADES]; float cascade_distances[NUM_SHADOW_CASCADES];
} maps[MAX_LIGHTS]; } maps[MAX_LIGHTS];
@ -383523,10 +383517,6 @@ shadowmap_t shadowmap(int vsm_texture_width, int csm_texture_width) { // = 512,
s.vsm_texture_width = vsm_texture_width; s.vsm_texture_width = vsm_texture_width;
s.csm_texture_width = csm_texture_width; s.csm_texture_width = csm_texture_width;
s.saved_fb = 0; s.saved_fb = 0;
s.blur_csm = false;
s.blur_vsm = false;
s.csm_blur_scale = 0.5f;
s.vsm_blur_scale = 0.75f;
s.filter_size = 8; s.filter_size = 8;
s.window_size = 10; s.window_size = 10;
#if 0 #if 0
@ -383629,16 +383619,6 @@ void shadowmap_destroy_light(shadowmap_t *s, int light_index) {
s->maps[light_index].texture_2d[i] = 0; s->maps[light_index].texture_2d[i] = 0;
} }
} }
if (s->maps[light_index].blur_texture_2d) {
glDeleteTextures(1, &s->maps[light_index].blur_texture_2d);
s->maps[light_index].blur_texture_2d = 0;
}
if (s->maps[light_index].blur_texture) {
glDeleteTextures(1, &s->maps[light_index].blur_texture);
s->maps[light_index].blur_texture = 0;
}
} }
void shadowmap_destroy(shadowmap_t *s) { void shadowmap_destroy(shadowmap_t *s) {
@ -383815,163 +383795,6 @@ static void shadowmap_light_directional(shadowmap_t *s, light_t *l, int dir, flo
model_setpass(RENDER_PASS_SHADOW_CSM); model_setpass(RENDER_PASS_SHADOW_CSM);
} }
static inline
void shadowmap_blur_csm(shadowmap_t *s, int light_index) {
if (!s->blur_csm) {
return;
}
float blur_scale = 1.999 * (1 - s->csm_blur_scale) + 0.001;
// blur_scale = 0.1f;
if (s->maps[light_index].blur_texture_2d == 0) {
// Blur texture
float borderColor[] = {1.0, 1.0, 1.0, 1.0};
glGenTextures(1, &s->maps[light_index].blur_texture_2d);
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, s->csm_texture_width, s->csm_texture_width, 0, GL_RED, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
static renderstate_t rs;
static int program = -1, vao = -1, u_scale = -1, u_source = -1;
if (program < 0) {
rs = renderstate(); {
rs.depth_test_enabled = false;
rs.depth_write_enabled = false;
rs.blend_enabled = false;
}
const char* vs = vfs_read("shaders/vs_shadow_blur.glsl");
const char* fs = vfs_read("shaders/fs_shadow_blur.glsl");
program = shader(vs, fs, "", "fragcolor", NULL);
u_scale = glGetUniformLocation(program, "ScaleU");
u_source = glGetUniformLocation(program, "textureSource");
glGenVertexArrays(1, &vao);
}
// renderstate_apply(&rs);
glViewport(0, 0, s->csm_texture_width, s->csm_texture_width);
unsigned oldprog = last_shader;
glUseProgram(program);
glBindVertexArray(vao);
glActiveTexture(GL_TEXTURE0);
// Horizontal pass
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d, 0);
glUniform2f(u_scale, 1.0f / (s->csm_texture_width * blur_scale), 0);
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
glUniform1i(u_source, 0);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
// Vertical pass
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s->maps[light_index].texture_2d[i], 0);
glUniform2f(u_scale, 0, 1.0f / (s->csm_texture_width * blur_scale));
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d);
glUniform1i(u_source, 0);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
}
glBindVertexArray(0);
glUseProgram(oldprog);
}
static inline
void shadowmap_blur_vsm(shadowmap_t *s, int light_index) {
if (!s->blur_vsm) {
return;
}
float blur_scale = 1.999 * (1 - s->vsm_blur_scale) + 0.001;
if (s->maps[light_index].blur_texture == 0) {
// Blur texture
float borderColor[] = {1.0, 1.0, 1.0, 1.0};
glGenTextures(1, &s->maps[light_index].blur_texture);
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].blur_texture);
for (int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_R32F, s->vsm_texture_width, s->vsm_texture_width, 0, GL_RED, GL_FLOAT, 0);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BORDER_COLOR, borderColor);
}
static renderstate_t rs;
static int program = -1, vao = -1, u_scale = -1, u_source = -1, u_face = -1;
if (program < 0) {
rs = renderstate(); {
rs.depth_test_enabled = false;
rs.depth_write_enabled = false;
rs.blend_enabled = false;
}
const char* vs = vfs_read("shaders/vs_shadow_blur_cubemap.glsl");
const char* fs = vfs_read("shaders/fs_shadow_blur_cubemap.glsl");
program = shader(vs, fs, "", "fragcolor", NULL);
u_scale = glGetUniformLocation(program, "ScaleU");
u_source = glGetUniformLocation(program, "textureSource");
u_face = glGetUniformLocation(program, "face");
glGenVertexArrays(1, &vao);
}
renderstate_apply(&rs);
// return;
glViewport(0, 0, s->vsm_texture_width, s->vsm_texture_width);
unsigned oldprog = last_shader;
glUseProgram(program);
glBindVertexArray(vao);
glActiveTexture(GL_TEXTURE0);
for (int face = 0; face < 6; face++) {
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, s->maps[light_index].blur_texture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 0);
glUniform2f(u_scale, 1.0f / (s->vsm_texture_width * blur_scale), 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].texture);
glUniform1i(u_source, 0);
glUniform1i(u_face, face);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, s->maps[light_index].texture, 0);
glUniform2f(u_scale, 0, 1.0f / (s->vsm_texture_width * blur_scale));
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].blur_texture);
glUniform1i(u_source, 0);
glUniform1i(u_face, face);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
}
glBindVertexArray(0);
glUseProgram(oldprog);
}
static inline static inline
bool shadowmap_step_finish(shadowmap_t *s) { bool shadowmap_step_finish(shadowmap_t *s) {
if (s->shadow_technique == SHADOW_CSM) { if (s->shadow_technique == SHADOW_CSM) {
@ -383980,9 +383803,6 @@ bool shadowmap_step_finish(shadowmap_t *s) {
s->step = 0; s->step = 0;
return false; return false;
} }
shadowmap_blur_csm(s, s->light_step);
} else {
shadowmap_blur_vsm(s, s->light_step);
} }
s->step = 0; s->step = 0;
@ -384097,17 +383917,6 @@ void shadowmap_end(shadowmap_t *s) {
s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2; s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2;
} }
} }
// Add blur textures if they exist
for (int i = 0; i < MAX_LIGHTS; i++) {
if (s->maps[i].blur_texture) {
s->vram_usage_vsm += 6 * s->vsm_texture_width * s->vsm_texture_width * 4; // GL_R32F
}
if (s->maps[i].blur_texture_2d) {
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // GL_R32F
}
}
s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm; s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm;
} }
} }

View File

@ -1698,10 +1698,6 @@ shadowmap_t shadowmap(int vsm_texture_width, int csm_texture_width) { // = 512,
s.vsm_texture_width = vsm_texture_width; s.vsm_texture_width = vsm_texture_width;
s.csm_texture_width = csm_texture_width; s.csm_texture_width = csm_texture_width;
s.saved_fb = 0; s.saved_fb = 0;
s.blur_csm = false;
s.blur_vsm = false;
s.csm_blur_scale = 0.5f;
s.vsm_blur_scale = 0.75f;
s.filter_size = 8; s.filter_size = 8;
s.window_size = 10; s.window_size = 10;
#if 0 #if 0
@ -1804,16 +1800,6 @@ void shadowmap_destroy_light(shadowmap_t *s, int light_index) {
s->maps[light_index].texture_2d[i] = 0; s->maps[light_index].texture_2d[i] = 0;
} }
} }
if (s->maps[light_index].blur_texture_2d) {
glDeleteTextures(1, &s->maps[light_index].blur_texture_2d);
s->maps[light_index].blur_texture_2d = 0;
}
if (s->maps[light_index].blur_texture) {
glDeleteTextures(1, &s->maps[light_index].blur_texture);
s->maps[light_index].blur_texture = 0;
}
} }
void shadowmap_destroy(shadowmap_t *s) { void shadowmap_destroy(shadowmap_t *s) {
@ -1990,163 +1976,6 @@ static void shadowmap_light_directional(shadowmap_t *s, light_t *l, int dir, flo
model_setpass(RENDER_PASS_SHADOW_CSM); model_setpass(RENDER_PASS_SHADOW_CSM);
} }
static inline
void shadowmap_blur_csm(shadowmap_t *s, int light_index) {
if (!s->blur_csm) {
return;
}
float blur_scale = 1.999 * (1 - s->csm_blur_scale) + 0.001;
// blur_scale = 0.1f;
if (s->maps[light_index].blur_texture_2d == 0) {
// Blur texture
float borderColor[] = {1.0, 1.0, 1.0, 1.0};
glGenTextures(1, &s->maps[light_index].blur_texture_2d);
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, s->csm_texture_width, s->csm_texture_width, 0, GL_RED, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
static renderstate_t rs;
static int program = -1, vao = -1, u_scale = -1, u_source = -1;
if (program < 0) {
rs = renderstate(); {
rs.depth_test_enabled = false;
rs.depth_write_enabled = false;
rs.blend_enabled = false;
}
const char* vs = vfs_read("shaders/vs_shadow_blur.glsl");
const char* fs = vfs_read("shaders/fs_shadow_blur.glsl");
program = shader(vs, fs, "", "fragcolor", NULL);
u_scale = glGetUniformLocation(program, "ScaleU");
u_source = glGetUniformLocation(program, "textureSource");
glGenVertexArrays(1, &vao);
}
// renderstate_apply(&rs);
glViewport(0, 0, s->csm_texture_width, s->csm_texture_width);
unsigned oldprog = last_shader;
glUseProgram(program);
glBindVertexArray(vao);
glActiveTexture(GL_TEXTURE0);
// Horizontal pass
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d, 0);
glUniform2f(u_scale, 1.0f / (s->csm_texture_width * blur_scale), 0);
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
glUniform1i(u_source, 0);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
// Vertical pass
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s->maps[light_index].texture_2d[i], 0);
glUniform2f(u_scale, 0, 1.0f / (s->csm_texture_width * blur_scale));
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d);
glUniform1i(u_source, 0);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
}
glBindVertexArray(0);
glUseProgram(oldprog);
}
static inline
void shadowmap_blur_vsm(shadowmap_t *s, int light_index) {
if (!s->blur_vsm) {
return;
}
float blur_scale = 1.999 * (1 - s->vsm_blur_scale) + 0.001;
if (s->maps[light_index].blur_texture == 0) {
// Blur texture
float borderColor[] = {1.0, 1.0, 1.0, 1.0};
glGenTextures(1, &s->maps[light_index].blur_texture);
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].blur_texture);
for (int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_R32F, s->vsm_texture_width, s->vsm_texture_width, 0, GL_RED, GL_FLOAT, 0);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BORDER_COLOR, borderColor);
}
static renderstate_t rs;
static int program = -1, vao = -1, u_scale = -1, u_source = -1, u_face = -1;
if (program < 0) {
rs = renderstate(); {
rs.depth_test_enabled = false;
rs.depth_write_enabled = false;
rs.blend_enabled = false;
}
const char* vs = vfs_read("shaders/vs_shadow_blur_cubemap.glsl");
const char* fs = vfs_read("shaders/fs_shadow_blur_cubemap.glsl");
program = shader(vs, fs, "", "fragcolor", NULL);
u_scale = glGetUniformLocation(program, "ScaleU");
u_source = glGetUniformLocation(program, "textureSource");
u_face = glGetUniformLocation(program, "face");
glGenVertexArrays(1, &vao);
}
renderstate_apply(&rs);
// return;
glViewport(0, 0, s->vsm_texture_width, s->vsm_texture_width);
unsigned oldprog = last_shader;
glUseProgram(program);
glBindVertexArray(vao);
glActiveTexture(GL_TEXTURE0);
for (int face = 0; face < 6; face++) {
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, s->maps[light_index].blur_texture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 0);
glUniform2f(u_scale, 1.0f / (s->vsm_texture_width * blur_scale), 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].texture);
glUniform1i(u_source, 0);
glUniform1i(u_face, face);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, s->maps[light_index].texture, 0);
glUniform2f(u_scale, 0, 1.0f / (s->vsm_texture_width * blur_scale));
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].blur_texture);
glUniform1i(u_source, 0);
glUniform1i(u_face, face);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
}
glBindVertexArray(0);
glUseProgram(oldprog);
}
static inline static inline
bool shadowmap_step_finish(shadowmap_t *s) { bool shadowmap_step_finish(shadowmap_t *s) {
if (s->shadow_technique == SHADOW_CSM) { if (s->shadow_technique == SHADOW_CSM) {
@ -2155,9 +1984,6 @@ bool shadowmap_step_finish(shadowmap_t *s) {
s->step = 0; s->step = 0;
return false; return false;
} }
shadowmap_blur_csm(s, s->light_step);
} else {
shadowmap_blur_vsm(s, s->light_step);
} }
s->step = 0; s->step = 0;
@ -2272,17 +2098,6 @@ void shadowmap_end(shadowmap_t *s) {
s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2; s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2;
} }
} }
// Add blur textures if they exist
for (int i = 0; i < MAX_LIGHTS; i++) {
if (s->maps[i].blur_texture) {
s->vram_usage_vsm += 6 * s->vsm_texture_width * s->vsm_texture_width * 4; // GL_R32F
}
if (s->maps[i].blur_texture_2d) {
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // GL_R32F
}
}
s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm; s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm;
} }
} }

View File

@ -361,10 +361,6 @@ typedef struct shadowmap_t {
int cascade_index; int cascade_index;
unsigned shadow_technique; unsigned shadow_technique;
float cascade_splits[NUM_SHADOW_CASCADES]; float cascade_splits[NUM_SHADOW_CASCADES];
bool blur_csm;
bool blur_vsm;
float csm_blur_scale;
float vsm_blur_scale;
// signals // signals
bool skip_render; bool skip_render;
@ -390,8 +386,6 @@ typedef struct shadowmap_t {
unsigned shadow_technique; unsigned shadow_technique;
handle texture; handle texture;
handle texture_2d[NUM_SHADOW_CASCADES]; handle texture_2d[NUM_SHADOW_CASCADES];
handle blur_texture, blur_texture_2d;
// handle blur_fbo_cubemap, blur_texture_cubemap;
float cascade_distances[NUM_SHADOW_CASCADES]; float cascade_distances[NUM_SHADOW_CASCADES];
} maps[MAX_LIGHTS]; } maps[MAX_LIGHTS];

View File

@ -18552,10 +18552,6 @@ shadowmap_t shadowmap(int vsm_texture_width, int csm_texture_width) { // = 512,
s.vsm_texture_width = vsm_texture_width; s.vsm_texture_width = vsm_texture_width;
s.csm_texture_width = csm_texture_width; s.csm_texture_width = csm_texture_width;
s.saved_fb = 0; s.saved_fb = 0;
s.blur_csm = false;
s.blur_vsm = false;
s.csm_blur_scale = 0.5f;
s.vsm_blur_scale = 0.75f;
s.filter_size = 8; s.filter_size = 8;
s.window_size = 10; s.window_size = 10;
#if 0 #if 0
@ -18658,16 +18654,6 @@ void shadowmap_destroy_light(shadowmap_t *s, int light_index) {
s->maps[light_index].texture_2d[i] = 0; s->maps[light_index].texture_2d[i] = 0;
} }
} }
if (s->maps[light_index].blur_texture_2d) {
glDeleteTextures(1, &s->maps[light_index].blur_texture_2d);
s->maps[light_index].blur_texture_2d = 0;
}
if (s->maps[light_index].blur_texture) {
glDeleteTextures(1, &s->maps[light_index].blur_texture);
s->maps[light_index].blur_texture = 0;
}
} }
void shadowmap_destroy(shadowmap_t *s) { void shadowmap_destroy(shadowmap_t *s) {
@ -18844,163 +18830,6 @@ static void shadowmap_light_directional(shadowmap_t *s, light_t *l, int dir, flo
model_setpass(RENDER_PASS_SHADOW_CSM); model_setpass(RENDER_PASS_SHADOW_CSM);
} }
static inline
void shadowmap_blur_csm(shadowmap_t *s, int light_index) {
if (!s->blur_csm) {
return;
}
float blur_scale = 1.999 * (1 - s->csm_blur_scale) + 0.001;
// blur_scale = 0.1f;
if (s->maps[light_index].blur_texture_2d == 0) {
// Blur texture
float borderColor[] = {1.0, 1.0, 1.0, 1.0};
glGenTextures(1, &s->maps[light_index].blur_texture_2d);
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, s->csm_texture_width, s->csm_texture_width, 0, GL_RED, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
static renderstate_t rs;
static int program = -1, vao = -1, u_scale = -1, u_source = -1;
if (program < 0) {
rs = renderstate(); {
rs.depth_test_enabled = false;
rs.depth_write_enabled = false;
rs.blend_enabled = false;
}
const char* vs = vfs_read("shaders/vs_shadow_blur.glsl");
const char* fs = vfs_read("shaders/fs_shadow_blur.glsl");
program = shader(vs, fs, "", "fragcolor", NULL);
u_scale = glGetUniformLocation(program, "ScaleU");
u_source = glGetUniformLocation(program, "textureSource");
glGenVertexArrays(1, &vao);
}
// renderstate_apply(&rs);
glViewport(0, 0, s->csm_texture_width, s->csm_texture_width);
unsigned oldprog = last_shader;
glUseProgram(program);
glBindVertexArray(vao);
glActiveTexture(GL_TEXTURE0);
// Horizontal pass
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d, 0);
glUniform2f(u_scale, 1.0f / (s->csm_texture_width * blur_scale), 0);
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
glUniform1i(u_source, 0);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
// Vertical pass
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s->maps[light_index].texture_2d[i], 0);
glUniform2f(u_scale, 0, 1.0f / (s->csm_texture_width * blur_scale));
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].blur_texture_2d);
glUniform1i(u_source, 0);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
}
glBindVertexArray(0);
glUseProgram(oldprog);
}
static inline
void shadowmap_blur_vsm(shadowmap_t *s, int light_index) {
if (!s->blur_vsm) {
return;
}
float blur_scale = 1.999 * (1 - s->vsm_blur_scale) + 0.001;
if (s->maps[light_index].blur_texture == 0) {
// Blur texture
float borderColor[] = {1.0, 1.0, 1.0, 1.0};
glGenTextures(1, &s->maps[light_index].blur_texture);
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].blur_texture);
for (int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_R32F, s->vsm_texture_width, s->vsm_texture_width, 0, GL_RED, GL_FLOAT, 0);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BORDER_COLOR, borderColor);
}
static renderstate_t rs;
static int program = -1, vao = -1, u_scale = -1, u_source = -1, u_face = -1;
if (program < 0) {
rs = renderstate(); {
rs.depth_test_enabled = false;
rs.depth_write_enabled = false;
rs.blend_enabled = false;
}
const char* vs = vfs_read("shaders/vs_shadow_blur_cubemap.glsl");
const char* fs = vfs_read("shaders/fs_shadow_blur_cubemap.glsl");
program = shader(vs, fs, "", "fragcolor", NULL);
u_scale = glGetUniformLocation(program, "ScaleU");
u_source = glGetUniformLocation(program, "textureSource");
u_face = glGetUniformLocation(program, "face");
glGenVertexArrays(1, &vao);
}
renderstate_apply(&rs);
// return;
glViewport(0, 0, s->vsm_texture_width, s->vsm_texture_width);
unsigned oldprog = last_shader;
glUseProgram(program);
glBindVertexArray(vao);
glActiveTexture(GL_TEXTURE0);
for (int face = 0; face < 6; face++) {
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, s->maps[light_index].blur_texture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 0);
glUniform2f(u_scale, 1.0f / (s->vsm_texture_width * blur_scale), 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].texture);
glUniform1i(u_source, 0);
glUniform1i(u_face, face);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, s->maps[light_index].texture, 0);
glUniform2f(u_scale, 0, 1.0f / (s->vsm_texture_width * blur_scale));
glBindTexture(GL_TEXTURE_CUBE_MAP, s->maps[light_index].blur_texture);
glUniform1i(u_source, 0);
glUniform1i(u_face, face);
glDrawArrays(GL_TRIANGLES, 0, 6);
profile_incstat("Render.num_drawcalls", +1);
profile_incstat("Render.num_triangles", +2);
}
glBindVertexArray(0);
glUseProgram(oldprog);
}
static inline static inline
bool shadowmap_step_finish(shadowmap_t *s) { bool shadowmap_step_finish(shadowmap_t *s) {
if (s->shadow_technique == SHADOW_CSM) { if (s->shadow_technique == SHADOW_CSM) {
@ -19009,9 +18838,6 @@ bool shadowmap_step_finish(shadowmap_t *s) {
s->step = 0; s->step = 0;
return false; return false;
} }
shadowmap_blur_csm(s, s->light_step);
} else {
shadowmap_blur_vsm(s, s->light_step);
} }
s->step = 0; s->step = 0;
@ -19126,17 +18952,6 @@ void shadowmap_end(shadowmap_t *s) {
s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2; s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2;
} }
} }
// Add blur textures if they exist
for (int i = 0; i < MAX_LIGHTS; i++) {
if (s->maps[i].blur_texture) {
s->vram_usage_vsm += 6 * s->vsm_texture_width * s->vsm_texture_width * 4; // GL_R32F
}
if (s->maps[i].blur_texture_2d) {
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // GL_R32F
}
}
s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm; s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm;
} }
} }

View File

@ -3396,10 +3396,6 @@ typedef struct shadowmap_t {
int cascade_index; int cascade_index;
unsigned shadow_technique; unsigned shadow_technique;
float cascade_splits[NUM_SHADOW_CASCADES]; float cascade_splits[NUM_SHADOW_CASCADES];
bool blur_csm;
bool blur_vsm;
float csm_blur_scale;
float vsm_blur_scale;
// signals // signals
bool skip_render; bool skip_render;
@ -3425,8 +3421,6 @@ typedef struct shadowmap_t {
unsigned shadow_technique; unsigned shadow_technique;
handle texture; handle texture;
handle texture_2d[NUM_SHADOW_CASCADES]; handle texture_2d[NUM_SHADOW_CASCADES];
handle blur_texture, blur_texture_2d;
// handle blur_fbo_cubemap, blur_texture_cubemap;
float cascade_distances[NUM_SHADOW_CASCADES]; float cascade_distances[NUM_SHADOW_CASCADES];
} maps[MAX_LIGHTS]; } maps[MAX_LIGHTS];

6
ga.bat 100644
View File

@ -0,0 +1,6 @@
@echo off
:loop
if "%~1"=="" goto :eof
git add "%~1"
shift
goto loop