enable analytical lights for PBR shading mode

main
Dominik Madarász 2024-08-24 19:57:55 +02:00
parent fff2db7ea5
commit 9ed0c978a3
8 changed files with 28 additions and 15 deletions

View File

@ -112,7 +112,7 @@ surface_t surface() {
pbr_mat.metallic = s.metallic; pbr_mat.metallic = s.metallic;
pbr_mat.alpha = s.alpha; pbr_mat.alpha = s.alpha;
// Lo += lighting(pbr_mat); Lo += lighting(pbr_mat);
s.light_indirect = sample_colormap( map_ambient, v_texcoord ).xyz; s.light_indirect = sample_colormap( map_ambient, v_texcoord ).xyz;
vec3 diffuse_ambient; vec3 diffuse_ambient;
@ -199,6 +199,21 @@ surface_t surface() {
s.fragcolor.rgb += s.emissive; s.fragcolor.rgb += s.emissive;
s.fragcolor *= shadowing(); s.fragcolor *= shadowing();
s.fragcolor.rgb += get_rimlight(); s.fragcolor.rgb += get_rimlight();
#ifdef SHADING_PBR
{
// aces film (CC0, src: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/)
vec3 x = s.fragcolor.rgb;
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
vec3 color = clamp((x*(a*x+b))/(x*(c*x+d)+e), 0.0, 1.0);
// gamma correction
s.fragcolor.rgb = pow( color, vec3(1.0/2.2) );
}
#endif
return s; return s;
} }

View File

@ -1,5 +1,3 @@
//version 400
// original PBR shader by @seece (Public Domain). link: https://github.com/Gargaj/Foxotron/pull/12 // original PBR shader by @seece (Public Domain). link: https://github.com/Gargaj/Foxotron/pull/12
//#define textureQueryLod(t,c) vec2(0.0,0.0) // version 400 required //#define textureQueryLod(t,c) vec2(0.0,0.0) // version 400 required

View File

@ -1,5 +1,3 @@
//version 330 core
layout(location = 0) in vec3 in_pos; layout(location = 0) in vec3 in_pos;
layout(location = 1) in vec2 in_texcoord; layout(location = 1) in vec2 in_texcoord;
layout(location = 2) in vec3 in_normal; layout(location = 2) in vec3 in_normal;

View File

@ -1,5 +1,3 @@
#version 330 core
in vec3 out_worldpos; in vec3 out_worldpos;
uniform float texture_lod; uniform float texture_lod;

View File

@ -1,5 +1,3 @@
#version 330 core
in vec3 in_pos; in vec3 in_pos;
uniform mat4 mat_mvp; uniform mat4 mat_mvp;

View File

@ -386344,12 +386344,14 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f
"SHADING_PBR", "SHADING_PBR",
}; };
ASSERT(shading < countof(shading_defines));
const char *shading_define = shading_defines[shading]; const char *shading_define = shading_defines[shading];
// rebind shader // rebind shader
// @fixme: app crashes rn // @fixme: app crashes rn
// glUseProgram(0); glUseProgram(0);
// glDeleteProgram(m->program); if (m->program)
glDeleteProgram(m->program);
const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs, int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor",

View File

@ -4687,12 +4687,14 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f
"SHADING_PBR", "SHADING_PBR",
}; };
ASSERT(shading < countof(shading_defines));
const char *shading_define = shading_defines[shading]; const char *shading_define = shading_defines[shading];
// rebind shader // rebind shader
// @fixme: app crashes rn // @fixme: app crashes rn
// glUseProgram(0); glUseProgram(0);
// glDeleteProgram(m->program); if (m->program)
glDeleteProgram(m->program);
const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs, int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor",

View File

@ -21486,12 +21486,14 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f
"SHADING_PBR", "SHADING_PBR",
}; };
ASSERT(shading < countof(shading_defines));
const char *shading_define = shading_defines[shading]; const char *shading_define = shading_defines[shading];
// rebind shader // rebind shader
// @fixme: app crashes rn // @fixme: app crashes rn
// glUseProgram(0); glUseProgram(0);
// glDeleteProgram(m->program); if (m->program)
glDeleteProgram(m->program);
const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs, int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor",