Skip to content

Commit 3938a0a

Browse files
small changes
1 parent f1649d2 commit 3938a0a

File tree

5 files changed

+35
-29
lines changed

5 files changed

+35
-29
lines changed

lighting/common/envBRDFApprox.glsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef FNC_ENVBRDFAPPROX
22
#define FNC_ENVBRDFAPPROX
33

4+
//https://www.unrealengine.com/en-US/blog/physically-based-shading-on-mobile
45
vec3 envBRDFApprox(const in vec3 _specularColor, const in float _NoV, const in float _roughness) {
56
vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022 );
67
vec4 c1 = vec4( 1.0, 0.0425, 1.040, -0.040 );
@@ -10,4 +11,14 @@ vec3 envBRDFApprox(const in vec3 _specularColor, const in float _NoV, const in f
1011
return _specularColor * AB.x + AB.y;
1112
}
1213

14+
//https://www.unrealengine.com/en-US/blog/physically-based-shading-on-mobile
15+
vec2 envBRDFApprox(const in float _NoV, in float _roughness ) {
16+
const vec4 c0 = vec4( -1.0, -0.0275, -0.572, 0.022 );
17+
const vec4 c1 = vec4( 1.0, 0.0425, 1.04, -0.04 );
18+
vec4 r = _roughness * c0 + c1;
19+
float a004 = min( r.x * r.x, exp2( -9.28 * _NoV ) ) * r.x + r.y;
20+
vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;
21+
return vec2(AB.x, AB.y);
22+
}
23+
1324
#endif

