Skip to content

Commit 5553f06

Browse files
author
Thayer J Andrews
committed
CCEffectContrast - Fix for negative contrast values
Multiply the constant offset value, 0.5, by the input alpha value to make sure it is also in premultiplied alpha space as the RGB values are. Without this correction, input RGB values of (0,0,0) can become non-(0,0,0) when the contrast adjustment is less than 1.0.
1 parent b4fd3f5 commit 5553f06

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cocos2d/CCEffectContrast.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ -(void)buildFragmentFunctions
5454
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" initialSnippet:CCEffectDefaultInitialInputSnippet snippet:CCEffectDefaultInputSnippet];
5555

5656
NSString* effectBody = CC_GLSL(
57-
return vec4(((inputValue.rgb - vec3(0.5)) * vec3(u_contrast) + vec3(0.5)), inputValue.a);
57+
vec3 offset = vec3(0.5) * inputValue.a;
58+
return vec4(((inputValue.rgb - offset) * vec3(u_contrast) + offset), inputValue.a);
5859
);
5960

6061
CCEffectFunction* fragmentFunction = [[CCEffectFunction alloc] initWithName:@"contrastEffect" body:effectBody inputs:@[input] returnType:@"vec4"];

0 commit comments

Comments
 (0)