Next: , Previous: , Up: Graphics   [Contents][Index]


5.3.11 Meshes

The (chickadee graphics mesh) modules provides procedures for programmatically creating 3D objects (to load 3D models from a file on disk, see Meshes.)

5.3.11.1 Materials

Before we talk about meshes themselves, let’s discuss “materials.” Materials control the appearance of 3D objects. Whether an object appears like a rough rock, a smooth and shiny metal, etc. depends on the material that is applied to it. Different types of materials use different lighting models. Chickadee supports two lighting models: The classic Blinn-Phong model and a more modern physically based rendering (PBR) model.

All materials share some common data:

Procedure: material? obj

Return #t if obj is a material.

Procedure: material-name material

Return the name of material.

Procedure: material-shader material

Return the shader of material.

Procedure: material-blend-mode material

Return the blend mode of material.

Procedure: material-polygon-mode material

Return the polygon mode of material.

Procedure: material-cull-face-mode material

Return the cull face mode of material.

Procedure: material-depth-test material

Return the depth test of material.

Procedure: material-stencil-test material

Return the stencil test of material.

Procedure: material-multisample? material

Return #t if material uses multisampling.

Materials support 5 textures. What each texture is used for depends on the lighting model.

Procedure: material-texture-0 material

Return the first texture of material.

Procedure: material-texture-1 material

Return the second texture of material.

Procedure: material-texture-2 material

Return the third texture of material.

Procedure: material-texture-3 material

Return the fourth texture of material.

Procedure: material-texture-4 material

Return the fifth texture of material.

For all data that is specific to the lighting model, materials have a “properties” field.

Procedure: material-properties material

Return the lighting model specific properties of material.

5.3.11.2 Blinn-Phong Materials

The (chickadee graphics phong) module has the Blinn-Phong lighting model:

Procedure: make-phong-material [#:name "anonymous"] [#:blend-mode] [#:polygon-mode] [#:cull-face-mode] [#:depth-test] [#:stencil-test] [#:multisample? #f] [#:ambient-factor (vec3 1 1 1)] [#:diffuse-factor (vec3 1 1 1)] [#:specular-factor (vec3 1 1 1)] [#:shininess 32] [#:ambient-texture] [#:diffuse-texture] [#:specular-texture] [#:normal-texture]

Return a new Blinn-Phong material.

Procedure: make-phong-properties [#:ambient] [#:diffuse] [#:specular] [#:shininess]

Return a new Blinn-Phong properties object.

Procedure: phong-properties? obj

Return #t if obj is a Blinn-Phong properties object.

Procedure: phong-properties-ambient properties

Return the ambient factor of properties.

Procedure: phong-properties-diffuse properties

Return the diffuse factor of properties.

Procedure: phong-properties-specular properties

Return the specular factor of properties.

Procedure: phong-properties-shininess properties

Return the shininess factor of properties.

5.3.11.3 PBR Materials

The (chickadee graphics pbr) module has the PBR lighting model:

Procedure: make-pbr-material [#:name "anonymous"] [#:blend-mode] [#:polygon-mode] [#:cull-face-mode] [#:depth-test] [#:stencil-test] [#:multisample? #f] [#:base-color-factor (vec3 1 1 1)] [#:base-color-texcoord 0] [#:metallic-factor 1.0] [#:roughness-factor 1.0] [#:metallic-roughness-texcoord 0] [#:normal-texcoord 0] [#:occlusion-texcoord 0] [#:emissive-factor (vec3 1 1 1)] [#:emissive-texcoord 0] [#:alpha-mode opaque] [#:alpha-cutoff 0.5] [#:base-color-texture] [#:metallic-roughness-texture] [#:normal-texture] [#:occlusion-texture] [#:emissive-texture]

Return a new PBR material.

Procedure: make-pbr-properties [#:base-color-factor] [#:base-color-texcoord] [#:metallic-factor] [#:roughness-factor] [#:metallic-roughness-texcoord] [#:normal-texcoord] [#:occlusion-texcoord] [#:emissive-factor] [#:emissive-texcoord] [#:alpha-mode] [#:alpha-cutoff]

Return a new PBR properties object.

Procedure: pbr-properties? obj

Return #t if obj is a PBR properties object.

Procedure: pbr-properties-base-color-factor properties

Return the base color factor of properties.

Procedure: pbr-properties-base-color-texcoord properties

Return the base color texture coordinate attribute index of properties.

Procedure: pbr-properties-metallic-factor properties

Return the metallic factor of properties.

Procedure: pbr-properties-roughness properties

Return the roughness factor of properties.

Procedure: pbr-properties-metallic-roughness-texcoord properties

Return the metallic-roughness texture coordinate attribute index of properties.

Procedure: pbr-properties-normal-texcoord properties

Return the normal texture coordinate attribute index of properties.

Procedure: pbr-properties-occlusion-texcoord properties

Return the ambient occlusion texture coordinate attribute index of properties.

Procedure: pbr-properties-emissive-factor properties

Return the emissive factor of properties.

Procedure: pbr-properties-emissive-texcoord properties

Return the emissive texture coordinate attribute index of properties.

Procedure: pbr-properties-alpha-mode properties

Return the alpha mode of properties.

Procedure: pbr-properties-alpha-cutoff properties

Return the alpha cutoff threshold of properties.

5.3.11.4 Primitives and Meshes

A mesh is a collection of “primitives,” so we should discuss those next. A primitive contains vertex data and a material.

Procedure: make-primitive name vertex-array material

Return a new primitive named name that renders vertex-array (see Buffers) using material.

Procedure: primitive? obj

Return #t if obj is a primitive.

Procedure: primitive-name primitive

Return the name of primitive.

Procedure: primitive-vertex-array primitive

Return the vertex array of primitive.

Procedure: primitive-material primitive

Return the material of primitive.

Okay, now we can talk about meshes, which are just a glorified list of primitive objects.

Procedure: make-mesh name primitives

Return a new mesh named name that is composed of the list primitives.

Procedure: mesh? obj

Return #t if obj is a mesh.

Procedure: mesh-name mesh

Return the name of mesh.

Procedure: mesh-primitives mesh

Return the list of primitives for mesh.

The mesh module also conveniently provides procedures to build several basic 3D shapes.

Procedure: make-plane length width material

Return a new mesh that forms a flat plane on the XZ axis that is width units long along the X axis and length units long along the Z axis.

Procedure: make-tesselated-plane length width resolution material

Return a new mesh that forms a tesselated plane on the XZ axis that is width units long along the X axis and length units long along the Z axis.

A regular plane is a single rectangle, but a tesselated plane is subdivided into many smaller rectangles by resolution. This allows for transforming the vertices in a shader to achieve effects such as waves in water or mountainous terrain.

Procedure: make-cube size material

Return a new mesh that forms a cube that is size units big.

Procedure: make-sphere radius material [#:quality 2]

Return a new mesh that forms a sphere that has a radius of radius units. Since 3D models are composed of triangles, the quality of a sphere is entirely dependent upon how many triangles are used to appromixate the shape. The higher the value of quality, the better the appromixation, but the more time it will take to generate and the more expensive it will be to draw. The number of triangles in the resulting sphere increases exponentially with each increment to quality.


Next: , Previous: , Up: Graphics   [Contents][Index]