@@ -44,79 +44,33 @@ -(void)buildFragmentFunctions
44
44
self.fragmentFunctions = [[NSMutableArray alloc ] init ];
45
45
46
46
NSString * effectBody = CC_GLSL (
47
+ // works with DistanceFieldX.png
47
48
48
- vec4 outputColor = vec4 (0.0 );
49
- // Make the color values to go from [-1, 1].
50
- vec4 distanceField = 2.0 * texture2D (cc_MainTexture, cc_FragTexCoord1) - 1.0 ;
51
- vec4 fw = fwidth (distanceField);
52
- vec4 mask = smoothstep (-fw, fw, distanceField);
49
+ vec4 outputColor = vec4 (0.0 , 0.0 , 0.0 , 1.0 );
50
+ float distAlphaMask = texture2D (cc_MainTexture, cc_FragTexCoord1).r ;
53
51
54
- float distAlphaMask = distanceField.r ;
55
- // outline
56
- const float min0 = 0.0 ;
57
- const float min1 = 0.0 ;
58
- const float max0 = 0.4 ;
59
- const float max1 = 0.8 ;
52
+ float center = 0.46 ;
53
+ float transition = fwidth (distAlphaMask) * 1.0 ;
60
54
61
- bool less = distAlphaMask >= min0;
62
- bool more = distAlphaMask <= max1;
63
-
64
- if (less && more && false ) // outline
65
- {
66
- float oFactor = 1.0 ;
67
- if (distAlphaMask <= min1)
68
- {
69
- oFactor = smoothstep (min0, min1, distAlphaMask);
70
- }
71
- else
72
- {
73
- oFactor = smoothstep (max1, max0, distAlphaMask);
74
- }
75
-
76
- mask = mix (mask, vec4 (1.0 , 0.0 , 0.0 , 1.0 ), oFactor);
77
-
78
- }
79
-
80
- if (false ) // soft edges
81
- {
82
- const float min = 0.2 ;
83
- const float max = 0.8 ;
84
- distanceField.r *= smoothstep (min, max, distAlphaMask);
85
- distanceField.g *= smoothstep (min, max, distAlphaMask);
86
- distanceField.b *= smoothstep (min, max, distAlphaMask);
87
- }
88
- else
89
- {
90
- if (distAlphaMask >= 0.5 )
91
- {
92
- // distanceField.a = 1.0;
93
- distanceField.rgb = vec3 (1.0 );
94
- }
95
- else
96
- {
97
- // distanceField.a = 0.0;
98
- distanceField.rgb = vec3 (0.0 );
99
- }
100
- }
55
+ float min = center - transition;
56
+ float max = center + transition;
101
57
58
+ // soft edges
59
+ outputColor.a *= smoothstep (min, max, distAlphaMask);
102
60
103
-
104
- if (true ) {
61
+ // glow
62
+ if (true )
63
+ {
105
64
vec4 glowTexel = texture2D (cc_MainTexture, cc_FragTexCoord1);
106
- vec4 glowc = vec4 (1.0 , 0.0 , 0.0 , 1.0 ) * smoothstep (0.2 , 0.4 , glowTexel.r );
65
+ min -= 0.09 ;
66
+ max -= 0.05 ;
67
+ vec4 glowc = u_glowColor * smoothstep (min, max, glowTexel.r );
107
68
108
- distanceField = mix (glowc, distanceField, mask);
109
- }
110
- // else
111
- {
112
- outputColor.r = distanceField.r + (1.0 - distanceField.r ) * mask.r ;
113
- outputColor.g = distanceField.g + (1.0 - distanceField.g ) * mask.g ;
114
- outputColor.b = distanceField.b + (1.0 - distanceField.b ) * mask.b ;
115
- outputColor.a = distanceField.a ;
116
- // outputColor = distanceField + mask;
69
+ outputColor = mix (glowc, outputColor, outputColor.a );
117
70
}
118
71
119
72
return outputColor;
73
+
120
74
);
121
75
122
76
CCEffectFunction* fragmentFunction = [[CCEffectFunction alloc ] initWithName: @" outerGlowEffect"
0 commit comments