@@ -45,22 +45,23 @@ -(void)buildFragmentFunctions
45
45
46
46
NSString * effectBody = CC_GLSL (
47
47
48
+ vec4 outputColor = vec4 (0.0 );
48
49
// Make the color values to go from [-1, 1].
49
50
vec4 distanceField = 2.0 * texture2D (cc_MainTexture, cc_FragTexCoord1) - 1.0 ;
50
51
vec4 fw = fwidth (distanceField);
51
52
vec4 mask = smoothstep (-fw, fw, distanceField);
52
53
53
- float distAlphaMask = distanceField.a ;
54
+ float distAlphaMask = distanceField.r ;
54
55
// outline
55
56
const float min0 = 0.0 ;
56
- const float min1 = 0.4 ;
57
+ const float min1 = 0.0 ;
57
58
const float max0 = 0.4 ;
58
- const float max1 = 0.9 ;
59
+ const float max1 = 0.8 ;
59
60
60
61
bool less = distAlphaMask >= min0;
61
62
bool more = distAlphaMask <= max1;
62
63
63
- if (less && more)
64
+ if (less && more && false ) // outline
64
65
{
65
66
float oFactor = 1.0 ;
66
67
if (distAlphaMask <= min1)
@@ -72,28 +73,50 @@ -(void)buildFragmentFunctions
72
73
oFactor = smoothstep (max1, max0, distAlphaMask);
73
74
}
74
75
75
- mask = vec4 ( 1.0 , 0.0 , 0.0 , 1.0 ); // mix(mask, vec4(1.0, 1 .0, 0.0, 1.0), oFactor);
76
+ mask = mix (mask, vec4 (1.0 , 0 .0 , 0.0 , 1.0 ), oFactor);
76
77
77
78
}
78
79
79
- if (distAlphaMask >= 0.5 )
80
- mask.a = 1.0 ;
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
+ }
81
88
else
82
- mask.a = 0.0 ;
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
+ }
83
101
84
102
85
103
86
- if (false ) {
87
- vec4 glowTexel = texture2D (cc_MainTexture, cc_FragTexCoord1);
88
- vec4 glowc = vec4 (1.0 , 0.0 , 0.0 , 1.0 ) * smoothstep (0.0 , 0.0 , glowTexel.a );
89
-
90
- distanceField = mix (glowc, distanceField, mask);
91
-
92
- vec4 outputColor = distanceField;
104
+ if (true ) {
105
+ 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 );
107
+
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;
93
117
}
94
118
95
-
96
- return mask;
119
+ return outputColor;
97
120
);
98
121
99
122
CCEffectFunction* fragmentFunction = [[CCEffectFunction alloc ] initWithName: @" outerGlowEffect"
0 commit comments