Browse Source

WebGLProgram: Moved dithering_pars_fragment include logic to glsl preprocessor. See #11076.

Mr.doob 8 years ago
parent
commit
122a8d550f

+ 15 - 11
src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl

@@ -1,14 +1,18 @@
-// based on https://www.shadertoy.com/view/MslGR8
-vec3 dithering( vec3 color ) {
-	//Calculate grid position
-	float grid_position = fract( dot( gl_FragCoord.xy - vec2( 0.5, 0.5 ) , vec2( 1.0 / 16.0, 10.0 / 36.0 ) + 0.25 ) );
+#if defined( DITHERING )
 
-	//Shift the individual colors differently, thus making it even harder to see the dithering pattern
-	vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
+	// based on https://www.shadertoy.com/view/MslGR8
+	vec3 dithering( vec3 color ) {
+		//Calculate grid position
+		float grid_position = fract( dot( gl_FragCoord.xy - vec2( 0.5, 0.5 ) , vec2( 1.0 / 16.0, 10.0 / 36.0 ) + 0.25 ) );
 
-	//modify shift acording to grid position.
-	dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
+		//Shift the individual colors differently, thus making it even harder to see the dithering pattern
+		vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
 
-	//shift the color by dither_shift
-	return color + 0.5 / 255.0 + dither_shift_RGB;
-}
+		//modify shift acording to grid position.
+		dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
+
+		//shift the color by dither_shift
+		return color + 0.5 / 255.0 + dither_shift_RGB;
+	}
+
+#endif

+ 1 - 0
src/renderers/shaders/ShaderLib/meshlambert_frag.glsl

@@ -12,6 +12,7 @@ varying vec3 vLightFront;
 
 #include <common>
 #include <packing>
+#include <dithering_pars_fragment>
 #include <color_pars_fragment>
 #include <uv_pars_fragment>
 #include <uv2_pars_fragment>

+ 1 - 0
src/renderers/shaders/ShaderLib/meshphong_frag.glsl

@@ -8,6 +8,7 @@ uniform float opacity;
 
 #include <common>
 #include <packing>
+#include <dithering_pars_fragment>
 #include <color_pars_fragment>
 #include <uv_pars_fragment>
 #include <uv2_pars_fragment>

+ 1 - 0
src/renderers/shaders/ShaderLib/meshphysical_frag.glsl

@@ -21,6 +21,7 @@ varying vec3 vViewPosition;
 
 #include <common>
 #include <packing>
+#include <dithering_pars_fragment>
 #include <color_pars_fragment>
 #include <uv_pars_fragment>
 #include <uv2_pars_fragment>

+ 0 - 1
src/renderers/webgl/WebGLProgram.js

@@ -478,7 +478,6 @@ function WebGLProgram( renderer, code, material, parameters ) {
 			( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
 
 			parameters.dithering ? '#define DITHERING' : '',
-			parameters.dithering ? ShaderChunk[ 'dithering_pars_fragment' ] : '',
 
 			( parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ? ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
 			parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',