root/as3/Astro/RadialBlur/src/RadialBlur.pbk

リビジョン 1540, 4.7 kB (コミッタ: muta, コミット時期: 3 年 前)

PixelBender? のサンプル.

Line 
1 /*
2  * Copyright 2008 (c) muta
3  *
4  * http://unbland.net/
5  * http://unbland.net/blog/
6  *
7  * Licensed under the MIT License
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  */
27 <languageVersion : 1.0;>
28 kernel RadialBlur
29 <
30     namespace   : "org.unbland";
31     vendor      : "muta";
32     version     : 1;
33 >
34 {
35     parameter float2 center
36     <
37         minValue     : float2(1.0, 1.0);
38         maxValue     : float2(4096.0, 4096.0);
39         //defaultValue : float2(1.0, 1.0);
40         defaultValue : float2(160.0, 160.0);
41     >;
42    
43     parameter float amount
44     <
45         minValue     : float(1.0);
46         maxValue     : float(100.0);
47         defaultValue : float(1.0);
48     >;
49    
50     parameter float rotation
51     <
52         minValue     : float(-90.0);
53         maxValue     : float(90.0);
54         defaultValue : float(0.0);
55     >;
56    
57     input  image4 source;
58     output pixel4 result;
59
60     void evaluatePixel()
61     {
62         float  numSamples = 9.0;
63         float  base = 4.0;
64         float2 coord = outCoord();
65         float2 dist = coord - center;
66         float  radian = atan(dist.y, dist.x) + radians(rotation);
67         float  rate = amount / 200.0 * length(dist) / numSamples;
68         float2 n = float2(cos(radian), sin(radian));
69        
70         float  d;
71         float2 p;
72         float4 c;
73        
74         float4 color = float4(0.0, 0.0, 0.0, 1.0);
75         float  w = 0.0;
76        
77         d = (0.0 - base) * rate;
78         p.x = d * n.x + coord.x;
79         p.y = d * n.y + coord.y;
80         c = sampleNearest(source, p);
81        
82         if (c.a != 0.0)
83         {
84             color += c;
85             w += 1.0;
86         }
87        
88         d = (1.0 - base) * rate;
89         p.x = d * n.x + coord.x;
90         p.y = d * n.y + coord.y;
91         c = sampleNearest(source, p);
92        
93         if (c.a != 0.0)
94         {
95             color += c;
96             w += 1.0;
97         }
98        
99         d = (2.0 - base) * rate;
100         p.x = d * n.x + coord.x;
101         p.y = d * n.y + coord.y;
102         c = sampleNearest(source, p);
103        
104         if (c.a != 0.0)
105         {
106             color += c;
107             w += 1.0;
108         }
109        
110         d = (3.0 - base) * rate;
111         p.x = d * n.x + coord.x;
112         p.y = d * n.y + coord.y;
113         c = sampleNearest(source, p);
114        
115         if (c.a != 0.0)
116         {
117             color += c;
118             w += 1.0;
119         }
120        
121         d = (4.0 - base) * rate;
122         p.x = d * n.x + coord.x;
123         p.y = d * n.y + coord.y;
124         c = sampleNearest(source, p);
125        
126         if (c.a != 0.0)
127         {
128             color += c * 3.0;
129             w += 3.0;
130         }
131        
132         d = (5.0 - base) * rate;
133         p.x = d * n.x + coord.x;
134         p.y = d * n.y + coord.y;
135         c = sampleNearest(source, p);
136        
137         if (c.a != 0.0)
138         {
139             color += c;
140             w += 1.0;
141         }
142        
143         d = (6.0 - base) * rate;
144         p.x = d * n.x + coord.x;
145         p.y = d * n.y + coord.y;
146         c = sampleNearest(source, p);
147        
148         if (c.a != 0.0)
149         {
150             color += c;
151             w += 1.0;
152         }
153        
154         d = (7.0 - base) * rate;
155         p.x = d * n.x + coord.x;
156         p.y = d * n.y + coord.y;
157         c = sampleNearest(source, p);
158        
159         if (c.a != 0.0)
160         {
161             color += c;
162             w += 1.0;
163         }
164        
165         d = (8.0 - base) * rate;
166         p.x = d * n.x + coord.x;
167         p.y = d * n.y + coord.y;
168         c = sampleNearest(source, p);
169        
170         if (c.a != 0.0)
171         {
172             color += c;
173             w += 1.0;
174         }
175        
176         result = color / w;
177     }
178 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。