Basics


All noise modules must derive from the IModule interface.
public class MyModule : Luminoise.IModule { ... }

Modules generate OpenCL function code that can be strung together to form complete kernels. The IModule interface defines two methods which can be used by external classes:
string FunctionName { get; }
string GetCode() { get; }

GetCode() returns the code of the function. The signature of the method must be float _FunctionName_(__global int *p, Single3 input) .
*p is the permutation buffer, and input is the input location to operate on. Single3 is a basic structure created to make up for the lack of three dimensional types in the OpenCL 1.0 Specification.
typedef struct
{
    float x, y, z;
} Single3;
Both parameters can be used for the basic perlin noise function, which is detailed here.

An example function is provided below.
public string GetCode()
{
    return @"
float myFunction(__global int *p, Single3 input)
{
    float output = 0;
    // Perform operations here.
    return output;
}
";
}

FunctionName must return the name of the function generated by GetCode().
public string FunctionName { get { return "myFunction"; } }

Take care to avoid naming conflicts with other modules. Some of the names used in Luminoise are (for a complete list, refer to the source code):
  • cl_fBm
  • cl_ridgedmf
  • cl_turbulence
  • cl_add
  • cl_subtract
  • cl_multiply
  • cl_divide

To avoid having to hard code the function name, it is recommended to format the output of GetCode() using FunctionName.
public string GetCode()
{
    return @"
float " + FunctionName + @"(__global int *p, Single3 input)
{
    float output = 0;
    // Perform operations here.
    return output
}
";
}

Last edited Sep 13, 2010 at 4:07 AM by YellPika, version 4

Comments

No comments yet.