Materials
Rin supports two types of materials, those used in the scene graph mode, which live in the rin::material
module and those used in immediate mode which depend on the specific renderer so right now they are in rin::gl
.
In the future these might be unified so the same materials can be used for both modes but the very different ways in which this two modes work makes that difficult to achieve without turning the gl::Renderer
or any other future renderer into a much more complex part than it is right now.
Scene graph materials
Let's see first how to use the scene graph materials. Indeed we've used them already in the first app chapter. Let's review the basics.
First of all, in order to use a material we need to create it, usually through it's corresponding builder, with whatever attributes we want to use, then register it in the scene, which returns a handle to it and finally use that handle when creating models to assign them the material we just created. This is the way we created a material and assigned it to a model in the first app example:
// Create a cube geometry and register it in the scene so we can use it later.
// as a return value we get it's entity id
let cube = scene.register_mesh(rin::graphics::cube(1.));
// Create a new material of with a red color
let red_material = StandardMaterialBuilder::default()
.color(RED)
.build();
// Register the material and get a handle to it
let red_material = scene.register_material(
"RedMaterial",
red_material
);
// Create a model using the previously created material and geometry at the origin
scene.add_model("Cube")
.geometry(cube)
.material(red_material)
.dynamic_transformation(pnt3!(0., 0.5, 0.))
.add(Velocity(vec3(0.1, 0., 0.)))
.build();
Most materials are used in more or less the same way but let's review the materials available by default in rin and how to create our own.
Standard material
This is probably the most common material, it behaves like a non-metallic or metallic material depending on it's metallic property value and it's parameters are:
base_color
: Defines the color of the material