浏览代码

Support for lightmaps in unlit PBR materials (#8553)

Popov72 5 年之前
父节点
当前提交
ab27e512b4

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

@@ -133,6 +133,7 @@
 - Allow using the single comment syntax `// comment` in a `#if` construct in shader code ([Popov72](https://github.com/Popov72))
 - Added the possibility to update the shader code before being compiled ([Popov72](https://github.com/Popov72))
 - Added the `shadowOnly` property to the `BackgroundMaterial` class ([Popov72](https://github.com/Popov72))
+- Added support for lightmaps in unlit PBR materials ([Popov72](https://github.com/Popov72))
 
 ### WebXR
 

+ 2 - 0
src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

@@ -921,6 +921,8 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
 
         state.compilationString += AmbientOcclusionBlock.GetCode(aoBlock);
 
+        state.compilationString += state._emitCodeFromInclude("pbrBlockLightmapInit", comments);
+
         // _____________________________ UNLIT  _______________________________
 
         state.compilationString += `#ifdef UNLIT

+ 0 - 13
src/Shaders/ShadersInclude/pbrBlockDirectLighting.fx

@@ -9,19 +9,6 @@ vec3 diffuseBase = vec3(0., 0., 0.);
     vec3 sheenBase = vec3(0., 0., 0.);
 #endif
 
-#ifdef LIGHTMAP
-    vec4 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset);
-
-    #ifdef RGBDLIGHTMAP
-        lightmapColor.rgb = fromRGBD(lightmapColor);
-    #endif
-
-    #ifdef GAMMALIGHTMAP
-        lightmapColor.rgb = toLinearSpace(lightmapColor.rgb);
-    #endif
-    lightmapColor.rgb *= vLightmapInfos.y;
-#endif
-
 // Direct Lighting Variables
 preLightingInfo preInfo;
 lightingInfo info;

+ 12 - 0
src/Shaders/ShadersInclude/pbrBlockLightmapInit.fx

@@ -0,0 +1,12 @@
+#ifdef LIGHTMAP
+    vec4 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset);
+
+    #ifdef RGBDLIGHTMAP
+        lightmapColor.rgb = fromRGBD(lightmapColor);
+    #endif
+
+    #ifdef GAMMALIGHTMAP
+        lightmapColor.rgb = toLinearSpace(lightmapColor.rgb);
+    #endif
+    lightmapColor.rgb *= vLightmapInfos.y;
+#endif

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

@@ -130,6 +130,8 @@ void main(void) {
         aoOut
     );
 
+    #include<pbrBlockLightmapInit>
+
 #ifdef UNLIT
     vec3 diffuseBase = vec3(1., 1., 1.);
 #else