My favorites
▼
|
Sign in
blendmodes4flash
Pixel Bender shaders for Flash 10
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
pbk
/
BlendModeColor.pbk
r9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
.__ _____ ____ ______ ______ __ __
/\ \ /\ __`\/\ _`\ /\__ _\ /\__ _\ /\ \/\ \
\ \ \ \ \ \/\ \ \,\L\_\/_/\ \/ \/_/\ \/ \ \ `\\ \
.\ \ \ __\ \ \ \ \/_\__ \ \ \ \ \ \ \ \ \ , ` \
..\ \ \L\ \\ \ \_\ \/\ \L\ \ \ \ \ \_\ \__\ \ \`\ \
...\ \____/ \ \_____\ `\____\ \ \_\ /\_____\\ \_\ \_\
....\/___/ \/_____/\/_____/ \/_/ \/_____/ \/_/\/_/
.______ ____ ______ ______ _____ __ __ ____ ____ ____ ______ ____ ______
/\ _ \/\ _`\ /\__ _\/\__ _\ /\ __`\/\ \/\ \/\ _`\ /\ _`\ /\ _`\ /\__ _\ /\ _`\ /\__ _\
\ \ \L\ \ \ \/\_\/_/\ \/\/_/\ \/ \ \ \/\ \ \ `\\ \ \,\L\_\ \ \/\_\\ \ \L\ \/_/\ \/ \ \ \L\ \/_/\ \/
.\ \ __ \ \ \/_/_ \ \ \ \ \ \ \ \ \ \ \ \ , ` \/_\__ \\ \ \/_/_\ \ , / \ \ \ \ \ ,__/ \ \ \
..\ \ \/\ \ \ \L\ \ \ \ \ \_\ \__\ \ \_\ \ \ \`\ \/\ \L\ \ \ \L\ \\ \ \\ \ \_\ \__\ \ \/ \ \ \
...\ \_\ \_\ \____/ \ \_\ /\_____\\ \_____\ \_\ \_\ `\____\ \____/ \ \_\ \_\/\_____\\ \_\ \ \_\
....\/_/\/_/\/___/ \/_/ \/_____/ \/_____/\/_/\/_/\/_____/\/___/ \/_/\/ /\/_____/ \/_/ \/_/
Copyright (c) 2009 Lost In Actionscript - Shane McCartney
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
<languageVersion: 1.0;>
kernel BlendModeColor
<
namespace : "blendmodes";
vendor: "Lost In Actionscript";
version: 1;
description: "This blend mode uses the luminance of the top layer color and the saturation and hue of the bottom layer.";
>
{
input image4 src1;
input image4 src2;
parameter float alpha
<defaultValue:float(1.0);>;
parameter float multiply
<defaultValue:float(1.0);
minValue:float(1.0);
maxValue:float(10.0);>;
output pixel4 dst;
void evaluatePixel()
{
float2 uv = outCoord();
float4 src1Rgba = sampleLinear(src1, uv);
float4 src2Rgba = sampleLinear(src2, uv);
float src1Alpha = src1Rgba.a;
float src2Alpha = alpha*src2Rgba.a;
if(src1Alpha>0.0) src1Rgba.rgb *= 1.0/src1Rgba.a;
if(src2Alpha>0.0) src2Rgba.rgb *= 1.0/src2Rgba.a;
// RGB to HSL
// Hue / Saturation
float fmin = min(min(src2Rgba.r, src2Rgba.g), src2Rgba.b); //Min. value of RGB
float fmax = max(max(src2Rgba.r, src2Rgba.g), src2Rgba.b); //Max. value of RGB
float delta = fmax - fmin; //Delta RGB value
float3 hsl;
hsl.z = (fmax + fmin) / 2.0; // Luminance
if (delta == 0.0) //This is a gray, no chroma...
{
hsl.x = 0.0; // Hue
hsl.y = 0.0; // Saturation
}
else //Chromatic data...
{
if (hsl.z < 0.5){
hsl.y = delta / (fmax + fmin); // Saturation
} else {
hsl.y = delta / (2.0 - fmax - fmin); // Saturation
}
float deltaR = (((fmax - src2Rgba.r) / 6.0) + (delta / 2.0)) / delta;
float deltaG = (((fmax - src2Rgba.g) / 6.0) + (delta / 2.0)) / delta;
float deltaB = (((fmax - src2Rgba.b) / 6.0) + (delta / 2.0)) / delta;
if (src2Rgba.r == fmax){
hsl.x = deltaB - deltaG; // Hue
} else if (src2Rgba.g == fmax) {
hsl.x = (1.0 / 3.0) + deltaR - deltaB; // Hue
} else if (src2Rgba.b == fmax) {
hsl.x = (2.0 / 3.0) + deltaG - deltaR; // Hue
}
if (hsl.x < 0.0){
hsl.x += 1.0; // Hue
} else if (hsl.x > 1.0) {
hsl.x -= 1.0; // Hue
}
}
// Luminance
fmin = min(min(src1Rgba.r, src1Rgba.g), src1Rgba.b); //Min. value of RGB
fmax = max(max(src1Rgba.r, src1Rgba.g), src1Rgba.b); //Max. value of RGB
delta = fmax - fmin; //Delta RGB value
hsl.z = (fmax + fmin) / 2.0; // Luminance
// HSL to RGB
float4 rgba = float4(hsl.x,hsl.x,hsl.x,src2Alpha);
if (hsl.y == 0.0){
rgba.rgb = float3(hsl.z, hsl.z, hsl.z); // Luminance
} else {
float f2;
if (hsl.z < 0.5){
f2 = hsl.z * (1.0 + hsl.y);
} else {
f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);
}
float f1 = 2.0 * hsl.z - f2;
// Hue to RGB
float hue;
float rgb;
//
// Convert Red
hue = hsl.x + (1.0/3.0);
if (hue < 0.0) {
hue += 1.0;
} else if (hue > 1.0) {
hue -= 1.0;
}
if ((6.0 * hue) < 1.0){
rgb = f1 + (f2 - f1) * 6.0 * hue;
} else if ((2.0 * hue) < 1.0){
rgb = f2;
} else if ((3.0 * hue) < 2.0){
rgb = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
} else {
rgb = f1;
}
rgba.r = rgb;
//
// Convert Green
hue = hsl.x;
if (hue < 0.0) {
hue += 1.0;
} else if (hue > 1.0) {
hue -= 1.0;
}
if ((6.0 * hue) < 1.0){
rgb = f1 + (f2 - f1) * 6.0 * hue;
} else if ((2.0 * hue) < 1.0){
rgb = f2;
} else if ((3.0 * hue) < 2.0){
rgb = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
} else {
rgb = f1;
}
rgba.g = rgb;
//
// Convert Blue
hue = hsl.x - (1.0/3.0);
if (hue < 0.0) {
hue += 1.0;
} else if (hue > 1.0) {
hue -= 1.0;
}
if ((6.0 * hue) < 1.0){
rgb = f1 + (f2 - f1) * 6.0 * hue;
} else if ((2.0 * hue) < 1.0){
rgb = f2;
} else if ((3.0 * hue) < 2.0){
rgb = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
} else {
rgb = f1;
}
rgba.b = rgb;
//
}
//
rgba.rgb*=multiply;
rgba.rgb*=rgba.a;
float offsetAlpha = 1.0-src2Alpha;
dst.rgb = rgba.rgb+src1Rgba.rgb*offsetAlpha;
dst.a = min(1.0, src1Alpha+src2Alpha);
}
}
Show details
Hide details
Change log
r2
by flashdynamix on May 25, 2009
Diff
Initial commit for shader source code and swc
Go to:
/trunk/pbj
/trunk/pbj/BlendModeAdd.pbj
/trunk/pbj/BlendModeAlpha.pbj
/trunk/pbj/BlendModeAverage.pbj
/trunk/pbj/BlendModeColor.pbj
/trunk/pbj/BlendModeColorBurn.pbj
/trunk/pbj/BlendModeColorDodge.pbj
/trunk/pbj/BlendModeDarken.pbj
/trunk/pbj/BlendModeDarkerColor.pbj
/trunk/pbj/BlendModeDesaturate.pbj
/trunk/pbj/BlendModeDifference.pbj
/trunk/pbj/BlendModeDissolve.pbj
/trunk/pbj/BlendModeExclusion.pbj
/trunk/pbj/BlendModeExtrapolate.pbj
/trunk/pbj/BlendModeFreeze.pbj
/trunk/pbj/BlendModeGlow.pbj
/trunk/pbj/BlendModeHardMix.pbj
/trunk/pbj/BlendModeHardlight.pbj
/trunk/pbj/BlendModeHeat.pbj
/trunk/pbj/BlendModeHue.pbj
/trunk/pbj/BlendModeLighten.pbj
...nk/pbj/BlendModeLighterColor.pbj
/trunk/pbj/BlendModeLinearBurn.pbj
/trunk/pbj/BlendModeLinearDodge.pbj
/trunk/pbj/BlendModeLinearLight.pbj
/trunk/pbj/BlendModeLuminosity.pbj
/trunk/pbj/BlendModeMultiply.pbj
/trunk/pbj/BlendModeNegation.pbj
/trunk/pbj/BlendModeOverlay.pbj
/trunk/pbj/BlendModePhoenix.pbj
/trunk/pbj/BlendModePinLight.pbj
/trunk/pbj/BlendModeReflect.pbj
/trunk/pbj/BlendModeSaturation.pbj
/trunk/pbj/BlendModeScreen.pbj
...pbj/BlendModeSilhouetteAlpha.pbj
.../pbj/BlendModeSilhouetteLuma.pbj
/trunk/pbj/BlendModeSoftlight.pbj
/trunk/pbj/BlendModeStamp.pbj
...nk/pbj/BlendModeStencilAlpha.pbj
/trunk/pbj/BlendModeStencilLuma.pbj
/trunk/pbj/BlendModeSubtract.pbj
/trunk/pbj/BlendModeVividLight.pbj
/trunk/pbk
/trunk/pbk/BlendModeAdd.pbk
/trunk/pbk/BlendModeAlpha.pbk
/trunk/pbk/BlendModeAverage.pbk
/trunk/pbk/BlendModeColor.pbk
/trunk/pbk/BlendModeColorBurn.pbk
/trunk/pbk/BlendModeColorDodge.pbk
/trunk/pbk/BlendModeDarken.pbk
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 6419 bytes, 224 lines
View raw file
Powered by
Google Project Hosting