improve pbr analytical lights

main
Dominik Madarász 2024-03-20 22:49:11 +01:00
parent 2aee9c3240
commit 4fcfb2690a
2 changed files with 10 additions and 16 deletions

View File

@ -7,15 +7,15 @@
const char *skyboxes[][2] = { // reflection, env, metadata const char *skyboxes[][2] = { // reflection, env, metadata
{"hdr/mesto.hdr","hdr/mesto_Env.hdr"}, {"hdr/Tokyo_BigSight_1k.hdr","hdr/Tokyo_BigSight_Env.hdr"},
{"hdr/graffiti_shelter_4k.hdr","hdr/graffiti_shelter_Env.hdr"}, {"hdr/graffiti_shelter_4k.hdr","hdr/graffiti_shelter_Env.hdr"},
{"hdr/music_hall_01_4k.hdr","hdr/music_hall_01_Env.hdr"}, {"hdr/music_hall_01_4k.hdr","hdr/music_hall_01_Env.hdr"},
{"hdr/the_sky_is_on_fire_2k.hdr","hdr/the_sky_is_on_fire_Env.hdr"}, {"hdr/the_sky_is_on_fire_2k.hdr","hdr/the_sky_is_on_fire_Env.hdr"},
{"hdr/Tokyo_BigSight_1k.hdr","hdr/Tokyo_BigSight_Env.hdr"},
{"hdr/GCanyon_C_YumaPoint_1k.hdr","hdr/GCanyon_C_YumaPoint_Env.hdr"}, {"hdr/GCanyon_C_YumaPoint_1k.hdr","hdr/GCanyon_C_YumaPoint_Env.hdr"},
{"hdr/Factory_Catwalk_1k.hdr","hdr/Factory_Catwalk_Env.hdr"}, {"hdr/Factory_Catwalk_1k.hdr","hdr/Factory_Catwalk_Env.hdr"},
{"hdr/MonValley_G_DirtRoad_1k.hdr","hdr/MonValley_G_DirtRoad_Env.hdr"}, {"hdr/MonValley_G_DirtRoad_1k.hdr","hdr/MonValley_G_DirtRoad_Env.hdr"},
{"hdr/Shiodome_Stairs_1k.hdr","hdr/Shiodome_Stairs_Env.hdr"}, {"hdr/Shiodome_Stairs_1k.hdr","hdr/Shiodome_Stairs_Env.hdr"},
{"hdr/mesto.hdr","hdr/mesto_Env.hdr"},
}; };
int main() { int main() {
@ -73,8 +73,10 @@ int main() {
object_pivot(obj4, vec3(0,0,90)); object_pivot(obj4, vec3(0,0,90));
// create point light // create point light
scene_spawn_light(); // sun
light_t* l = scene_spawn_light(); light_t* l = scene_spawn_light();
light_type(l, LIGHT_POINT); light_type(l, LIGHT_POINT);
l->diffuse = vec3(1,0,0);
// load skybox // load skybox
scene_get_active()->skybox = skybox_pbr(skyboxes[0][0], skyboxes[0][0], skyboxes[0][1]); scene_get_active()->skybox = skybox_pbr(skyboxes[0][0], skyboxes[0][0], skyboxes[0][1]);

View File

@ -535,6 +535,7 @@ void main(void)
F0 = mix( F0, baseColor, metallic ); F0 = mix( F0, baseColor, metallic );
bool use_ibl = has_tex_skysphere; bool use_ibl = has_tex_skysphere;
// use_ibl = false;
// Add contributions from analytic lights. // Add contributions from analytic lights.
@ -569,21 +570,12 @@ void main(void)
continue; continue;
} }
// vec3 n = normalize(v_normal_ws); vec3 radiance = l.diffuse * BOOST_LIGHTING;
// float diffuse = max(dot(n, lightDir), 0.0);
// vec3 halfVec = normalize(lightDir + u_cam_dir);
// float specular = pow(max(dot(n, halfVec), 0.0), l.power);
// return (attenuation*l.ambient + diffuse*attenuation*l.diffuse + specular*attenuation*l.specular);
vec3 radiance = l.diffuse;
vec3 L = normalize( lightDir ); vec3 L = normalize( lightDir );
vec3 H = normalize( u_cam_dir + L ); vec3 H = normalize( V + L );
vec3 F = fresnel_schlick( H, u_cam_dir, F0 ); vec3 F = fresnel_schlick( H, V, F0 );
vec3 kS = F; vec3 kS = F;
vec3 kD = vec3(1.0) - kS; vec3 kD = vec3(1.0) - kS;
kD *= 1.0 - metallic; kD *= 1.0 - metallic;
@ -592,10 +584,10 @@ void main(void)
kD *= alpha; kD *= alpha;
float D = distribution_ggx( N, H, roughness ); float D = distribution_ggx( N, H, roughness );
float G = geometry_smith( N, u_cam_dir, L, roughness ); float G = geometry_smith( N, V, L, roughness );
vec3 num = D * F * G; vec3 num = D * F * G;
float denom = 4. * max( 0., dot( N, u_cam_dir ) ) * max( 0., dot( N, L ) ); float denom = 4. * max( 0., dot( N, V ) ) * max( 0., dot( N, L ) );
vec3 specular = kS * (num / max( 0.001, denom )); vec3 specular = kS * (num / max( 0.001, denom ));