pbr: add environment light modulation support
This commit is contained in:
parent
746b20eb4f
commit
aa9929e469
10 changed files with 17 additions and 7 deletions
|
@ -19,7 +19,7 @@ UNIFORM(9) sampler2D ibl_brdf_lut;
|
|||
// These either modulate their respective maps, or are used instead of them
|
||||
UNIFORM(10) vec4 diffuseRGB_metallicA;
|
||||
UNIFORM(11) vec4 ambientRGB_roughnessA;
|
||||
UNIFORM(12) float depth_scale;
|
||||
UNIFORM(12) vec4 environmentRGB_depthScale;
|
||||
|
||||
UNIFORM(13) mat4 inv_camera_transform; // only used if PBR_FEATURE_ENVIRONMENT_MAP is set
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ void main(void) {
|
|||
|
||||
vec3 color = p.mat.ambient;
|
||||
color += PBR_PointLights(pbr, light_count, light_positions, light_colors);
|
||||
color += PBR_Generic_EnvironmentLight(pbr, ibl_brdf_lut, environment_map, features_mask);
|
||||
color += PBR_Generic_EnvironmentLight(pbr, ibl_brdf_lut, environment_map, environmentRGB_depthScale.rgb, features_mask);
|
||||
PBR_Generic_MaybeTonemap(color, features_mask);
|
||||
|
||||
fragColor = vec4(color, 1);
|
||||
|
|
|
@ -12,7 +12,7 @@ void PBR_Generic_MaybeParallaxMap(
|
|||
) {
|
||||
if(PBR_FEATURE_ENABLED(PBR_FEATURE_DEPTH_MAP, features_mask)) {
|
||||
vec3 vdir = normalize(transpose(tbn) * -pos);
|
||||
uv = parallaxOcclusionMap(depth_map, depth_scale, uv, vdir);
|
||||
uv = parallaxOcclusionMap(depth_map, environmentRGB_depthScale.a, uv, vdir);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,13 @@ vec3 PBR_Generic_EnvironmentLight(
|
|||
in PBRState pbr,
|
||||
in sampler2D ibl_brdf_lut,
|
||||
in samplerCube environment_map,
|
||||
in vec3 environment_color,
|
||||
in int features_mask
|
||||
) {
|
||||
vec3 color = vec3(0);
|
||||
|
||||
if(PBR_FEATURE_ENABLED(PBR_FEATURE_ENVIRONMENT_MAP, features_mask)) {
|
||||
color = PBR_EnvironmentLight(pbr, ibl_brdf_lut, environment_map);
|
||||
color = PBR_EnvironmentLight(pbr, ibl_brdf_lut, environment_map) * environment_color;
|
||||
}
|
||||
|
||||
return color;
|
||||
|
|
|
@ -67,7 +67,7 @@ vec3 topLayer(vec3 normal, vec3 pos, vec3 bottom) {
|
|||
pbr.F0 = vec3(F0_WATER);
|
||||
|
||||
vec3 color = PBR_PointLights(pbr, light_count, light_positions, light_colors);
|
||||
color += PBR_Generic_EnvironmentLight(pbr, ibl_brdf_lut, environment_map, features_mask);
|
||||
color += PBR_Generic_EnvironmentLight(pbr, ibl_brdf_lut, environment_map, environmentRGB_depthScale.rgb, features_mask);
|
||||
|
||||
return mix(bottom, color, pbr.fresnelNV);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ vec3 bottomLayer(mat3 tbn, vec2 uv, vec3 pos) {
|
|||
|
||||
vec3 color = p.mat.ambient;
|
||||
color += PBR_PointLights(pbr, light_count, light_positions, light_colors);
|
||||
color += PBR_Generic_EnvironmentLight(pbr, ibl_brdf_lut, environment_map, features_mask);
|
||||
color += PBR_Generic_EnvironmentLight(pbr, ibl_brdf_lut, environment_map, environmentRGB_depthScale.rgb, features_mask);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
|
|
@ -246,6 +246,7 @@ static void credits_bg_setup_pbr_lighting(Camera3D *cam) {
|
|||
static void credits_bg_setup_pbr_env(Camera3D *cam, PBREnvironment *env) {
|
||||
credits_bg_setup_pbr_lighting(cam);
|
||||
glm_vec3_broadcast(1.0f, env->ambient_color);
|
||||
glm_vec3_broadcast(1.0f, env->environment_color);
|
||||
camera3d_apply_inverse_transforms(cam, env->cam_inverse_transform);
|
||||
env->environment_map = credits.env_map;
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ static void stage2_bg_setup_pbr_lighting(Camera3D *cam, int max_lights) {
|
|||
static void stage2_bg_setup_pbr_env(Camera3D *cam, int max_lights, PBREnvironment *env) {
|
||||
stage2_bg_setup_pbr_lighting(cam, max_lights);
|
||||
glm_vec3_broadcast(0.5f, env->ambient_color);
|
||||
glm_vec3_broadcast(1.0f, env->environment_color);
|
||||
camera3d_apply_inverse_transforms(cam, env->cam_inverse_transform);
|
||||
env->environment_map = stage2_draw_data->envmap;
|
||||
env->disable_tonemap = true;
|
||||
|
|
|
@ -72,6 +72,7 @@ static void stage5_bg_setup_pbr_lighting(Camera3D *cam) {
|
|||
static void stage5_bg_setup_pbr_env(Camera3D *cam, PBREnvironment *env) {
|
||||
stage5_bg_setup_pbr_lighting(cam);
|
||||
glm_vec3_broadcast(1.0f + stage5_draw_data->stairs.light_strength, env->ambient_color);
|
||||
glm_vec3_broadcast(1.0f, env->environment_color);
|
||||
env->environment_map = stage5_draw_data->env_map;
|
||||
camera3d_apply_inverse_transforms(cam, env->cam_inverse_transform);
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ static void stage6_bg_setup_pbr_lighting(Camera3D *cam) {
|
|||
static void stage6_bg_setup_pbr_env(Camera3D *cam, PBREnvironment *env) {
|
||||
stage6_bg_setup_pbr_lighting(cam);
|
||||
glm_vec3_broadcast(1.0f, env->ambient_color);
|
||||
glm_vec3_broadcast(1.0f, env->environment_color);
|
||||
env->environment_map = stage6_draw_data->envmap;
|
||||
camera3d_apply_inverse_transforms(cam, env->cam_inverse_transform);
|
||||
}
|
||||
|
|
|
@ -160,7 +160,6 @@ void pbr_set_material_uniforms(const PBRMaterial *m, const PBREnvironment *env)
|
|||
|
||||
if(m->depth_map && m->depth_scale) {
|
||||
r_uniform_sampler("depth_map", m->depth_map);
|
||||
r_uniform_float("depth_scale", m->depth_scale);
|
||||
flags |= PBR_FEATURE_DEPTH_MAP;
|
||||
}
|
||||
|
||||
|
@ -190,6 +189,11 @@ void pbr_set_material_uniforms(const PBRMaterial *m, const PBREnvironment *env)
|
|||
ambientRGB_roughnessA[3] = m->roughness_value;
|
||||
r_uniform_vec4_vec("ambientRGB_roughnessA", ambientRGB_roughnessA);
|
||||
|
||||
vec4 environmentRGB_depthScale;
|
||||
glm_vec3_copy((float*)env->environment_color, (float*)environmentRGB_depthScale);
|
||||
environmentRGB_depthScale[3] = m->depth_scale;
|
||||
r_uniform_vec4_vec("environmentRGB_depthScale", environmentRGB_depthScale);
|
||||
|
||||
r_uniform_int("features_mask", flags);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ typedef struct PBREnvironment {
|
|||
mat4 cam_inverse_transform;
|
||||
Texture *environment_map;
|
||||
vec3 ambient_color;
|
||||
vec3 environment_color;
|
||||
bool disable_tonemap;
|
||||
} PBREnvironment;
|
||||
|
||||
|
|
Loading…
Reference in a new issue