浏览代码

Merge branch 'prepass' into prepass-es6

Benjamin Guignabert 5 年之前
父节点
当前提交
ad8f5c31e2
共有 3 个文件被更改,包括 32 次插入18 次删除
  1. 27 17
      src/Materials/Textures/multiRenderTarget.ts
  2. 1 1
      src/Rendering/prePassRenderer.ts
  3. 4 0
      src/Shaders/pbr.fragment.fx

+ 27 - 17
src/Materials/Textures/multiRenderTarget.ts

@@ -138,22 +138,9 @@ export class MultiRenderTarget extends RenderTargetTexture {
             return;
         }
 
-        var types = [];
-        var samplingModes = [];
-
-        for (var i = 0; i < count; i++) {
-            if (options && options.types && options.types[i] !== undefined) {
-                types.push(options.types[i]);
-            } else {
-                types.push(options && options.defaultType ? options.defaultType : Constants.TEXTURETYPE_UNSIGNED_INT);
-            }
-
-            if (options && options.samplingModes && options.samplingModes[i] !== undefined) {
-                samplingModes.push(options.samplingModes[i]);
-            } else {
-                samplingModes.push(Texture.BILINEAR_SAMPLINGMODE);
-            }
-        }
+        var types: number[] = [];
+        var samplingModes: number[] = [];
+        this._initTypes(count, types, samplingModes, options);
 
         var generateDepthBuffer = !options || options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
         var generateStencilBuffer = !options || options.generateStencilBuffer === undefined ? false : options.generateStencilBuffer;
@@ -175,6 +162,22 @@ export class MultiRenderTarget extends RenderTargetTexture {
         this._createTextures();
     }
 
+    private _initTypes(count: number, types: number[], samplingModes: number[], options?: IMultiRenderTargetOptions) {
+        for (var i = 0; i < count; i++) {
+            if (options && options.types && options.types[i] !== undefined) {
+                types.push(options.types[i]);
+            } else {
+                types.push(options && options.defaultType ? options.defaultType : Constants.TEXTURETYPE_UNSIGNED_INT);
+            }
+
+            if (options && options.samplingModes && options.samplingModes[i] !== undefined) {
+                samplingModes.push(options.samplingModes[i]);
+            } else {
+                samplingModes.push(Texture.BILINEAR_SAMPLINGMODE);
+            }
+        }
+    }
+
     /** @hidden */
     public _rebuild(forceFullRebuild: boolean = false): void {
         this.releaseInternalTextures();
@@ -243,9 +246,16 @@ export class MultiRenderTarget extends RenderTargetTexture {
      * Be careful as it will recreate all the data in the new texture.
      * @param count new texture count
      */
-    public updateCount(count: number) {
+    public updateCount(count: number, options?: IMultiRenderTargetOptions) {
         this._multiRenderTargetOptions.textureCount = count;
         this._count = count;
+
+        const types: number[] = [];
+        const samplingModes: number[] = [];
+
+        this._initTypes(count, types, samplingModes, options);
+        this._multiRenderTargetOptions.types = types;
+        this._multiRenderTargetOptions.samplingModes = samplingModes;
         this._rebuild(true);
     }
 

+ 1 - 1
src/Rendering/prePassRenderer.ts

@@ -311,7 +311,7 @@ export class PrePassRenderer {
         }
 
         if (this.prePassRT && this.mrtCount !== previousMrtCount) {
-            this.prePassRT.updateCount(this.mrtCount);
+            this.prePassRT.updateCount(this.mrtCount, { types: this._mrtFormats });
         }
 
         this._resetPostProcessChain();

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

@@ -513,6 +513,10 @@ void main(void) {
         vec3 sqAlbedo = sqrt(surfaceAlbedo); // for pre and post scatter
         gl_FragData[0] = vec4(finalColor.rgb - irradiance, finalColor.a); // Split irradiance from final color
         irradiance /= sqAlbedo;
+        
+        #ifndef SS_SCATTERING
+            float scatteringDiffusionProfile = 255.;
+        #endif
         gl_FragData[PREPASS_IRRADIANCE_INDEX] = vec4(tagLightingForSSS(irradiance), scatteringDiffusionProfile / 255.); // Irradiance + SS diffusion profile
     #else
         gl_FragData[0] = vec4(finalColor.rgb, finalColor.a);