DirectTrace  0.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Using Shaders and Materials

Using shaders will allow more flexible pipelines, as well as having a more efficient pipeline by only using one kernel call per sample as opposed to multiple kernel calls when using the predefined functionalities. In fact, most of the functionalities in the pipeline can be re-written with a shader. To write a shader for an X86 application, you just need to specify a pointer to a function that processes a single pixel/ray, and an array of images the shader will be applied to. The library will do the rest. OpenCL shaders work similarly to this, but you will have to provide an OpenCL function string that will need to be compiled first.
Shaders can be specified for DTImage and DTRayBuffer classes (support for DTTexture is not decided yet). With an image, the shader will apply the same function to all the pixels. RayBuffer shaders work only on the active rays of the RayBuffer variable. According to the needs, they also allow to de-activate some rays in the buffer by returning 0 (i.e., false) if some conditions of your choice are met.

images:
Cloning images will be required if you want to modify a specific component of a RayBuffer instance in your shader (i.e., either a direction or a center). This can be done by writing something similar to:

Shader may also be tricky from time to time. here is a few lists of problems that may occur and generates bugs:
If your Image shader needs to read a pixel, make sure its content has been set before. This may not be true if you have run a RayBuffer shader before that only applies to active rays. Best way to ensure this is to always initialize the image with a constant value (e.g., 0).
Also, do not forget that all buffers and images should have the same dimensions. If not, images can be resized to match the caller's dimensions in some circumstances (if they are accessed in write-only mode). Resizing will re-init the content of the non-matching images, and is likely to generate bugs if one of these unmatching buffers is actually a member of a RayBuffer class (i.e., either a direction or a center, without both being used by the shader).



Images are ray buffers are a usefull way to pack information regarding sampled data. In some cases, it can be useful to merge several of those buffers into one. For this purpose, several variants of a MergeWith operator are available, providing different levels of flexibility. For instance, several buffers may be used to aggregate sampled data.

See also:
MergeWith