-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gate diffuse and specular transmission behind shader defs #11627
Changes from 4 commits
bfaa64d
33851b7
83a6324
1a2650e
6806650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ fn prepare_world_normal( | |
) -> vec3<f32> { | ||
var output: vec3<f32> = world_normal; | ||
#ifndef VERTEX_TANGENTS | ||
#ifndef STANDARDMATERIAL_NORMAL_MAP | ||
#ifndef STANDARD_MATERIAL_NORMAL_MAP | ||
// NOTE: When NOT using normal-mapping, if looking at the back face of a double-sided | ||
// material, the normal needs to be inverted. This is a branchless version of that. | ||
output = (f32(!double_sided || is_front) * 2.0 - 1.0) * output; | ||
|
@@ -65,7 +65,7 @@ fn apply_normal_mapping( | |
double_sided: bool, | ||
is_front: bool, | ||
#ifdef VERTEX_TANGENTS | ||
#ifdef STANDARDMATERIAL_NORMAL_MAP | ||
#ifdef STANDARD_MATERIAL_NORMAL_MAP | ||
world_tangent: vec4<f32>, | ||
#endif | ||
#endif | ||
|
@@ -83,7 +83,7 @@ fn apply_normal_mapping( | |
var N: vec3<f32> = world_normal; | ||
|
||
#ifdef VERTEX_TANGENTS | ||
#ifdef STANDARDMATERIAL_NORMAL_MAP | ||
#ifdef STANDARD_MATERIAL_NORMAL_MAP | ||
// NOTE: The mikktspace method of normal mapping explicitly requires that these NOT be | ||
// normalized nor any Gram-Schmidt applied to ensure the vertex normal is orthogonal to the | ||
// vertex tangent! Do not change this code unless you really know what you are doing. | ||
|
@@ -95,7 +95,7 @@ fn apply_normal_mapping( | |
|
||
#ifdef VERTEX_TANGENTS | ||
#ifdef VERTEX_UVS | ||
#ifdef STANDARDMATERIAL_NORMAL_MAP | ||
#ifdef STANDARD_MATERIAL_NORMAL_MAP | ||
// Nt is the tangent-space normal. | ||
var Nt = textureSampleBias(pbr_bindings::normal_map_texture, pbr_bindings::normal_map_sampler, uv, mip_bias).rgb; | ||
if (standard_material_flags & pbr_types::STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP) != 0u { | ||
|
@@ -213,6 +213,7 @@ fn apply_pbr_lighting( | |
let light_contrib = lighting::point_light(in.world_position.xyz, light_id, roughness, NdotV, in.N, in.V, R, F0, f_ab, diffuse_color); | ||
direct_light += light_contrib * shadow; | ||
|
||
#ifdef STANDARD_MATERIAL_DIFFUSE_TRANSMISSION | ||
if diffuse_transmission > 0.0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the shader def being present should mean it's > 0.0, could we remove the if from the shader? (same for the others) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, we could, but with the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how much that really matters. I suspect the overhead of the if statement would be worse than any potential extra work on average. It's not a big deal either way, but it's probably worth removing still. |
||
// NOTE: We use the diffuse transmissive color, the second Lambertian lobe's calculated | ||
// world position, inverted normal and view vectors, and the following simplified | ||
|
@@ -231,6 +232,7 @@ fn apply_pbr_lighting( | |
let light_contrib = lighting::point_light(diffuse_transmissive_lobe_world_position.xyz, light_id, 1.0, 1.0, -in.N, -in.V, vec3<f32>(0.0), vec3<f32>(0.0), vec2<f32>(0.1), diffuse_transmissive_color); | ||
transmitted_light += light_contrib * transmitted_shadow; | ||
} | ||
#endif | ||
} | ||
|
||
// Spot lights (direct) | ||
|
@@ -245,6 +247,7 @@ fn apply_pbr_lighting( | |
let light_contrib = lighting::spot_light(in.world_position.xyz, light_id, roughness, NdotV, in.N, in.V, R, F0, f_ab, diffuse_color); | ||
direct_light += light_contrib * shadow; | ||
|
||
#ifdef STANDARD_MATERIAL_DIFFUSE_TRANSMISSION | ||
if diffuse_transmission > 0.0 { | ||
// NOTE: We use the diffuse transmissive color, the second Lambertian lobe's calculated | ||
// world position, inverted normal and view vectors, and the following simplified | ||
|
@@ -263,6 +266,7 @@ fn apply_pbr_lighting( | |
let light_contrib = lighting::spot_light(diffuse_transmissive_lobe_world_position.xyz, light_id, 1.0, 1.0, -in.N, -in.V, vec3<f32>(0.0), vec3<f32>(0.0), vec2<f32>(0.1), diffuse_transmissive_color); | ||
transmitted_light += light_contrib * transmitted_shadow; | ||
} | ||
#endif | ||
} | ||
|
||
// directional lights (direct) | ||
|
@@ -286,6 +290,7 @@ fn apply_pbr_lighting( | |
#endif | ||
direct_light += light_contrib * shadow; | ||
|
||
#ifdef STANDARD_MATERIAL_DIFFUSE_TRANSMISSION | ||
if diffuse_transmission > 0.0 { | ||
// NOTE: We use the diffuse transmissive color, the second Lambertian lobe's calculated | ||
// world position, inverted normal and view vectors, and the following simplified | ||
|
@@ -304,11 +309,13 @@ fn apply_pbr_lighting( | |
let light_contrib = lighting::directional_light(i, 1.0, 1.0, -in.N, -in.V, vec3<f32>(0.0), vec3<f32>(0.0), vec2<f32>(0.1), diffuse_transmissive_color); | ||
transmitted_light += light_contrib * transmitted_shadow; | ||
} | ||
#endif | ||
} | ||
|
||
// Ambient light (indirect) | ||
var indirect_light = ambient::ambient_light(in.world_position, in.N, in.V, NdotV, diffuse_color, F0, perceptual_roughness, diffuse_occlusion); | ||
|
||
#ifdef STANDARD_MATERIAL_DIFFUSE_TRANSMISSION | ||
if diffuse_transmission > 0.0 { | ||
// NOTE: We use the diffuse transmissive color, the second Lambertian lobe's calculated | ||
// world position, inverted normal and view vectors, and the following simplified | ||
|
@@ -320,6 +327,7 @@ fn apply_pbr_lighting( | |
// diffuse_occlusion = vec3<f32>(1.0) | ||
transmitted_light += ambient::ambient_light(diffuse_transmissive_lobe_world_position, -in.N, -in.V, 1.0, diffuse_transmissive_color, vec3<f32>(0.0), 1.0, vec3<f32>(1.0)); | ||
} | ||
#endif | ||
|
||
// Environment map light (indirect) | ||
#ifdef ENVIRONMENT_MAP | ||
|
@@ -339,6 +347,7 @@ fn apply_pbr_lighting( | |
// light in the call to `specular_transmissive_light()` below | ||
var specular_transmitted_environment_light = vec3<f32>(0.0); | ||
|
||
#ifdef STANDARD_MATERIAL_SPECULAR_OR_DIFFUSE_TRANSMISSION | ||
if diffuse_transmission > 0.0 || specular_transmission > 0.0 { | ||
// NOTE: We use the diffuse transmissive color, inverted normal and view vectors, | ||
// and the following simplified values for the transmitted environment light contribution | ||
|
@@ -368,9 +377,14 @@ fn apply_pbr_lighting( | |
T, | ||
vec3<f32>(1.0), | ||
in.world_position.xyz); | ||
#ifdef STANDARD_MATERIAL_DIFFUSE_TRANSMISSION | ||
transmitted_light += transmitted_environment_light.diffuse * diffuse_transmissive_color; | ||
#endif | ||
#ifdef STANDARD_MATERIAL_SPECULAR_TRANSMISSION | ||
specular_transmitted_environment_light = transmitted_environment_light.specular * specular_transmissive_color; | ||
#endif | ||
} | ||
#endif // STANDARD_MATERIAL_SPECULAR_OR_DIFFUSE_TRANSMISSION | ||
#else | ||
// If there's no environment map light, there's no transmitted environment | ||
// light specular component, so we can just hardcode it to zero. | ||
|
@@ -383,6 +397,7 @@ fn apply_pbr_lighting( | |
|
||
let emissive_light = emissive.rgb * output_color.a; | ||
|
||
#ifdef STANDARD_MATERIAL_SPECULAR_TRANSMISSION | ||
if specular_transmission > 0.0 { | ||
transmitted_light += transmission::specular_transmissive_light(in.world_position, in.frag_coord.xyz, view_z, in.N, in.V, F0, ior, thickness, perceptual_roughness, specular_transmissive_color, specular_transmitted_environment_light).rgb; | ||
} | ||
|
@@ -401,6 +416,7 @@ fn apply_pbr_lighting( | |
vec3<f32>(0.0) // TODO: Pass in (pre-attenuated) scattered light contribution here | ||
).rgb; | ||
} | ||
#endif | ||
|
||
// Total light | ||
output_color = vec4<f32>( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a small drive-by fix for consistency with the instances of
STANDARD_MATERIAL
in the codebase.