File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -72,9 +72,17 @@ -(void)buildFragmentFunctions
72
72
// Perturb the screen space texture coordinate by the scaled normal
73
73
// vector.
74
74
vec2 refractTexCoords = envSpaceTexCoords.xy + normal.xy * u_refraction;
75
+
76
+ // This is positive if refractTexCoords is in [0..1] and negative otherwise.
77
+ vec2 compare = 0.5 - abs (refractTexCoords - 0.5 );
78
+
79
+ // This is 1.0 if both refracted texture coords are in bounds and 0.0 otherwise.
80
+ float inBounds = step (0.0 , min (compare.x , compare.y ));
75
81
76
82
vec4 primaryColor = cc_FragColor * texture2D (cc_MainTexture, cc_FragTexCoord1);
77
- return primaryColor * texture2D (u_envMap, refractTexCoords);
83
+ primaryColor += inBounds * texture2D (u_envMap, refractTexCoords) * (1.0 - primaryColor.a );
84
+
85
+ return primaryColor;
78
86
);
79
87
80
88
CCEffectFunction* fragmentFunction = [[CCEffectFunction alloc ] initWithName: @" refractionEffect" body: effectBody inputs: @[input] returnType: @" vec4" ];
Original file line number Diff line number Diff line change @@ -159,11 +159,12 @@ -(void)drawSprite:(CCSprite *)sprite withEffect:(CCEffect *)effect uniforms:(NSM
159
159
CCTexture *previousPassTexture = nil ;
160
160
if (previousPassRT)
161
161
{
162
+ NSAssert (previousPassRT.texture, @" Texture for render target unexpectedly nil." );
162
163
previousPassTexture = previousPassRT.texture ;
163
164
}
164
165
else
165
166
{
166
- previousPassTexture = sprite.texture ;
167
+ previousPassTexture = sprite.texture ?: [CCTexture none ] ;
167
168
}
168
169
169
170
CCEffectRenderPass* renderPass = [effect renderPassAtIndex: i];
Original file line number Diff line number Diff line change @@ -529,13 +529,22 @@ -(void) setSpriteFrame:(CCSpriteFrame*)frame
529
529
530
530
-(void ) setNormalMapSpriteFrame : (CCSpriteFrame*)frame
531
531
{
532
+ if (!self.texture )
533
+ {
534
+ // If there is no texture set on the sprite, set the sprite's texture rect from the
535
+ // normal map's sprite frame. Note that setting the main texture, then the normal map,
536
+ // and then removing the main texture will leave the texture rect from the main texture.
537
+ [self setTextureRect: frame.rect rotated: frame.rotated untrimmedSize: frame.originalSize];
538
+ }
539
+
540
+ // Set the second texture coordinate set from the normal map's sprite frame.
532
541
CCSpriteTexCoordSet texCoords = [CCSprite textureCoordsForTexture: frame.texture withRect: frame.rect rotated: frame.rotated xFlipped: _flipX yFlipped: _flipY];
533
542
_verts.bl .texCoord2 = texCoords.bl ;
534
543
_verts.br .texCoord2 = texCoords.br ;
535
544
_verts.tr .texCoord2 = texCoords.tr ;
536
545
_verts.tl .texCoord2 = texCoords.tl ;
537
546
538
- // Set the main texture in the uniforms dictionary (if the dictionary exists).
547
+ // Set the normal map texture in the uniforms dictionary (if the dictionary exists).
539
548
self.shaderUniforms [CCShaderUniformNormalMapTexture] = (frame.texture ?: [CCTexture none ]);
540
549
_renderState = nil ;
541
550
You can’t perform that action at this time.
0 commit comments