further improve sh calcs

main
Dominik Madarász 2024-08-28 17:39:46 +02:00
parent 5b6afd747f
commit ac0dd11cc1
4 changed files with 40 additions and 7 deletions

View File

@ -46,6 +46,9 @@ int main(int argc, char** argv) {
sky = skybox(flag("--mie") ? 0 : SKY_DIRS[SKY_DIR], 0);
env_probe = skybox(0, 0);
mdl = model(OBJ_MDLS[OBJ_MDL], 0);
shader_bind(mdl.program);
vec3 clr[9]={0};
shader_vec3v("u_coefficients_sh", 9, clr);
// rotation44(mdl.pivot, 0, 1,0,0); // @fixme: -90,1,0,0 -> should we rotate SHMs as well? compensate rotation in shader?
}
@ -82,16 +85,16 @@ int main(int argc, char** argv) {
if (follow_cam) {
probe_pos = cam.position;
}
unsigned tex_size = 128;
unsigned tex_size = 256;
cubemap_bake_begin(&env_probe.cubemap, probe_pos, tex_size, tex_size);
while (cubemap_bake_step(&env_probe.cubemap, probe_proj, probe_view)) {
skybox_render(&sky, probe_proj, probe_view);
shader_bind(mdl.program);
shader_vec3v("u_coefficients_sh", 9, sky.cubemap.sh);
shader_bind(mdl.program);
cubemap_sh_shader(0);
model_render(mdl, probe_proj, probe_view, mdl.pivot, 0);
}
cubemap_bake_end(&env_probe.cubemap, 8, 1.0f);
cubemap_bake_end(&env_probe.cubemap, 4, 1.0f);
}
ddraw_sphere(probe_pos, 0.1f);

View File

@ -383877,7 +383877,12 @@ void cubemap_sh_reset(cubemap_t *c) {
}
void cubemap_sh_shader(cubemap_t *c) {
shader_vec3v("u_coefficients_sh", 9, c->sh);
if (c) {
shader_vec3v("u_coefficients_sh", 9, c->sh);
} else {
vec3 clr[9] = {0};
shader_vec3v("u_coefficients_sh", 9, clr);
}
}
void cubemap_sh_add_light(cubemap_t *c, vec3 light, vec3 dir, float strength) {
@ -383895,6 +383900,11 @@ void cubemap_sh_add_light(cubemap_t *c, vec3 light, vec3 dir, float strength) {
}
void cubemap_sh_blend(vec3 pos, float max_dist, unsigned count, cubemap_t *probes) {
if (count == 0) {
cubemap_sh_shader(0);
return;
}
float total_weight = 0.0f;
vec3 final_sh[9] = {0};

View File

@ -2190,7 +2190,12 @@ void cubemap_sh_reset(cubemap_t *c) {
}
void cubemap_sh_shader(cubemap_t *c) {
shader_vec3v("u_coefficients_sh", 9, c->sh);
if (c) {
shader_vec3v("u_coefficients_sh", 9, c->sh);
} else {
vec3 clr[9] = {0};
shader_vec3v("u_coefficients_sh", 9, clr);
}
}
void cubemap_sh_add_light(cubemap_t *c, vec3 light, vec3 dir, float strength) {
@ -2208,6 +2213,11 @@ void cubemap_sh_add_light(cubemap_t *c, vec3 light, vec3 dir, float strength) {
}
void cubemap_sh_blend(vec3 pos, float max_dist, unsigned count, cubemap_t *probes) {
if (count == 0) {
cubemap_sh_shader(0);
return;
}
float total_weight = 0.0f;
vec3 final_sh[9] = {0};

View File

@ -18989,7 +18989,12 @@ void cubemap_sh_reset(cubemap_t *c) {
}
void cubemap_sh_shader(cubemap_t *c) {
shader_vec3v("u_coefficients_sh", 9, c->sh);
if (c) {
shader_vec3v("u_coefficients_sh", 9, c->sh);
} else {
vec3 clr[9] = {0};
shader_vec3v("u_coefficients_sh", 9, clr);
}
}
void cubemap_sh_add_light(cubemap_t *c, vec3 light, vec3 dir, float strength) {
@ -19007,6 +19012,11 @@ void cubemap_sh_add_light(cubemap_t *c, vec3 light, vec3 dir, float strength) {
}
void cubemap_sh_blend(vec3 pos, float max_dist, unsigned count, cubemap_t *probes) {
if (count == 0) {
cubemap_sh_shader(0);
return;
}
float total_weight = 0.0f;
vec3 final_sh[9] = {0};