lighting/fresnelReflection.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ vec3 fresnelReflection(const in vec3 R, const in vec3 f0, const in float NoV) {
2424
#elif defined(ENVMAP_FNC)
2525
reflectColor = ENVMAP_FNC(R, 0.001, 0.001);
2626

27-
#elif defined(SCENE_CUBEMAP)
28-
reflectColor = SAMPLE_CUBE_FNC( SCENE_CUBEMAP, R, ENVMAP_MAX_MIP_LEVEL ).rgb;
29-
3027
#elif defined(SCENE_SH_ARRAY)
3128
reflectColor = sphericalHarmonics(R);
3229

30+
#elif defined(SCENE_CUBEMAP)
31+
reflectColor = SAMPLE_CUBE_FNC( SCENE_CUBEMAP, R, ENVMAP_MAX_MIP_LEVEL ).rgb;
32+
3333
#else
3434
reflectColor = fakeCube(R);
3535
#endif

lighting/pbr.glsl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,11 @@ vec4 pbr(const in Material _mat) {
6161
// Global Ilumination ( Image Based Lighting )
6262
// ------------------------
6363
vec3 E = envBRDFApprox(specularColor, NoV, _mat.roughness);
64-
65-
// This is a bit of a hack to pop the metalics
66-
float specIntensity = (2.0 * _mat.metallic) *
67-
saturate(-1.1 + NoV + _mat.metallic) * // Fresnel
68-
(_mat.metallic + (.95 - _mat.roughness) * 2.0); // make smaller highlights brighter
69-
// (_mat.metallic + (1.0 - _mat.roughness)); // make smaller highlights brighter
70-
7164
float diffuseAO = min(_mat.ambientOcclusion, ssao);
7265

7366
vec3 Fr = vec3(0.0, 0.0, 0.0);
74-
Fr = envMap(R, _mat.roughness, _mat.metallic) * E * specIntensity;
75-
#if defined(PLATFORM_RPI)
67+
Fr = envMap(R, _mat.roughness, _mat.metallic) * E * 2.0;
68+
#if !defined(PLATFORM_RPI)
7669
Fr += tonemap( fresnelReflection(R, _mat.f0, NoV) ) * _mat.metallic * (1.0-_mat.roughness) * 0.2;
7770
#endif
7871
Fr *= specularAO(NoV, diffuseAO, _mat.roughness);
@@ -81,7 +74,7 @@ vec4 pbr(const in Material _mat) {
8174
#if defined(SCENE_SH_ARRAY)
8275
Fd *= tonemap( sphericalHarmonics(N) );
8376
#endif
84-
Fd *= diffuseAO; // diffuseAO
77+
Fd *= diffuseAO;
8578
Fd *= (1.0 - E);
8679

8780
// Local Ilumination

lighting/pbrClearCoat.glsl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,31 @@ vec4 pbrClearCoat(const Material _mat) {
7575
// vec2 pixel = 1.0/RESOLUTION;
7676
// ssao = ssao(SCENE_DEPTH, gl_FragCoord.xy*pixel, pixel, 1.);
7777
// #endif
78-
float diffuseAO = min(_mat.ambientOcclusion, ssao);
79-
float specularAO = specularAO(NoV, diffuseAO, _mat.roughness);
8078

8179
// Global Ilumination ( mage Based Lighting )
8280
// ------------------------
8381
vec3 E = envBRDFApprox(specularColor, NoV, _mat.roughness);
8482

85-
// This is a bit of a hack to pop the metalics
86-
float specIntensity = (2.0 * _mat.metallic) *
87-
saturate(-1.1 + NoV + _mat.metallic) * // Fresnel
88-
(_mat.metallic + (.95 - _mat.roughness) * 2.0); // make smaller highlights brighter
83+
// // This is a bit of a hack to pop the metalics
84+
// float specIntensity = (2.0 * _mat.metallic) *
85+
// saturate(-1.1 + NoV + _mat.metallic) * // Fresnel
86+
// (_mat.metallic + (.95 - _mat.roughness) * 2.0); // make smaller highlights brighter
8987

88+
float diffAO = min(_mat.ambientOcclusion, ssao);
89+
float specAO = specularAO(NoV, diffAO, _mat.roughness);
9090

9191
vec3 Fr = vec3(0.0, 0.0, 0.0);
92-
Fr = envMap(R, _mat.roughness, _mat.metallic) * E * specIntensity;
92+
Fr = envMap(R, _mat.roughness, _mat.metallic) * E * 2.0;
93+
#if !defined(PLATFORM_RPI)
9394
Fr += tonemap( fresnelReflection(R, f0, NoV) ) * _mat.metallic * (1.0-_mat.roughness) * 0.2;
94-
Fr *= specularAO;
95+
#endif
96+
Fr *= specAO;
9597

96-
vec3 Fd = vec3(0.0, 0.0, 0.0);
97-
Fd = diffuseColor;
98+
vec3 Fd = diffuseColor;
9899
#if defined(SCENE_SH_ARRAY)
99100
Fd *= tonemap( sphericalHarmonics(N) );
100101
#endif
101-
Fd *= diffuseAO;
102+
Fd *= diffAO;
102103
Fd *= (1.0 - E);
103104

104105
vec3 Fc = fresnel(f0, clearCoatNoV) * _mat.clearCoat;
@@ -111,8 +112,8 @@ vec4 pbrClearCoat(const Material _mat) {
111112
vec3 clearCoatE = envBRDFApprox(f0, clearCoatNoV, _mat.clearCoatRoughness);
112113
vec3 clearCoatLobe = vec3(0.0, 0.0, 0.0);
113114
clearCoatLobe += envMap(clearCoatR, _mat.clearCoatRoughness, 1.0) * clearCoatE * 3.;
114-
clearCoatLobe += tonemap( fresnelReflection(clearCoatR, f0, clearCoatNoV) ) * (1.0-_mat.clearCoatRoughness);
115-
Fr += clearCoatLobe * (specularAO * _mat.clearCoat);
115+
clearCoatLobe += tonemap( fresnelReflection(clearCoatR, f0, clearCoatNoV) ) * (1.0-_mat.clearCoatRoughness) * 0.2;
116+
Fr += clearCoatLobe * (specAO * _mat.clearCoat);
116117

117118
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
118119
color.rgb += Fd * IBL_LUMINANCE; // Diffuse
@@ -136,8 +137,9 @@ vec4 pbrClearCoat(const Material _mat) {
136137
color.rgb += lightDiffuse; // Diffuse
137138
color.rgb += lightSpecular; // Specular
138139

139-
// Clear Coat
140+
// Clear Coat Local ilumination
140141
#if defined(LIGHT_DIRECTION) || defined(LIGHT_POSITION)
142+
141143
#if defined(LIGHT_DIRECTION)
142144
vec3 L = normalize(LIGHT_DIRECTION);
143145
#elif defined(LIGHT_POSITION)

lighting/pbrGlass.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ vec4 pbrGlass(const Material _mat) {
6363

6464
vec3 Fr = vec3(0.0, 0.0, 0.0);
6565
Fr = envMap(Re, roughness) * E;
66-
#if defined(PLATFORM_RPI)
67-
Fr += tonemap( fresnelReflection(Re, _mat.f0, NoV) ) * (1.0-roughness);
66+
#if !defined(PLATFORM_RPI)
67+
Fr += tonemap( fresnelReflection(Re, _mat.f0, NoV) ) * (1.0-roughness) * 0.2;
6868
#endif
6969

7070
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);

0 commit comments

Comments
 (0)