-
Notifications
You must be signed in to change notification settings - Fork 0
/
wine_glass.acn
executable file
·219 lines (178 loc) · 7.72 KB
/
wine_glass.acn
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
// Actinon source code: Rendering a wine-glass.
/* Copyright 2018 Johannes Bernhard Steffens
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* This script file represents a small program in Actinon-language.
* It creates an image file of name <source-file>.pnm depicting a partially
* filled wine-glass. Illumination and render parameters are set
* to demonstrate caustics produced by the glass and liquid.
*/
// Actinon language specifier
<mclosure_s></>
// This script-language was specifically designed for Actinon.
// Its basic syntax was inspired by popular languages like C, C++, Python.
// It should be easy to learn if you are familiar with one of these.
//
// Special functions and operators are provided for
// - Vector/Matrix arithmetic
// - Object -rotation, -scaling, -movement
// - Fusing objects to build composite objects.
// - Arranging objects
//
// Functions are first class objects.
// A block '{ .... }' defines a function body, which can either be assigned
// to a variable or executed immediately if followed by '()'.'
//
// For rudimentary messaging and debugging, operators '?' and '??'
// are available, which output a variable to stdout.
//
// ? - prints the full internal structure of a variable.
// ?? - prints only the value of a primitive variable.
// Examples:
// ?? "Hello World!";
// ? vec( 1, 2, 3 );
/***************************************************/
// Here we specify rendering parameters
// Keyword 'def' defines a new variable
def scene = scene_s;
scene.threads = 64;
// image parameters
scene.image_width = 400;
scene.image_height = 400;
scene.gamma = 0.9;
/** Gradient refinement:
*
* Gradient refinement serves two purposes:
* 1. Anti-aliasing by computing at sub-pixel accuracy.
* 2. Refinement of light scatter effects and path tracing effects.
*
* For each gradient cycle, the image is refined by computing
* within selected pixels 'n' random sub-pixel positions and adding the
* result to the pixel. Only sub-pixels with significant gradients to
* neighboring pixels are refined. Each refinement also re-randomizes the
* light and path-scatter adding to overall randomization and after sufficient
* converging to a smooth overall effect.
*/
scene.gradient_cycles = 100;
scene.gradient_samples = 2;
scene.gradient_threshold = 0.03;
// Ray & Path Tracing Parameters ...
// trace_depth specifies maximum amount of reflection-, refraction-
// and path-recursions to be traced.
// A path-recursion consumes 10 depth-counts, all other 1 depth-count
scene.trace_depth = 25;
scene.trace_min_intensity = 0.03;
scene.direct_samples = 200; // direct light sampling
scene.path_samples = 500; // path tracing (0=off)
// Camera Parameters ...
def camera_position = vec( 0, -10, 7 );
scene.camera_position = camera_position;
scene.camera_view_direction = vec( 0, 0, 0 ) - camera_position;
scene.camera_top_direction = vec( 0, 0, 1 );
scene.camera_focal_length = 4;
// Color values are specified in the form (red, green, blue )
scene.background_color = color( 0.4, 0.4, 0.3 );
/***************************************************/
// The code defining the scene begins here...
// Defining a function with no arguments.
def create_lights =
{
def base_light = create_sphere( 1 );
base_light.set_radiance( 40 );
base_light.set_color( color( 1.0, 1.0, 1.0 ) );
base_light.move( vec( -2, 2, 5 ) );
// The evaluation-result of the last expression defines the return value of the function.
// Here it is just the object base_light.
base_light;
};
def create_floor =
{
def plane = create_plane();
plane.set_material( "diffuse" );
plane.set_color( color( 0.8, 0.7, 0.6 ) );
plane.set_refractive_index( 1.0 );
plane.move( vec( 0, 0, -1 ) );
plane;
};
// This function creates the wine-glass
def create_glass =
{
def sphere = create_sphere( 1 );
def cover = create_plane();
def cylinder = create_cylinder( 1, 1 );
def outer_sphere = sphere;
// Operator '&' mutually composes two objects to a new object.
// Only surface area 'inside' the other object is valid.
// The complement to '&' is operator '|' where only surface
// 'outside' the other object is valid.
// Unary operator '!' swaps 'inside' and 'outside' areas of an object.
// These three operations allow the creation of arbitrarily complex 'composite-objects'
// from a suite of very few elementary objects types: sphere, plane, cylinder and cone.
def bowl = outer_sphere & ( cover + vecz( 0.6 ) );
def inner_sphere = outer_sphere * 0.96;
// If liquid exactly touches inner sphere, the renderer calculates media-transition (water<->glass) properly.
def liquid_sphere = inner_sphere;
def liquid = liquid_sphere & ( cover - vecz( 0.3 ) );
inner_sphere.move( vecz( 0.02 ) );
liquid.move( vecz( 0.02 ) );
// Unary operator '!' swaps 'inside' and 'outside' area of an object.
bowl = bowl & !inner_sphere;
// The 'envelope' is a (minimal-)sphere enclosing the entire object without touching it.
// It is neither required nor visible. But it improves render-efficiency (speed)
// by supporting the renderer in determining the boundaries of an object.
bowl. set_envelope( outer_sphere * 1.01 );
liquid.set_envelope( outer_sphere * 1.01 );
bowl.move( vecz( 2 ) );
liquid.move( vecz( 2 ) );
def neckcyl = ( cylinder * 0.08 ) & ( cover + vecz( 0.5 ) ) & !( cover - vecz( 0.5 ) );
def pearl = ( sphere * 0.15 );
// Operator '|': See comments about operator '&' above.
def neck = neckcyl | ( pearl + vecz( 0.45 ) ) | ( pearl - vecz( 0.45 ) );
neck.set_envelope( sphere * 1.2 );
neck.move( vecz( 0.55 ) );
def bottom = ( sphere * 3 ) & ( cylinder * 0.8 ) & !( cover + vecz( 2.85 ) );
bottom.set_envelope( sphere * 0.85 + vecz( 2.85 ) );
bottom.move( vecz( -2.85 ) );
def glass = ( bowl | neck | bottom );
glass.set_envelope( sphere * 1.7 + vecz( 1.5 ) );
glass.set_material( "glass" );
liquid.set_material( "water" ); // physical properties of water...
liquid.set_transparency( color( 0.177, 9.61E-6, 9.54E-7 ) ); // ... and color of red wine
def wine = glass : liquid;
// We keep a miniscule gap between glass-bottom and floor.
// This ensures that the renderer will see the glass always above the floor
// computing refractions and reflections as intended.
wine.move( vecz( -0.999 ) );
wine;
};
// This block represents the main function. This implementation finalizes the scene and computes the scene-image.
{
// 'clear' removes all objects from the scene but keeps scene parameters (rendering & camera) intact.
scene.clear(); // This is not really needed for a single image but useful for a video sequence
scene.push( create_lights() );
scene.push( create_floor() );
scene.push( create_glass() );
// output file name = source file name with appended '.pnm'
def file_name = #source_file_name + ".pnm";
scene.create_image( file_name );
}();
// The code ends here
/** Reserved key words (do not use as custom identifier)
*
* Types:
* bool, int, float, num, string, map, list, object, v3d, func
*
* Controls:
* def, for, while, if, else
*/