textures

Methods

(static) texture(settings)

Represents a texture
Parameters:
Name Type Description
settings object Texture settings
Properties
Name Type Attributes Description
name string The name/id of the texture.
url string <optional>
If supplied this url will be used to load an image for the texture.
src strirng <optional>
If supplied this glsl code string will be used to generate a texture dynamically via a fragment shader. See example below.
Source:
Examples
// check pattern dynamic texture
// set tColor to the output rgba value for the current pixel fragment

texture({
    name: 'check',
    src: `
        float s = sin(50.*uv.x)*sin(50.*uv.y);
        if(s < 0.) {
            tColor = vec4(${normedColorStr('#aaaaaa')}, 1.0);
        } else {
            tColor = vec4(0.3, 0.0, 0.0, 1.);
        }
    `
}),
// regular texture with image loaded from url

texture({
    name: 'concrete-texture',
    url: 'assets/images/concrete.jpg'
})

(static) volumeTexture(settings, data)

Represents a volume texture (sampling data for an inhomogeneous volume)
Parameters:
Name Type Description
settings object Texture settings
Properties
Name Type Attributes Description
size number Volume size (cubic)
name string The name/id of the texture.
cache bool <optional>
Whether to cache the data (useful if generated on the fly, see example 1)
data Array.<Array.<Array.<number>>> | function A 3d array containing sampling data or a function returning a 3d array with data
Source:
Example
// tiled & cached volume generated on the fly
textures = [
    volumeTexture({
        name: 'volume-texture',
        size: 64,
        cache: true,
        data: range3d(64)
            |> #.map(([x, y, z]) => {
                const scale = 50;
                let f = simplex.noise3D(x*scale, y*scale, z*scale);
                return clamp(f, 0.0, 1.0);
            })
            |> tileSeamless3d(#, 64)
    })
];

Type Definitions

geometryDisplacementMap :object

Apply texture with name 'name' as a displacement map to a SDF geometry.
Properties:
Name Type Description
name string The name of the texture as it is defined in the main texture array of the scene.
uvScale number | vec2 Texture scale as single number or per axis.
scale number The normal map scale/intensity
Source:

geometryNormalMap :object

Apply texture with name 'name' as a normal map to a regular geometry.
Properties:
Name Type Description
name string The name of the texture as it is defined in the main texture array of the scene.
uvScale number | vec2 Texture scale as single number or per axis.
scale number The normal map scale/intensity
Source:

geometryTexture :object

Apply texture with name 'name' to a geometry.
Properties:
Name Type Description
name string The name of the texture as it is defined in the main texture array of the scene.
uvScale number | vec2 Texture scale as single number or per axis.
Source: