opengtl / shiva-collections (http://opengtl.org/)
No description has been added.
Clone this repository (size: 64.0 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/opengtl/shiva-collections/
| commit 28: | e70566ce05d1 |
| parent 27: | b2452973f303 |
| branch: | default |
add a single ball generator
5 months ago
Changed (Δ1.5 KB):
raw changeset »
generators/Singleball.shiva (62 lines added, 0 lines removed)
Up to file-list generators/Singleball.shiva:
1 |
< |
|
2 |
parameters: < |
|
3 |
xcenter: < |
|
4 |
label: "Center x"; |
|
5 |
type: float; |
|
6 |
>; |
|
7 |
ycenter: < |
|
8 |
label: "Center y"; |
|
9 |
type: float; |
|
10 |
>; |
|
11 |
radius: < |
|
12 |
label: "Radius"; |
|
13 |
type:float; |
|
14 |
defaultValue: 0.1; |
|
15 |
>; |
|
16 |
ringradius: < |
|
17 |
label: "Ring radius"; |
|
18 |
type:float; |
|
19 |
defaultValue: 0.05; |
|
20 |
>; |
|
21 |
outsidecolor: < |
|
22 |
label: "Outside color"; |
|
23 |
type: rgba; |
|
24 |
defaultValue: { 0.0, 0.0, 0.0, 1.0 }; |
|
25 |
>; |
|
26 |
ballcolor: < |
|
27 |
label: "Ball color"; |
|
28 |
type: rgba; |
|
29 |
defaultValue: { 0.0, 1.0, 0.0, 1.0 }; |
|
30 |
>; |
|
31 |
||
32 |
>; |
|
33 |
>; |
|
34 |
kernel Singleball |
|
35 |
{ |
|
36 |
const float2 center = { IMAGE_WIDTH * xcenter, IMAGE_HEIGHT * ycenter }; |
|
37 |
dependent float pxradius, pxringradius; |
|
38 |
void evaluateDependents() |
|
39 |
{ |
|
40 |
int image_size = min(IMAGE_WIDTH, IMAGE_HEIGHT); |
|
41 |
pxradius = radius * image_size; |
|
42 |
pxringradius = ringradius * image_size; |
|
43 |
} |
|
44 |
void evaluatePixel(out pixel4 result) |
|
45 |
{ |
|
46 |
float2 vec = result.coord - center; |
|
47 |
float angle = atan2( vec.x, vec.y); |
|
48 |
float r = length(vec); |
|
49 |
if(r < pxradius or r > (pxradius + pxringradius)) |
|
50 |
{ |
|
51 |
result = outsidecolor; |
|
52 |
} else { |
|
53 |
float v = (r - pxradius) / pxringradius; |
|
54 |
result = (1.0 - v) * ballcolor + v * outsidecolor; |
|
55 |
} |
|
56 |
} |
|
57 |
region generated() |
|
58 |
{ |
|
59 |
region reg = { 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT}; |
|
60 |
return reg; |
|
61 |
} |
|
62 |
} |
