Skip to content

Commit 9e78c32

Browse files
author
Thayer J Andrews
committed
CCEffects - Fix stacking of refraction, reflection, and glass
These were all directly reading cc_MainTexture and combining it with cc_FragColor within their function bodies instead of putting this into their input snippets. In simpler terms this means that input values from previous effects were not being used.
1 parent ad31d22 commit 9e78c32

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

cocos2d/CCEffectGlass.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ -(void)buildFragmentFunctions
7676
{
7777
self.fragmentFunctions = [[NSMutableArray alloc] init];
7878

79-
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
79+
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"cc_FragColor * texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
8080

8181
NSString* effectBody = CC_GLSL(
8282
// Index the normal map and expand the color value from [0..1] to [-1..1]
@@ -128,7 +128,7 @@ -(void)buildFragmentFunctions
128128

129129

130130
// Compute the combination of the sprite's color and texture.
131-
vec4 primaryColor = cc_FragColor * texture2D(cc_MainTexture, cc_FragTexCoord1);
131+
vec4 primaryColor = inputValue;
132132

133133
// If the refracted texture coordinates are within the bounds of the environment map
134134
// blend the primary color with the refracted environment. Multiplying by the normal

cocos2d/CCEffectReflection.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ -(void)buildFragmentFunctions
6464
{
6565
self.fragmentFunctions = [[NSMutableArray alloc] init];
6666

67-
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
67+
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"cc_FragColor * texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
6868

6969
NSString* effectBody = CC_GLSL(
7070
// Compute environment space texture coordinates from the screen space
@@ -92,7 +92,7 @@ -(void)buildFragmentFunctions
9292
reflectTexCoords.y = (1.0 - cos(reflectTexCoords.y * M_PI)) * 0.5;
9393

9494
// Compute the combination of the sprite's color and texture.
95-
vec4 primaryColor = cc_FragColor * texture2D(cc_MainTexture, cc_FragTexCoord1);
95+
vec4 primaryColor = inputValue;
9696

9797
float fresnel = max(u_fresnelBias + (1.0 - u_fresnelBias) * pow((1.0 - nDotV), u_fresnelPower), 0.0);;
9898

cocos2d/CCEffectRefraction.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ -(void)buildFragmentFunctions
6363
{
6464
self.fragmentFunctions = [[NSMutableArray alloc] init];
6565

66-
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
66+
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"cc_FragColor * texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
6767

6868
NSString* effectBody = CC_GLSL(
6969
// Compute environment space texture coordinates from the screen space
@@ -89,7 +89,7 @@ -(void)buildFragmentFunctions
8989
float inBounds = step(0.0, min(compare.x, compare.y));
9090

9191
// Compute the combination of the sprite's color and texture.
92-
vec4 primaryColor = cc_FragColor * texture2D(cc_MainTexture, cc_FragTexCoord1);
92+
vec4 primaryColor = inputValue;
9393

9494
// If the refracted texture coordinates are within the bounds of the environment map
9595
// blend the primary color with the refracted environment. Multiplying by the normal

0 commit comments

Comments
 (0)