... | ... | @@ -130,7 +130,7 @@ Creates a sphere of radius ```r``` centered on ```c```. ```sphere(r)``` is synta |
|
|
```cube(dx, dy, dz)```
|
|
|
|
|
|
Creates a cube with with sides ```dx```, ```dy```, ```dz``` with its bottom face centered on the origin. ```cube(d)``` and ```cube(v)``` are syntactic sugars for ```cube(d,d,d)``` and ```cube(v.x,v.y,v.z)``` respectively.
|
|
|
* ```dx```: length of the face perdendicular to the X-axis
|
|
|
* ```dx```: length of the face perpendicular to the X-axis
|
|
|
* ```dy```: length of the face perpendicular to the Y-axis
|
|
|
* ```dz```: length of the face perpendicular to the Z-axis
|
|
|
|
... | ... | @@ -150,7 +150,7 @@ Creates a cylinder with radius ```r```, base center ```c0``` and top center ```c |
|
|
|
|
|
Creates a polyhedron with ```points``` as its vertex and ```indices``` to specify its faces.
|
|
|
* ```points```: an array of vectors containing the polyhedron's vertex
|
|
|
* ```indices```: an array of vectors specifying the polyhedron's faces. Each vector specifies a face constructed from three vertex indices represented by the vector's compotnents. Indices start from 0 and faces point outwards whenever the orientation of the vertices to which the indices refer to is counterclockwise.
|
|
|
* ```indices```: an array of vectors specifying the polyhedron's faces. Each vector specifies a face constructed from three vertex indices represented by the vector's components. Indices start from 0 and faces point outwards whenever the orientation of the vertices to which the indices refer to is counterclockwise.
|
|
|
|
|
|
<table>
|
|
|
<tr>
|
... | ... | @@ -259,7 +259,7 @@ emit( rotate_extrude( triangle, 100 ) ) |
|
|
|
|
|
```sections_extrude(contours)```
|
|
|
|
|
|
Crates a closed object by conecting each polygon contained in ```contours```. Similar to the functions above, a polygon is defined as a table of at least three points. ```contours``` is a table of more than one polygon and all polygons must contain the same number of points.
|
|
|
Crates a closed object by connecting each polygon contained in ```contours```. Similar to the functions above, a polygon is defined as a table of at least three points. ```contours``` is a table of more than one polygon and all polygons must contain the same number of points.
|
|
|
|
|
|
<table>
|
|
|
<tr>
|
... | ... | @@ -302,7 +302,7 @@ IceSL supports implicits by way of the [GL Shading Language](https://www.khronos |
|
|
Creates an object out of the [implicit geometry](https://en.wikipedia.org/wiki/Implicit_function) calculated in ```fragment```. The bounding box constructed by ```boxMin``` and ```boxMax``` defines the boundaries of the implicit shape.
|
|
|
* ```boxMin, boxMax```: domain of the implicit. The domain is specified by the box constructed with corners ```boxMin``` and ```boxMax```
|
|
|
* ```voxSize```: voxel output size. Lower values result in greater quality at the expense of higher calculation costs.
|
|
|
* ```fragment```: string containing the GLSL progam. This program calculates the implicit function that defines the output geometry.
|
|
|
* ```fragment```: string containing the GLSL program. This program calculates the implicit function that defines the output geometry.
|
|
|
|
|
|
Implicits are calculated in IceSL with a sphere tracing method (detailed [here](http://graphics.cs.illinois.edu/sites/default/files/zeno.pdf)). The program specified in ```fragment``` must contain a function called either ```float distance(vec3 p)```, in the case of ```implicit_distance_field```, or ```float solid(vec3 p)``` in the case of ```implicit_solid```. This function calculates the distance field or the solid/empty classification respectively for every point of the domain of the box. A resulting negative value is interpreted as _solid_ whereas a positive value means _hollow_. Consider the following example.
|
|
|
|
... | ... | @@ -329,4 +329,148 @@ emit (cube) |
|
|
|
|
|
Above, every point in the domain of the implicit is marked as _solid_, therefore the geometry created has the shape of the boundary box.
|
|
|
|
|
|
Choosing ```implicit_distance_field``` over ```implicit_solid``` can be summarized as follows: The former requires to estimate a distance to the surface, which can prove difficult and prone to artifacts (when the estimate is too far off from reality). The latter is much easier, as the function simply has to return negative for solid and positive for empty. |
|
|
\ No newline at end of file |
|
|
Choosing ```implicit_distance_field``` over ```implicit_solid``` can be summarized as follows: The former requires to estimate a distance to the surface, which can prove difficult and prone to artifacts (when the estimate is too far off from reality). The latter is much easier, as the function simply has to return negative for solid and positive for empty.
|
|
|
|
|
|
### Progressive rendering
|
|
|
|
|
|
IceSL by default progressively renders implicits, consequently all the implicit's geometry may not render in one single frame. The order of rendering is defined by the distance to the camera (i.e. scene's point of view). To disable/enable this behavior use the following:
|
|
|
|
|
|
```enable_progressive_rendering(shape, bool)```
|
|
|
* ```shape```: output from either the ```implicit_*``` or ```to_voxel_*``` functions.
|
|
|
* ```bool```: either ```true``` or ```false```
|
|
|
|
|
|
This setting must be set right after the implicit/voxels creation. This is because IceSL clones a shape whenever it is transformed and/or reassigned to another variable. Each clone drags with it the '''current''' value of this setting.
|
|
|
|
|
|
### Uniform variables and file support
|
|
|
|
|
|
It is possible to set values for uniform variables specified inside the implicit's GLSL program via lua commands.
|
|
|
|
|
|
```set_uniform_{boolean|scalar|vector|matrix|texture3d}(implicit, var_name, var_value)```
|
|
|
|
|
|
sets ```var_name``` to ```var_value``` inside ```implicit```.
|
|
|
* ```implicit```: a created implicit
|
|
|
* ```var_name```: string specifying the name of the uniform variable in the implicit
|
|
|
* ```var_value```: new boolean/scalar/vector/matrix/texture3d/voxel_distance_field value
|
|
|
|
|
|
Furthermore, implicits can be loaded directly from files as the next function shows.
|
|
|
|
|
|
```implicit_distance_field_from_file(boxMin, boxMax, fileName)```
|
|
|
|
|
|
```implicit_solid_from_file(boxMin, boxMax, voxSize, fileName)```
|
|
|
|
|
|
Similar to ```implicit_distance_field``` and ```implicit_solid``` but the fragment program is in ```fileName```.
|
|
|
* ```boxMin, boxMax```: domain of the implicit. The domain is specified by the box constructed with corners ```boxMin``` and ```boxMax```
|
|
|
* ```fileName```: file containing the GLSL implicit program.
|
|
|
* ```voxSize```: voxel output size.
|
|
|
|
|
|
|
|
|
In the next example, we create an implicit whose points inside an origin-centered sphere are considered solid. The radius of the sphere is changed using ```set_uniform_scalar```.
|
|
|
|
|
|
<table>
|
|
|
<tr>
|
|
|
<td>
|
|
|
|
|
|
```lua
|
|
|
sphere = implicit_solid(v(-10,-10,-10), v(10,10,10), 0.25,
|
|
|
[[
|
|
|
uniform float r = 5;
|
|
|
float solid(vec3 p) {
|
|
|
return length(p) - r;
|
|
|
}
|
|
|
]])
|
|
|
set_uniform_scalar(sphere, 'r', 10.5)
|
|
|
emit(sphere)
|
|
|
```
|
|
|
|
|
|
</td>
|
|
|
<td>
|
|
|
<img src="uploads/ae21547d9fbf2d1199d8ce753f9441e8/Example_implicit_2.png" width="200">
|
|
|
</td>
|
|
|
</tr>
|
|
|
</table>
|
|
|
|
|
|
Notice how in the above example, the implicit boundary cuts off some parts of the sphere. Implicits are commonly used to construct geometry that is impossible to create with CSG or low-resolution meshes. See the following example.
|
|
|
|
|
|
<table>
|
|
|
<tr>
|
|
|
<td>
|
|
|
|
|
|
```lua
|
|
|
shape = implicit_distance_field(v(-2,-2,0), v(2,2,8),
|
|
|
[[
|
|
|
float distance(vec3 p) {
|
|
|
return 0.01 * ((pow(sqrt(p.x*p.x + p.y*p.y) - 3, 3) + p.z*p.z - 1) + noise(p));
|
|
|
}
|
|
|
]])
|
|
|
emit(scale(5) * shape)
|
|
|
```
|
|
|
|
|
|
</td>
|
|
|
<td>
|
|
|
<img src="uploads/06292b311081b3b4ba6f77fe2aa7c356/Example_implicit_3.png" width="200">
|
|
|
</td>
|
|
|
</tr>
|
|
|
</table>
|
|
|
|
|
|
### 3D Textures
|
|
|
IceSL features the ability to construct 3D textures programmatically. There is support for single channel textures as well as RGB textures in 8bit and 32bit variants.
|
|
|
|
|
|
```tex3d_{rgb32f|r32f|rgb8f|r8f}(w,h,d)```
|
|
|
|
|
|
Creates a 3d texture class with the following possible specifications:
|
|
|
* ```rgb32f```: rgb 32bit float texture
|
|
|
* ```r32f```: luminance 32bit float texture
|
|
|
* ```rgb8f```: rgb 8bit float texture
|
|
|
* ```r8f```: luminance 8bit float texture
|
|
|
|
|
|
The 3D texture class possesses the following methods:
|
|
|
* ```w()```: return the texture's width
|
|
|
* ```h()```: return the texture's height
|
|
|
* ```d()```: return the texture's depth
|
|
|
* ```set(u,v,w,val)```: sets the value ```val``` at texture coordinate ```(u,v,w)```
|
|
|
|
|
|
The following example shows a 1-channel 3D texture created programmatically and used as input in an implicit. Two solid cubes (one on each corner) made of the value ```-1.0``` are drawn into the texture while the rest is left at value ```10.0```. The implicit maps each point of the implicit area to a point of the texture repeated twice.
|
|
|
|
|
|
<table>
|
|
|
<tr>
|
|
|
<td>
|
|
|
|
|
|
```lua
|
|
|
tex_dim = v(10,10,10)
|
|
|
tex = tex3d_r32f(tex_dim.x,tex_dim.y,tex_dim.z)
|
|
|
for ucoord = 0, tex_dim.x-1 do
|
|
|
for vcoord = 0, tex_dim.y-1 do
|
|
|
for wcoord = 0, tex_dim.z-1 do
|
|
|
if (ucoord < tex_dim.x/2 and vcoord < tex_dim.y/2 and wcoord < tex_dim.z/2) or
|
|
|
(ucoord >= tex_dim.x/2 and vcoord >= tex_dim.y/2 and wcoord >= tex_dim.z/2) then
|
|
|
tex:set(ucoord,vcoord,wcoord,v(-1.0,0.0,0.0))
|
|
|
else
|
|
|
tex:set(ucoord,vcoord,wcoord,v(10.0,0.0,0.0))
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
imp_dim = v(20,20,20)
|
|
|
imp = implicit_distance_field(v(0,0,0), imp_dim,
|
|
|
[[
|
|
|
uniform sampler3D tex_data;
|
|
|
uniform vec3 imp_ext;
|
|
|
float distance(vec3 p)
|
|
|
{
|
|
|
return 0.01 * texture(tex_data,(p/imp_ext)*2.0).x;
|
|
|
}
|
|
|
]])
|
|
|
set_uniform_vector(imp, 'imp_ext', imp_dim)
|
|
|
set_uniform_texture3d(imp, 'tex_data', tex)
|
|
|
|
|
|
emit(imp)
|
|
|
|
|
|
```
|
|
|
|
|
|
</td>
|
|
|
<td>
|
|
|
<img src="uploads/ad5c9dcb1ccff2a925dc5061f1e4cbd4/Example_3dtex.png" width="200">
|
|
|
</td>
|
|
|
</tr>
|
|
|
</table> |
|
|
\ No newline at end of file |