瀏覽代碼

move grain out of applyImageProcessing, set IMAGEPROCESSING when grain is enabled

Trevor Baron 7 年之前
父節點
當前提交
8a171da3b4

+ 1 - 1
src/Materials/babylon.imageProcessingConfiguration.ts

@@ -442,8 +442,8 @@ module BABYLON {
             defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
             defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
-            defines.IMAGEPROCESSING = defines.VIGNETTE || defines.TONEMAPPING || defines.CONTRAST || defines.EXPOSURE || defines.COLORCURVES || defines.COLORGRADING;
             defines.GRAIN = this.grainEnabled;
+            defines.IMAGEPROCESSING = defines.VIGNETTE || defines.TONEMAPPING || defines.CONTRAST || defines.EXPOSURE || defines.COLORCURVES || defines.COLORGRADING || defines.GRAIN;
         }
 
         /**

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

@@ -81,18 +81,6 @@ vec4 applyImageProcessing(vec4 result) {
 	result.rgb = 1.0 - exp2(-tonemappingCalibration * result.rgb);
 #endif
 
-#ifdef GRAIN
-	vec2 seed = vUV*(grainAnimatedSeed);
-	float grain = dither(seed, grainVarianceAmount);
-
-	// Add less grain when luminance is high or low
-	float lum = getLuminance(result.rgb);
-	float grainAmount = (cos(-PI + (lum*PI*2.))+1.)/2.;
-	result.rgb += grain * grainAmount;
-
-	result.rgb = max(result.rgb, 0.0);
-#endif
-
 	// Going back to gamma space
 	result.rgb = toGammaSpace(result.rgb);
 	result.rgb = clamp(result.rgb, 0.0, 1.0);

+ 12 - 0
src/Shaders/imageProcessing.fragment.fx

@@ -18,6 +18,18 @@ void main(void)
 		result.rgb = toLinearSpace(result.rgb);
 	#endif
 
+	#ifdef GRAIN
+		vec2 seed = vUV*(grainAnimatedSeed);
+		float grain = dither(seed, grainVarianceAmount);
+
+		// Add less grain when luminance is high or low
+		float lum = getLuminance(result.rgb);
+		float grainAmount = (cos(-PI + (lum*PI*2.))+1.)/2.;
+		result.rgb += grain * grainAmount;
+
+		result.rgb = max(result.rgb, 0.0);
+	#endif
+
 	result = applyImageProcessing(result);
 #else
 	// In case where the input is in linear space we at least need to put it back in gamma.