improve shadowmap vram usage + ui_shadowmap
parent
a3b747fd46
commit
ccd9702a26
|
@ -212,14 +212,7 @@ int main(int argc, char** argv) {
|
||||||
ui_slider("CSM Blur Scale", &sm.csm_blur_scale);
|
ui_slider("CSM Blur Scale", &sm.csm_blur_scale);
|
||||||
ui_bool("VSM Blur", &sm.blur_vsm);
|
ui_bool("VSM Blur", &sm.blur_vsm);
|
||||||
ui_slider("VSM Blur Scale", &sm.vsm_blur_scale);
|
ui_slider("VSM Blur Scale", &sm.vsm_blur_scale);
|
||||||
int sm_vram = sm.vram_usage / 1024 / 1024;
|
ui_shadowmap(&sm);
|
||||||
int sm_vram_total = sm.vram_usage_total / 1024 / 1024;
|
|
||||||
int sm_vram_vsm = sm.vram_usage_vsm / 1024 / 1024;
|
|
||||||
int sm_vram_csm = sm.vram_usage_csm / 1024 / 1024;
|
|
||||||
ui_int("Vram Usage", &sm_vram);
|
|
||||||
ui_int("Vram Usage Total", &sm_vram_total);
|
|
||||||
ui_int("Vram Usage VSM", &sm_vram_vsm);
|
|
||||||
ui_int("Vram Usage CSM", &sm_vram_csm);
|
|
||||||
ui_panel_end();
|
ui_panel_end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -383431,20 +383431,24 @@ void ui_lights(unsigned num_lights, light_t *lights) {
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void shadowmap_init_common_resources(shadowmap_t *s, int vsm_texture_width, int csm_texture_width) {
|
void shadowmap_init_common_resources(shadowmap_t *s, int vsm_texture_width, int csm_texture_width) {
|
||||||
// Create a cubemap depth texture
|
// Create a cubemap depth texture for Variance Shadow Mapping (VSM)
|
||||||
glGenTextures(1, &s->depth_texture);
|
glGenTextures(1, &s->depth_texture);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, s->depth_texture);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, s->depth_texture);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, vsm_texture_width, vsm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
|
// Create a 16-bit depth component texture for each face of the cubemap
|
||||||
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT16, vsm_texture_width, vsm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unbind the cubemap texture
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||||
|
|
||||||
// Create a 2D depth texture
|
// Create a 2D depth texture for Cascaded Shadow Mapping (CSM)
|
||||||
glGenTextures(1, &s->depth_texture_2d);
|
glGenTextures(1, &s->depth_texture_2d);
|
||||||
glBindTexture(GL_TEXTURE_2D, s->depth_texture_2d);
|
glBindTexture(GL_TEXTURE_2D, s->depth_texture_2d);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, csm_texture_width, csm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
|
// Create a single 16-bit depth component texture
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, csm_texture_width, csm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
|
// Unbind the 2D texture
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383486,7 +383490,7 @@ shadowmap_init_caster_csm(shadowmap_t *s, int light_index, int texture_width) {
|
||||||
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
|
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
|
||||||
glGenTextures(1, &s->maps[light_index].texture_2d[i]);
|
glGenTextures(1, &s->maps[light_index].texture_2d[i]);
|
||||||
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
|
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, texture_width, texture_width, 0, GL_RED, GL_FLOAT, 0);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, texture_width, texture_width, 0, GL_RED, GL_HALF_FLOAT, 0);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
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_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
|
@ -384012,62 +384016,32 @@ void shadowmap_end(shadowmap_t *s) {
|
||||||
s->vram_usage_vsm = 0;
|
s->vram_usage_vsm = 0;
|
||||||
s->vram_usage_csm = 0;
|
s->vram_usage_csm = 0;
|
||||||
{
|
{
|
||||||
const int faces = 6;
|
// Common resources
|
||||||
const int cascades = NUM_SHADOW_CASCADES;
|
s->vram_usage += 6 * s->vsm_texture_width * s->vsm_texture_width * 2; // VSM depth texture (GL_DEPTH_COMPONENT16)
|
||||||
|
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 2; // CSM depth texture (GL_DEPTH_COMPONENT16)
|
||||||
// Depth textures
|
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 1;
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 8;
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 8;
|
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 1;
|
|
||||||
|
|
||||||
|
// Per-light resources
|
||||||
for (int i = 0; i < MAX_LIGHTS; i++) {
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
||||||
// VSM textures
|
if (s->maps[i].shadow_technique == SHADOW_VSM) {
|
||||||
if (s->maps[i].texture != 0) {
|
// VSM cubemap texture (GL_RG32F)
|
||||||
// Color texture (GL_RG32F)
|
s->vram_usage_vsm += 6 * s->vsm_texture_width * s->vsm_texture_width * 8;
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
} else if (s->maps[i].shadow_technique == SHADOW_CSM) {
|
||||||
}
|
// CSM textures (GL_R16F)
|
||||||
|
s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2;
|
||||||
// Color texture (GL_RG32F)
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
|
||||||
// Depth texture (GL_DEPTH_COMPONENT, assuming 8-bit depth)
|
|
||||||
|
|
||||||
// Color texture (GL_RG32F)
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
|
||||||
// Depth texture (GL_DEPTH_COMPONENT, assuming 8-bit depth)
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
|
|
||||||
|
|
||||||
// CSM textures
|
|
||||||
if (s->maps[i].texture_2d[0] != 0) {
|
|
||||||
for (int j = 0; j < cascades; j++) {
|
|
||||||
// Color texture (GL_R32F)
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < cascades; j++) {
|
// Add blur textures if they exist
|
||||||
// Color texture (GL_R32F)
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
||||||
s->vram_usage_total += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
if (s->maps[i].blur_texture) {
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// VSM blur texture (if used)
|
s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm;
|
||||||
if (s->maps[i].blur_texture != 0) {
|
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // Assuming same format as VSM color texture
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// CSM blur texture (if used)
|
|
||||||
if (s->maps[i].blur_texture_2d != 0) {
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
}
|
|
||||||
|
|
||||||
s->vram_usage_total += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384083,6 +384057,7 @@ void ui_shadowmap(shadowmap_t *s) {
|
||||||
ui_label2("Total VRAM", va("%lld KB", s->vram_usage_total / 1024));
|
ui_label2("Total VRAM", va("%lld KB", s->vram_usage_total / 1024));
|
||||||
ui_label2("VSM VRAM", va("%lld KB", s->vram_usage_vsm / 1024));
|
ui_label2("VSM VRAM", va("%lld KB", s->vram_usage_vsm / 1024));
|
||||||
ui_label2("CSM VRAM", va("%lld KB", s->vram_usage_csm / 1024));
|
ui_label2("CSM VRAM", va("%lld KB", s->vram_usage_csm / 1024));
|
||||||
|
ui_label2("Depth Texture VRAM", va("%lld KB", s->vram_usage / 1024));
|
||||||
ui_collapse_end();
|
ui_collapse_end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1614,20 +1614,24 @@ void ui_lights(unsigned num_lights, light_t *lights) {
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void shadowmap_init_common_resources(shadowmap_t *s, int vsm_texture_width, int csm_texture_width) {
|
void shadowmap_init_common_resources(shadowmap_t *s, int vsm_texture_width, int csm_texture_width) {
|
||||||
// Create a cubemap depth texture
|
// Create a cubemap depth texture for Variance Shadow Mapping (VSM)
|
||||||
glGenTextures(1, &s->depth_texture);
|
glGenTextures(1, &s->depth_texture);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, s->depth_texture);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, s->depth_texture);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, vsm_texture_width, vsm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
|
// Create a 16-bit depth component texture for each face of the cubemap
|
||||||
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT16, vsm_texture_width, vsm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unbind the cubemap texture
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||||
|
|
||||||
// Create a 2D depth texture
|
// Create a 2D depth texture for Cascaded Shadow Mapping (CSM)
|
||||||
glGenTextures(1, &s->depth_texture_2d);
|
glGenTextures(1, &s->depth_texture_2d);
|
||||||
glBindTexture(GL_TEXTURE_2D, s->depth_texture_2d);
|
glBindTexture(GL_TEXTURE_2D, s->depth_texture_2d);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, csm_texture_width, csm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
|
// Create a single 16-bit depth component texture
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, csm_texture_width, csm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
|
// Unbind the 2D texture
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1669,7 +1673,7 @@ shadowmap_init_caster_csm(shadowmap_t *s, int light_index, int texture_width) {
|
||||||
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
|
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
|
||||||
glGenTextures(1, &s->maps[light_index].texture_2d[i]);
|
glGenTextures(1, &s->maps[light_index].texture_2d[i]);
|
||||||
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
|
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, texture_width, texture_width, 0, GL_RED, GL_FLOAT, 0);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, texture_width, texture_width, 0, GL_RED, GL_HALF_FLOAT, 0);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
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_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
|
@ -2195,62 +2199,32 @@ void shadowmap_end(shadowmap_t *s) {
|
||||||
s->vram_usage_vsm = 0;
|
s->vram_usage_vsm = 0;
|
||||||
s->vram_usage_csm = 0;
|
s->vram_usage_csm = 0;
|
||||||
{
|
{
|
||||||
const int faces = 6;
|
// Common resources
|
||||||
const int cascades = NUM_SHADOW_CASCADES;
|
s->vram_usage += 6 * s->vsm_texture_width * s->vsm_texture_width * 2; // VSM depth texture (GL_DEPTH_COMPONENT16)
|
||||||
|
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 2; // CSM depth texture (GL_DEPTH_COMPONENT16)
|
||||||
// Depth textures
|
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 1;
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 8;
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 8;
|
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 1;
|
|
||||||
|
|
||||||
|
// Per-light resources
|
||||||
for (int i = 0; i < MAX_LIGHTS; i++) {
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
||||||
// VSM textures
|
if (s->maps[i].shadow_technique == SHADOW_VSM) {
|
||||||
if (s->maps[i].texture != 0) {
|
// VSM cubemap texture (GL_RG32F)
|
||||||
// Color texture (GL_RG32F)
|
s->vram_usage_vsm += 6 * s->vsm_texture_width * s->vsm_texture_width * 8;
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
} else if (s->maps[i].shadow_technique == SHADOW_CSM) {
|
||||||
}
|
// CSM textures (GL_R16F)
|
||||||
|
s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2;
|
||||||
// Color texture (GL_RG32F)
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
|
||||||
// Depth texture (GL_DEPTH_COMPONENT, assuming 8-bit depth)
|
|
||||||
|
|
||||||
// Color texture (GL_RG32F)
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
|
||||||
// Depth texture (GL_DEPTH_COMPONENT, assuming 8-bit depth)
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
|
|
||||||
|
|
||||||
// CSM textures
|
|
||||||
if (s->maps[i].texture_2d[0] != 0) {
|
|
||||||
for (int j = 0; j < cascades; j++) {
|
|
||||||
// Color texture (GL_R32F)
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < cascades; j++) {
|
// Add blur textures if they exist
|
||||||
// Color texture (GL_R32F)
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
||||||
s->vram_usage_total += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
if (s->maps[i].blur_texture) {
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// VSM blur texture (if used)
|
s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm;
|
||||||
if (s->maps[i].blur_texture != 0) {
|
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // Assuming same format as VSM color texture
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// CSM blur texture (if used)
|
|
||||||
if (s->maps[i].blur_texture_2d != 0) {
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
}
|
|
||||||
|
|
||||||
s->vram_usage_total += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2266,6 +2240,7 @@ void ui_shadowmap(shadowmap_t *s) {
|
||||||
ui_label2("Total VRAM", va("%lld KB", s->vram_usage_total / 1024));
|
ui_label2("Total VRAM", va("%lld KB", s->vram_usage_total / 1024));
|
||||||
ui_label2("VSM VRAM", va("%lld KB", s->vram_usage_vsm / 1024));
|
ui_label2("VSM VRAM", va("%lld KB", s->vram_usage_vsm / 1024));
|
||||||
ui_label2("CSM VRAM", va("%lld KB", s->vram_usage_csm / 1024));
|
ui_label2("CSM VRAM", va("%lld KB", s->vram_usage_csm / 1024));
|
||||||
|
ui_label2("Depth Texture VRAM", va("%lld KB", s->vram_usage / 1024));
|
||||||
ui_collapse_end();
|
ui_collapse_end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
83
engine/v4k.c
83
engine/v4k.c
|
@ -18468,20 +18468,24 @@ void ui_lights(unsigned num_lights, light_t *lights) {
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void shadowmap_init_common_resources(shadowmap_t *s, int vsm_texture_width, int csm_texture_width) {
|
void shadowmap_init_common_resources(shadowmap_t *s, int vsm_texture_width, int csm_texture_width) {
|
||||||
// Create a cubemap depth texture
|
// Create a cubemap depth texture for Variance Shadow Mapping (VSM)
|
||||||
glGenTextures(1, &s->depth_texture);
|
glGenTextures(1, &s->depth_texture);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, s->depth_texture);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, s->depth_texture);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, vsm_texture_width, vsm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
|
// Create a 16-bit depth component texture for each face of the cubemap
|
||||||
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT16, vsm_texture_width, vsm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unbind the cubemap texture
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||||
|
|
||||||
// Create a 2D depth texture
|
// Create a 2D depth texture for Cascaded Shadow Mapping (CSM)
|
||||||
glGenTextures(1, &s->depth_texture_2d);
|
glGenTextures(1, &s->depth_texture_2d);
|
||||||
glBindTexture(GL_TEXTURE_2D, s->depth_texture_2d);
|
glBindTexture(GL_TEXTURE_2D, s->depth_texture_2d);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, csm_texture_width, csm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
|
// Create a single 16-bit depth component texture
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, csm_texture_width, csm_texture_width, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
|
// Unbind the 2D texture
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18523,7 +18527,7 @@ shadowmap_init_caster_csm(shadowmap_t *s, int light_index, int texture_width) {
|
||||||
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
|
for (int i = 0; i < NUM_SHADOW_CASCADES; i++) {
|
||||||
glGenTextures(1, &s->maps[light_index].texture_2d[i]);
|
glGenTextures(1, &s->maps[light_index].texture_2d[i]);
|
||||||
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
|
glBindTexture(GL_TEXTURE_2D, s->maps[light_index].texture_2d[i]);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, texture_width, texture_width, 0, GL_RED, GL_FLOAT, 0);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, texture_width, texture_width, 0, GL_RED, GL_HALF_FLOAT, 0);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
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_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
|
@ -19049,62 +19053,32 @@ void shadowmap_end(shadowmap_t *s) {
|
||||||
s->vram_usage_vsm = 0;
|
s->vram_usage_vsm = 0;
|
||||||
s->vram_usage_csm = 0;
|
s->vram_usage_csm = 0;
|
||||||
{
|
{
|
||||||
const int faces = 6;
|
// Common resources
|
||||||
const int cascades = NUM_SHADOW_CASCADES;
|
s->vram_usage += 6 * s->vsm_texture_width * s->vsm_texture_width * 2; // VSM depth texture (GL_DEPTH_COMPONENT16)
|
||||||
|
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 2; // CSM depth texture (GL_DEPTH_COMPONENT16)
|
||||||
// Depth textures
|
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 1;
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 8;
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 8;
|
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 1;
|
|
||||||
|
|
||||||
|
// Per-light resources
|
||||||
for (int i = 0; i < MAX_LIGHTS; i++) {
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
||||||
// VSM textures
|
if (s->maps[i].shadow_technique == SHADOW_VSM) {
|
||||||
if (s->maps[i].texture != 0) {
|
// VSM cubemap texture (GL_RG32F)
|
||||||
// Color texture (GL_RG32F)
|
s->vram_usage_vsm += 6 * s->vsm_texture_width * s->vsm_texture_width * 8;
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
} else if (s->maps[i].shadow_technique == SHADOW_CSM) {
|
||||||
}
|
// CSM textures (GL_R16F)
|
||||||
|
s->vram_usage_csm += NUM_SHADOW_CASCADES * s->csm_texture_width * s->csm_texture_width * 2;
|
||||||
// Color texture (GL_RG32F)
|
|
||||||
s->vram_usage_total += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
|
||||||
// Depth texture (GL_DEPTH_COMPONENT, assuming 8-bit depth)
|
|
||||||
|
|
||||||
// Color texture (GL_RG32F)
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // 8 bytes per pixel (2 * 32-bit float)
|
|
||||||
// Depth texture (GL_DEPTH_COMPONENT, assuming 8-bit depth)
|
|
||||||
s->vram_usage_vsm += s->vsm_texture_width * s->vsm_texture_width * faces * 1;
|
|
||||||
|
|
||||||
|
|
||||||
// CSM textures
|
|
||||||
if (s->maps[i].texture_2d[0] != 0) {
|
|
||||||
for (int j = 0; j < cascades; j++) {
|
|
||||||
// Color texture (GL_R32F)
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < cascades; j++) {
|
// Add blur textures if they exist
|
||||||
// Color texture (GL_R32F)
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
||||||
s->vram_usage_total += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
if (s->maps[i].blur_texture) {
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // 4 bytes per pixel (1 * 32-bit float)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// VSM blur texture (if used)
|
s->vram_usage_total = s->vram_usage + s->vram_usage_vsm + s->vram_usage_csm;
|
||||||
if (s->maps[i].blur_texture != 0) {
|
|
||||||
s->vram_usage += s->vsm_texture_width * s->vsm_texture_width * faces * 8; // Assuming same format as VSM color texture
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// CSM blur texture (if used)
|
|
||||||
if (s->maps[i].blur_texture_2d != 0) {
|
|
||||||
s->vram_usage += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
}
|
|
||||||
|
|
||||||
s->vram_usage_total += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
s->vram_usage_csm += s->csm_texture_width * s->csm_texture_width * 4; // Assuming same format as CSM color texture
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19120,6 +19094,7 @@ void ui_shadowmap(shadowmap_t *s) {
|
||||||
ui_label2("Total VRAM", va("%lld KB", s->vram_usage_total / 1024));
|
ui_label2("Total VRAM", va("%lld KB", s->vram_usage_total / 1024));
|
||||||
ui_label2("VSM VRAM", va("%lld KB", s->vram_usage_vsm / 1024));
|
ui_label2("VSM VRAM", va("%lld KB", s->vram_usage_vsm / 1024));
|
||||||
ui_label2("CSM VRAM", va("%lld KB", s->vram_usage_csm / 1024));
|
ui_label2("CSM VRAM", va("%lld KB", s->vram_usage_csm / 1024));
|
||||||
|
ui_label2("Depth Texture VRAM", va("%lld KB", s->vram_usage / 1024));
|
||||||
ui_collapse_end();
|
ui_collapse_end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue