Parcourir la source

ShaderChunks: Testing potential mobile performance improvements.

Mr.doob il y a 3 mois
Parent
commit
3738cdb580

+ 1 - 1
src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js

@@ -1,7 +1,7 @@
 export default /* glsl */`
 #ifdef USE_AOMAP
 
-	uniform sampler2D aoMap;
+	uniform mediump sampler2D aoMap;
 	uniform float aoMapIntensity;
 
 #endif

+ 20 - 20
src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js

@@ -79,8 +79,8 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi
 #if NUM_DIR_LIGHTS > 0
 
 	struct DirectionalLight {
-		vec3 direction;
-		vec3 color;
+		mediump vec3 direction;
+		mediump vec3 color;
 	};
 
 	uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
@@ -99,10 +99,10 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi
 #if NUM_POINT_LIGHTS > 0
 
 	struct PointLight {
-		vec3 position;
-		vec3 color;
-		float distance;
-		float decay;
+		highp vec3 position;
+		mediump vec3 color;
+		mediump float distance;
+		mediump float decay;
 	};
 
 	uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
@@ -128,13 +128,13 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi
 #if NUM_SPOT_LIGHTS > 0
 
 	struct SpotLight {
-		vec3 position;
-		vec3 direction;
-		vec3 color;
-		float distance;
-		float decay;
-		float coneCos;
-		float penumbraCos;
+		highp vec3 position;
+		mediump vec3 direction;
+		mediump vec3 color;
+		mediump float distance;
+		mediump float decay;
+		mediump float coneCos;
+		mediump float penumbraCos;
 	};
 
 	uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
@@ -173,10 +173,10 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi
 #if NUM_RECT_AREA_LIGHTS > 0
 
 	struct RectAreaLight {
-		vec3 color;
-		vec3 position;
-		vec3 halfWidth;
-		vec3 halfHeight;
+		mediump vec3 color;
+		highp vec3 position;
+		highp vec3 halfWidth;
+		highp vec3 halfHeight;
 	};
 
 	// Pre-computed values of LinearTransformedCosine approximation of BRDF
@@ -192,9 +192,9 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi
 #if NUM_HEMI_LIGHTS > 0
 
 	struct HemisphereLight {
-		vec3 direction;
-		vec3 skyColor;
-		vec3 groundColor;
+		mediump vec3 direction;
+		mediump vec3 skyColor;
+		mediump vec3 groundColor;
 	};
 
 	uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];

+ 5 - 7
src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js

@@ -69,16 +69,14 @@ vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH )
     return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
 }
 
-// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2
-// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
+// Filament's optimized GGX Smith Correlated visibility function
 float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
-
+ 
 	float a2 = pow2( alpha );
 
-	float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
-	float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
-
-	return 0.5 / max( gv + gl, EPSILON );
+	float gv = dotNL * ( dotNV * ( 1.0 - a2 ) + a2 );
+    float gl = dotNV * ( dotNL * ( 1.0 - a2 ) + a2 );
+    return 0.5 / max( gv + gl, EPSILON );
 
 }
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js

@@ -1,7 +1,7 @@
 export default /* glsl */`
 #ifdef USE_MAP
 
-	uniform sampler2D map;
+	uniform mediump sampler2D map;
 
 #endif
 `;

+ 1 - 1
src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js

@@ -1,7 +1,7 @@
 export default /* glsl */`
 #ifdef USE_METALNESSMAP
 
-	uniform sampler2D metalnessMap;
+	uniform mediump sampler2D metalnessMap;
 
 #endif
 `;

+ 2 - 2
src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js

@@ -1,8 +1,8 @@
 export default /* glsl */`
 #ifdef USE_NORMALMAP
 
-	uniform sampler2D normalMap;
-	uniform vec2 normalScale;
+	uniform mediump sampler2D normalMap;
+	uniform mediump vec2 normalScale;
 
 #endif
 

+ 4 - 0
src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js

@@ -9,4 +9,8 @@ float roughnessFactor = roughness;
 	roughnessFactor *= texelRoughness.g;
 
 #endif
+
+// Clamp for mobile fp16 safety - prevents division by near-zero in BRDF
+roughnessFactor = clamp( roughnessFactor , 0.089, 1.0 );
+
 `;

+ 1 - 1
src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js

@@ -1,7 +1,7 @@
 export default /* glsl */`
 #ifdef USE_ROUGHNESSMAP
 
-	uniform sampler2D roughnessMap;
+	uniform mediump sampler2D roughnessMap;
 
 #endif
 `;

+ 5 - 5
src/renderers/shaders/ShaderLib/meshphysical.glsl.js

@@ -67,11 +67,11 @@ export const fragment = /* glsl */`
 	#define USE_SPECULAR
 #endif
 
-uniform vec3 diffuse;
-uniform vec3 emissive;
-uniform float roughness;
-uniform float metalness;
-uniform float opacity;
+uniform mediump vec3 diffuse;
+uniform mediump vec3 emissive;
+uniform mediump float roughness;
+uniform mediump float metalness;
+uniform mediump float opacity;
 
 #ifdef IOR
 	uniform float ior;

粤ICP备19079148号