浏览代码

Automatic shader precision management

David Catuhe 9 年之前
父节点
当前提交
bb50b674d3
共有 53 个文件被更改,包括 2923 次插入2973 次删除
  1. 4 4
      dist/preview release/babylon.core.js
  2. 2810 2809
      dist/preview release/babylon.d.ts
  3. 5 5
      dist/preview release/babylon.js
  4. 20 6
      dist/preview release/babylon.max.js
  5. 5 5
      dist/preview release/babylon.noworker.js
  6. 18 4
      src/Materials/babylon.effect.js
  7. 19 5
      src/Materials/babylon.effect.ts
  8. 1 3
      src/Shaders/anaglyph.fragment.fx
  9. 1 3
      src/Shaders/blackAndWhite.fragment.fx
  10. 1 3
      src/Shaders/blur.fragment.fx
  11. 0 2
      src/Shaders/chromaticAberration.fragment.fx
  12. 1 3
      src/Shaders/color.fragment.fx
  13. 1 3
      src/Shaders/color.vertex.fx
  14. 1 3
      src/Shaders/colorCorrection.fragment.fx
  15. 1 3
      src/Shaders/convolution.fragment.fx
  16. 0 2
      src/Shaders/default.fragment.fx
  17. 1 3
      src/Shaders/default.vertex.fx
  18. 1 3
      src/Shaders/depth.fragment.fx
  19. 1 3
      src/Shaders/depth.vertex.fx
  20. 1 3
      src/Shaders/depthBoxBlur.fragment.fx
  21. 0 3
      src/Shaders/depthOfField.fragment.fx
  22. 1 3
      src/Shaders/displayPass.fragment.fx
  23. 1 3
      src/Shaders/filter.fragment.fx
  24. 1 3
      src/Shaders/fxaa.fragment.fx
  25. 1 3
      src/Shaders/hdr.fragment.fx
  26. 1 3
      src/Shaders/layer.fragment.fx
  27. 1 3
      src/Shaders/layer.vertex.fx
  28. 1 3
      src/Shaders/legacydefault.fragment.fx
  29. 1 3
      src/Shaders/legacydefault.vertex.fx
  30. 1 3
      src/Shaders/lensFlare.fragment.fx
  31. 1 3
      src/Shaders/lensFlare.vertex.fx
  32. 0 2
      src/Shaders/lensHighlights.fragment.fx
  33. 1 3
      src/Shaders/line.fragment.fx
  34. 1 3
      src/Shaders/line.vertex.fx
  35. 1 3
      src/Shaders/outline.fragment.fx
  36. 1 3
      src/Shaders/outline.vertex.fx
  37. 1 3
      src/Shaders/particles.fragment.fx
  38. 1 3
      src/Shaders/particles.vertex.fx
  39. 1 3
      src/Shaders/pass.fragment.fx
  40. 1 3
      src/Shaders/postprocess.vertex.fx
  41. 1 3
      src/Shaders/procedural.vertex.fx
  42. 1 3
      src/Shaders/refraction.fragment.fx
  43. 1 3
      src/Shaders/shadowMap.fragment.fx
  44. 1 3
      src/Shaders/shadowMap.vertex.fx
  45. 1 3
      src/Shaders/sprites.fragment.fx
  46. 1 3
      src/Shaders/sprites.vertex.fx
  47. 1 3
      src/Shaders/ssao.fragment.fx
  48. 1 3
      src/Shaders/ssaoCombine.fragment.fx
  49. 1 3
      src/Shaders/stereoscopicInterlace.fragment.fx
  50. 1 3
      src/Shaders/tonemap.fragment.fx
  51. 1 3
      src/Shaders/volumetricLightScattering.fragment.fx
  52. 1 3
      src/Shaders/volumetricLightScatteringPass.fragment.fx
  53. 1 3
      src/Shaders/vrDistortionCorrection.fragment.fx

文件差异内容过多而无法显示
+ 4 - 4
dist/preview release/babylon.core.js


文件差异内容过多而无法显示
+ 2810 - 2809
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 5 - 5
dist/preview release/babylon.js


文件差异内容过多而无法显示
+ 20 - 6
dist/preview release/babylon.max.js


文件差异内容过多而无法显示
+ 5 - 5
dist/preview release/babylon.noworker.js


+ 18 - 4
src/Materials/babylon.effect.js

@@ -223,14 +223,28 @@ var BABYLON;
             }
             callback(returnValue);
         };
