Skip to content

Material Usage

Yuki Shimada edited this page Dec 3, 2022 · 4 revisions

Create Material

Rhodonite has many material classes. To generate them, use the MaterialHelper object.

const material = Rn.MaterialHelper.createPbrUberMaterial()

Setting shader parameters to Material

Shader parameters are done for the Material class that holds the shader.

material.setParameter(Rn.ShaderSemantics.BaseColorFactor, Rn.Vector4.fromCopy4(1, 1, 1, 1));

To pass the texture to the shader, do the following

material.setTextureParameter(Rn.ShaderSemantics.BaseColorTexture, rnTexture);

Apply Material

The created materials can be used in Primitive and MeshHelper class methods.

const primitive = Rn.Primitive.createPrimitive({
  indices: indices,
  attributeSemantics: [Rn.VertexAttribute.Position.XYZ],
  attributes: [positions],
  primitiveMode: Rn.PrimitiveMode.Lines,
});
primitive.material = mateiral;
const sphere = Rn.MeshHelper.createSphere({
    radius: 1,
    widthSegments: 10,
    heightSegments: 10,
    material: material
  })
Clone this wiki locally