マテリアルの利用 - actnwit/RhodoniteTS GitHub Wiki

Materialの作成

Rhodoniteには多くのマテリアルクラスがあります。これらを生成するには、MaterialHelperクラスを使います。

const material = Rn.MaterialHelper.createPbrUberMaterial()

Materialへのシェーダーパラメーター設定

シェーダーパラメータの設定は、そのシェーダーを保持しているMaterialクラスに対して行います。

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

テクスチャをシェーダーに渡す場合は、以下のようにします。

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

Materialの適用

作成したMaterialはPrimitiveやMeshHelperクラスのメソッド群で使用することができます。

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
  })