+        Effect.prototype._processPrecision = function (source) {
+            if (source.indexOf("precision highp float") === -1) {
+                if (!this._engine.getCaps().highPrecisionShaderSupported) {
+                    source = "precision mediump float;\n" + source;
+                }
+                else {
+                    source = "precision highp float;\n" + source;
+                }
+            }
+            else {
+                if (!this._engine.getCaps().highPrecisionShaderSupported) {
+                    source = source.replace("precision highp float", "precision mediump float");
+                }
+            }
+            return source;
+        };
         Effect.prototype._prepareEffect = function (vertexSourceCode, fragmentSourceCode, attributesNames, defines, fallbacks) {
             try {
                 var engine = this._engine;
                 // Precision
-                if (!engine.getCaps().highPrecisionShaderSupported) {
-                    vertexSourceCode = vertexSourceCode.replace("precision highp float", "precision mediump float");
-                    fragmentSourceCode = fragmentSourceCode.replace("precision highp float", "precision mediump float");
-                }
+                vertexSourceCode = this._processPrecision(vertexSourceCode);
+                fragmentSourceCode = this._processPrecision(fragmentSourceCode);
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._attributes = engine.getAttributes(this._program, attributesNames);

+ 19 - 5
src/Materials/babylon.effect.ts

@@ -281,16 +281,30 @@
             callback(returnValue);
         }
 
+        private _processPrecision(source: string): string {
+            if (source.indexOf("precision highp float") === -1) {
+                if (!this._engine.getCaps().highPrecisionShaderSupported) {
+                    source = "precision mediump float;\n" + source;
+                } else {
+                    source = "precision highp float;\n" + source;
+                }
+            } else {
+                if (!this._engine.getCaps().highPrecisionShaderSupported) { // Moving highp to mediump
+                    source = source.replace("precision highp float", "precision mediump float");
+                }
+            }
+
+            return source;
+        }
+
         private _prepareEffect(vertexSourceCode: string, fragmentSourceCode: string, attributesNames: string[], defines: string, fallbacks?: EffectFallbacks): void {
             try {
                 var engine = this._engine;
 
                 // Precision
-                if (!engine.getCaps().highPrecisionShaderSupported) { // Moving highp to mediump
-                    vertexSourceCode = vertexSourceCode.replace("precision highp float", "precision mediump float");
-                    fragmentSourceCode = fragmentSourceCode.replace("precision highp float", "precision mediump float");
-                }
-
+                vertexSourceCode = this._processPrecision(vertexSourceCode);
+                fragmentSourceCode = this._processPrecision(fragmentSourceCode);
+                
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
 
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);

+ 1 - 3
src/Shaders/anaglyph.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 uniform sampler2D leftSampler;

+ 1 - 3
src/Shaders/blackAndWhite.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

+ 1 - 3
src/Shaders/blur.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

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

@@ -1,5 +1,3 @@
-precision highp float;
-
 // samplers
 uniform sampler2D textureSampler;	// original color
 

+ 1 - 3
src/Shaders/color.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-uniform vec4 color;
+uniform vec4 color;
 
 void main(void) {
 	gl_FragColor = color;

+ 1 - 3
src/Shaders/color.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec3 position;
 
 // Uniforms

+ 1 - 3
src/Shaders/colorCorrection.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// samplers
+// samplers
 uniform sampler2D textureSampler;	// screen render
 uniform sampler2D colorTable;		// color table with modified colors
 

+ 1 - 3
src/Shaders/convolution.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

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

@@ -6,8 +6,6 @@
 #extension GL_EXT_frag_depth : enable
 #endif
 
-precision highp float;
-
 // Constants
 #define RECIPROCAL_PI2 0.15915494
 

+ 1 - 3
src/Shaders/default.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec3 position;
 #ifdef NORMAL
 attribute vec3 normal;

+ 1 - 3
src/Shaders/depth.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-#ifdef ALPHATEST
+#ifdef ALPHATEST
 varying vec2 vUV;
 uniform sampler2D diffuseSampler;
 #endif

+ 1 - 3
src/Shaders/depth.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attribute
+// Attribute
 attribute vec3 position;
 #include<bonesDeclaration>
 

+ 1 - 3
src/Shaders/depthBoxBlur.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

+ 0 - 3
src/Shaders/depthOfField.fragment.fx

@@ -3,9 +3,6 @@
 // Does depth-of-field blur, edge blur
 // Inspired by Francois Tarlier & Martins Upitis
 
-precision highp float;
-
-
 // samplers
 uniform sampler2D textureSampler;
 uniform sampler2D highlightsSampler;

+ 1 - 3
src/Shaders/displayPass.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 uniform sampler2D passSampler;

+ 1 - 3
src/Shaders/filter.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

+ 1 - 3
src/Shaders/fxaa.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-#define FXAA_REDUCE_MIN   (1.0/128.0)
+#define FXAA_REDUCE_MIN   (1.0/128.0)
 #define FXAA_REDUCE_MUL   (1.0/8.0)
 #define FXAA_SPAN_MAX     8.0
 

+ 1 - 3
src/Shaders/hdr.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-uniform sampler2D textureSampler;
+uniform sampler2D textureSampler;
 varying vec2 vUV;
 
 #if defined(GAUSSIAN_BLUR_H) || defined(GAUSSIAN_BLUR_V)

+ 1 - 3
src/Shaders/layer.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

+ 1 - 3
src/Shaders/layer.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec2 position;
 
 // Uniforms

+ 1 - 3
src/Shaders/legacydefault.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-#define MAP_PROJECTION	4.
+#define MAP_PROJECTION	4.
 
 // Constants
 uniform vec3 vEyePosition;

+ 1 - 3
src/Shaders/legacydefault.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec3 position;
 attribute vec3 normal;
 #ifdef UV1

+ 1 - 3
src/Shaders/lensFlare.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

+ 1 - 3
src/Shaders/lensFlare.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec2 position;
 
 // Uniforms

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

@@ -1,5 +1,3 @@
-precision highp float;
-
 // samplers
 uniform sampler2D textureSampler;	// original color
 

+ 1 - 3
src/Shaders/line.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-uniform vec4 color;
+uniform vec4 color;
 
 void main(void) {
 	gl_FragColor = color;

+ 1 - 3
src/Shaders/line.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec3 position;
 attribute vec4 normal;
 

+ 1 - 3
src/Shaders/outline.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-uniform vec4 color;
+uniform vec4 color;
 
 #ifdef ALPHATEST
 varying vec2 vUV;

+ 1 - 3
src/Shaders/outline.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attribute
+// Attribute
 attribute vec3 position;
 attribute vec3 normal;
 

+ 1 - 3
src/Shaders/particles.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 varying vec4 vColor;
 uniform vec4 textureMask;

+ 1 - 3
src/Shaders/particles.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec3 position;
 attribute vec4 color;
 attribute vec4 options;

+ 1 - 3
src/Shaders/pass.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

+ 1 - 3
src/Shaders/postprocess.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec2 position;
 
 // Output

+ 1 - 3
src/Shaders/procedural.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec2 position;
 
 // Output

+ 1 - 3
src/Shaders/refraction.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 uniform sampler2D refractionSampler;

+ 1 - 3
src/Shaders/shadowMap.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-vec4 pack(float depth)
+vec4 pack(float depth)
 {
 	const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);
 	const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);

+ 1 - 3
src/Shaders/shadowMap.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attribute
+// Attribute
 attribute vec3 position;
 
 #include<bonesDeclaration>

+ 1 - 3
src/Shaders/sprites.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-uniform bool alphaTest;
+uniform bool alphaTest;
 
 varying vec4 vColor;
 

+ 1 - 3
src/Shaders/sprites.vertex.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Attributes
+// Attributes
 attribute vec4 position;
 attribute vec4 options;
 attribute vec4 cellInfo;

+ 1 - 3
src/Shaders/ssao.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-uniform sampler2D textureSampler;
+uniform sampler2D textureSampler;
 uniform sampler2D randomSampler;
 
 uniform float randTextureTiles;

+ 1 - 3
src/Shaders/ssaoCombine.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-uniform sampler2D textureSampler;
+uniform sampler2D textureSampler;
 uniform sampler2D originalColor;
 
 varying vec2 vUV;

+ 1 - 3
src/Shaders/stereoscopicInterlace.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-const vec3 TWO = vec3(2.0, 2.0, 2.0);
+const vec3 TWO = vec3(2.0, 2.0, 2.0);
 
 varying vec2 vUV;
 uniform sampler2D camASampler;

+ 1 - 3
src/Shaders/tonemap.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 

+ 1 - 3
src/Shaders/volumetricLightScattering.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-uniform sampler2D textureSampler;
+uniform sampler2D textureSampler;
 uniform sampler2D lightScatteringSampler;
 
 uniform float decay;

+ 1 - 3
src/Shaders/volumetricLightScatteringPass.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-#if defined(ALPHATEST) || defined(NEED_UV)
+#if defined(ALPHATEST) || defined(NEED_UV)
 varying vec2 vUV;
 #endif
 

+ 1 - 3
src/Shaders/vrDistortionCorrection.fragment.fx

@@ -1,6 +1,4 @@
-precision highp float;
-
-// Samplers
+// Samplers
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 uniform vec2 LensCenter;