فهرست منبع

Fix horizon occlusion in PBR materials

Popov72 5 سال پیش
والد
کامیت
1cd830755e
3فایلهای تغییر یافته به همراه8 افزوده شده و 4 حذف شده
  1. 2 0
      dist/preview release/what's new.md
  2. 2 2
      src/Shaders/ShadersInclude/pbrIBLFunctions.fx
  3. 4 2
      src/Shaders/pbr.fragment.fx

+ 2 - 0
dist/preview release/what's new.md

@@ -64,5 +64,7 @@
 - Fixed NME codegen: missing common properties for float-value input block. ([ycw](https://github.com/ycw))
 - Fixed missing options for MeshBuilder.CreateBox. ([ycw](https://github.com/ycw))
 - Fix bug in `Plane.transform` when matrix passed in is not a pure rotation ([Popov72](https://github.com/Popov72)
+- Fix bug in PBR when anisotropy is enabled and no bump texture is provided ([Popov72](https://github.com/Popov72)
+- Fix horizon occlusion in PBR materials ([Popov72](https://github.com/Popov72)
 
 ## Breaking changes

+ 2 - 2
src/Shaders/ShadersInclude/pbrIBLFunctions.fx

@@ -21,10 +21,10 @@
 #endif
 
 #if defined(ENVIRONMENTBRDF) && defined(HORIZONOCCLUSION)
-    float environmentHorizonOcclusion(vec3 view, vec3 normal) {
+    float environmentHorizonOcclusion(vec3 view, vec3 normal, vec3 geometricNormal) {
         // http://marmosetco.tumblr.com/post/81245981087
         vec3 reflection = reflect(view, normal);
-        float temp = saturate(1.0 + 1.1 * dot(reflection, normal));
+        float temp = saturate(1.0 + 1.1 * dot(reflection, geometricNormal));
         return square(temp);
     }
 #endif

+ 4 - 2
src/Shaders/pbr.fragment.fx

@@ -64,6 +64,8 @@ void main(void) {
     vec3 normalW = normalize(cross(dFdx(vPositionW), dFdy(vPositionW))) * vEyePosition.w;
 #endif
 
+    vec3 geometricNormalW = normalW;
+
 #ifdef CLEARCOAT
     // Needs to use the geometric normal before bump for this.
     vec3 clearCoatNormalW = normalW;
@@ -883,7 +885,7 @@ void main(void) {
         #ifdef HORIZONOCCLUSION
             #ifdef BUMP
                 #ifdef REFLECTIONMAP_3D
-                    float eho = environmentHorizonOcclusion(-viewDirectionW, normalW);
+                    float eho = environmentHorizonOcclusion(-viewDirectionW, normalW, geometricNormalW);
                     specularEnvironmentReflectance *= eho;
                 #endif
             #endif
@@ -941,7 +943,7 @@ void main(void) {
             #ifdef HORIZONOCCLUSION
                 #ifdef BUMP
                     #ifdef REFLECTIONMAP_3D
-                        float clearCoatEho = environmentHorizonOcclusion(-viewDirectionW, clearCoatNormalW);
+                        float clearCoatEho = environmentHorizonOcclusion(-viewDirectionW, clearCoatNormalW, geometricNormalW);
                         clearCoatEnvironmentReflectance *= clearCoatEho;
                     #endif
                 #endif