Skip to content

Commit 7fd1fea

Browse files
committed
Add perceptualRoughness->roughness and clamping
1 parent 9d0f7bd commit 7fd1fea

File tree

1 file changed

+21
-3
lines changed
  • crates/bevy_pbr/src/render_graph/forward_pipeline

1 file changed

+21
-3
lines changed

crates/bevy_pbr/src/render_graph/forward_pipeline/forward.frag

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ layout(set = 1, binding = 0) uniform Lights {
2929

3030
layout(set = 3, binding = 0) uniform StandardMaterial_albedo { vec4 Albedo; };
3131

32-
layout(set = 3, binding = 3) uniform StandardMaterial_pbr { vec2 pbr; };
33-
3432
#ifdef STANDARDMATERIAL_ALBEDO_TEXTURE
3533
layout(set = 3, binding = 1) uniform texture2D StandardMaterial_albedo_texture;
3634
layout(set = 3,
@@ -39,6 +37,8 @@ layout(set = 3,
3937

4038
#ifndef STANDARDMATERIAL_UNLIT
4139

40+
layout(set = 3, binding = 3) uniform StandardMaterial_pbr { vec2 pbr; };
41+
4242
#define saturate(x) clamp(x, 0.0, 1.0)
4343
const float PI = 3.141592653589793;
4444

@@ -117,6 +117,20 @@ float clampNoV(float NoV) {
117117
return max(NoV, MIN_N_DOT_V);
118118
}
119119

120+
float perceptualRoughnessToRoughness(float perceptualRoughness) {
121+
return perceptualRoughness * perceptualRoughness;
122+
}
123+
124+
#if defined(TARGET_MOBILE)
125+
// min roughness such that (MIN_PERCEPTUAL_ROUGHNESS^4) > 0 in fp16 (i.e.
126+
// 2^(-14/4), rounded up)
127+
#define MIN_PERCEPTUAL_ROUGHNESS 0.089
128+
#define MIN_ROUGHNESS 0.007921
129+
#else
130+
#define MIN_PERCEPTUAL_ROUGHNESS 0.045
131+
#define MIN_ROUGHNESS 0.002025
132+
#endif
133+
120134
#endif
121135

122136
void main() {
@@ -128,7 +142,11 @@ void main() {
128142
#endif
129143

130144
#ifndef STANDARDMATERIAL_UNLIT
131-
float roughness = pbr.x;
145+
float perceptual_roughness = pbr.x;
146+
perceptual_roughness =
147+
clamp(perceptual_roughness, MIN_PERCEPTUAL_ROUGHNESS, 1.0);
148+
float roughness = perceptualRoughnessToRoughness(perceptual_roughness);
149+
132150
float metallic = pbr.y;
133151
vec3 N = normalize(v_Normal);
134152
vec3 V = normalize(CameraPos.xyz - v_Position.xyz);

0 commit comments

Comments
 (0)