Skip to content

Commit

Permalink
feat: improve lightmap quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan committed Mar 23, 2023
1 parent 39fa66c commit 1cfd4d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
16 changes: 6 additions & 10 deletions assets/shaders/world/pbr/lighting.gls
Expand Up @@ -50,29 +50,25 @@ vec3 calc_pbr_lighting(vec2 uv,MaterialInfo materialInfo,vec4 baseColor)
// TODO: Lightmap mode should be determined by specialization constant to avoid if-condition overhead
if(useLightmaps)
{
vec4 colLightMap = texture(u_lightMap,fs_in.vert_uv_lightmap.xy);
vec4 colDirect = texture(u_lightMap,fs_in.vert_uv_lightmap.xy);
float exposure = get_lightmap_exposure_pow();
if(is_indirect_light_map_enabled())
{
float exposure = get_lightmap_exposure_pow();
vec3 colIndirect = texture(u_lightMapIndirect,fs_in.vert_uv_lightmap.xy).rgb;

color += colIndirect *exposure *baseColor.rgb;

if(is_directional_light_map_enabled())
{
vec3 dominantDir = texture(u_lightMapDominant,fs_in.vert_uv_lightmap.xy).rgb;
dominantDir = dominantDir *2.0 -1.0;
dominantDir = normalize(dominantDir);

vec3 shade = get_point_shade(-dominantDir,materialInfo,normal,view);
color += shade *colLightMap.rgb *exposure;
vec3 shade = get_point_shade_lm(-dominantDir,materialInfo,normal,view,colDirect.rgb *exposure);
color = baseColor.rgb *(shade +colIndirect.rgb *exposure);
}
else
color += colLightMap.rgb *baseColor.rgb;

color = baseColor.rgb *((colDirect.rgb +colIndirect.rgb) *exposure);
}
else
color.rgb += baseColor.rgb *(get_lightmap_exposure_pow() *colLightMap.rgb);
color.rgb += baseColor.rgb *(exposure *colDirect.rgb);
}
}

Expand Down
18 changes: 18 additions & 0 deletions assets/shaders/world/pbr/lighting/light_shared.gls
Expand Up @@ -23,4 +23,22 @@ vec3 get_point_shade(vec3 pointToLight, MaterialInfo materialInfo, vec3 normal,
return angularInfo.NdotL * (diffuseContrib + specContrib);
}

vec3 get_point_shade_lm(vec3 pointToLight, MaterialInfo materialInfo, vec3 normal, vec3 view, vec3 diffuse)
{
AngularInfo angularInfo = get_angular_info(pointToLight, normal, view);
angularInfo.NdotL = max(angularInfo.NdotL,0.0);
angularInfo.NdotV = max(angularInfo.NdotV,0.0);

// Calculate the shading terms for the microfacet specular shading model
vec3 F = specular_reflection(materialInfo, angularInfo);
float Vis = visibility_occlusion(materialInfo, angularInfo);
float D = microfacet_distribution(materialInfo, angularInfo);

// Calculation of analytical lighting contribution
vec3 specContrib = F * Vis * D;

// Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
return angularInfo.NdotL * (diffuse + specContrib);
}

#endif
2 changes: 1 addition & 1 deletion core/shared/src/console/sh_convars.cpp
Expand Up @@ -45,7 +45,7 @@ REGISTER_ENGINE_CONCOMMAND(
},
ConVarFlags::None, "Deletes all cache files.");
REGISTER_ENGINE_CONVAR(cache_version, "", ConVarFlags::Archive, "The engine version that the cache files are associated with. If this version doesn't match the current engine version, the cache will be cleared.");
REGISTER_ENGINE_CONVAR(cache_version_target, "8", ConVarFlags::None, "If cache_version does not match this value, the cache files will be cleared and it will be set to it.");
REGISTER_ENGINE_CONVAR(cache_version_target, "9", ConVarFlags::None, "If cache_version does not match this value, the cache files will be cleared and it will be set to it.");
REGISTER_ENGINE_CONVAR(debug_profiling_enabled, "0", ConVarFlags::None, "Enables profiling timers.");
REGISTER_ENGINE_CONVAR(sh_mount_external_game_resources, "1", ConVarFlags::Archive, "If set to 1, the game will attempt to load missing resources from external games.");
REGISTER_ENGINE_CONVAR(sh_lua_remote_debugging, "0", ConVarFlags::Archive,
Expand Down

0 comments on commit 1cfd4d2

Please sign in to comment.