@@ -136,9 +136,9 @@ -(void)buildFragmentFunctions
136136{
137137 self.fragmentFunctions = [[NSMutableArray alloc ] init ];
138138
139- GLfloat *standardGaussianWeights = calloc (_trueBlurRadius + 1 , sizeof (GLfloat));
139+ GLfloat *standardGaussianWeights = calloc (_trueBlurRadius + 2 , sizeof (GLfloat));
140140 GLfloat sumOfWeights = 0.0 ;
141- for (NSUInteger currentGaussianWeightIndex = 0 ; currentGaussianWeightIndex < _trueBlurRadius + 1 ; currentGaussianWeightIndex++)
141+ for (NSUInteger currentGaussianWeightIndex = 0 ; currentGaussianWeightIndex < _trueBlurRadius + 2 ; currentGaussianWeightIndex++)
142142 {
143143 standardGaussianWeights[currentGaussianWeightIndex] = (1.0 / sqrt (2.0 * M_PI * pow (_sigma, 2.0 ))) * exp (-pow (currentGaussianWeightIndex, 2.0 ) / (2.0 * pow (_sigma, 2.0 )));
144144
@@ -153,14 +153,14 @@ -(void)buildFragmentFunctions
153153 }
154154
155155 // Next, normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance
156- for (NSUInteger currentGaussianWeightIndex = 0 ; currentGaussianWeightIndex < _trueBlurRadius + 1 ; currentGaussianWeightIndex++)
156+ for (NSUInteger currentGaussianWeightIndex = 0 ; currentGaussianWeightIndex < _trueBlurRadius + 2 ; currentGaussianWeightIndex++)
157157 {
158158 standardGaussianWeights[currentGaussianWeightIndex] = standardGaussianWeights[currentGaussianWeightIndex] / sumOfWeights;
159159 }
160160
161161 // From these weights we calculate the offsets to read interpolated values from
162- NSUInteger numberOfOptimizedOffsets = MIN (_blurRadius / 2 + (_blurRadius % 2 ), BLUR_OPTIMIZED_RADIUS_MAX) ;
163- NSUInteger trueNumberOfOptimizedOffsets = _trueBlurRadius / 2 + (_trueBlurRadius % 2 ) ;
162+ NSUInteger numberOfOptimizedOffsets = _numberOfOptimizedOffsets ;
163+ NSUInteger trueNumberOfOptimizedOffsets = _trueBlurRadius / 2 ;
164164
165165 NSMutableString *shaderString = [[NSMutableString alloc ] init ];
166166
@@ -183,7 +183,7 @@ -(void)buildFragmentFunctions
183183 [shaderString appendString: @" inBounds = step(0.0, min(compare.x, compare.y));" ];
184184 [shaderString appendFormat: @" srcPixel = texture2D(cc_PreviousPassTexture, v_blurCoordinates[0]);\n " ];
185185 [shaderString appendString: @" luminanceCheck = step(u_luminanceThreshold, dot(srcPixel.rgb, luminanceWeighting));\n " ];
186- [shaderString appendFormat: @" src += inBounds * luminanceCheck * srcPixel * %f ;\n " , standardGaussianWeights[0 ]];
186+ [shaderString appendFormat: @" src += inBounds * luminanceCheck * srcPixel * %f ;\n " , (_trueBlurRadius == 0 ) ? 1.0 : standardGaussianWeights[0 ]];
187187
188188 for (NSUInteger currentBlurCoordinateIndex = 0 ; currentBlurCoordinateIndex < numberOfOptimizedOffsets; currentBlurCoordinateIndex++)
189189 {
0 commit comments