Crystal Space 2.0.0: 4.10.19.3 Furmesh Material

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

#### 4.10.19.3 Furmesh Material

Written by Alexandru - Teodor Voicu, voicualexandruteodor@gmail.com.

#### Introduction

In order to render realistic hair and fur, some special shading models had to be used, such as the ones proposed by Marschner or Kajiya and Kay. This shaders are complex Bidirectional Scattering-Surface Reflectance Distribution Functions (BSSRDF) and Bidirectional Scattering Distribution Functions (named BSDF) that use lookup textures in order to have real-time performances.

However, lookup textures have to be recalculated from time to time, mostly when parameters change, and in order to include this option an `Invalidate()` function had to be associated with the `iMaterial` interface. The easiest way to do this was to create the `iFurMeshMaterialProperties` interface, which besides giving access to a material, by `GetMaterial()` and `SetMaterial()`, also provides the `Invalidate()` method and a function that is called each frame, named `Update()`.

#### Creating Furmesh Materials

Materials can be loaded from files and registered with the `iFurMeshMaterialProperties` interface afterwards, as can be seen in the following example:

    ...
    // Load furMesh
    csRef<CS::Mesh::iFurMeshType> furMeshType =
      csQueryRegistry<CS::Mesh::iFurMeshType> (hairTest->object_reg);
    if (!furMeshType)
      return hairTest->ReportError("Failed to locate CS::Mesh::iFurMeshType plugin!");

    // Load Marschner shader
    csRef<iMaterialWrapper> materialWrapper =
      hairTest->engine->FindMaterial("marschner_material");
    if (!materialWrapper)
      hairTest->ReportError("Can't find marschner material!");
    ...
    // Create hairMeshProperties
    csRef<CS::Mesh::iFurMeshMaterialProperties> hairMeshProperties =
      furMeshType->CreateHairMeshMarschnerProperties("krsytal_marschner");

    hairMeshProperties->SetMaterial(materialWrapper->GetMaterial());
    ...
    furMesh->SetFurMeshProperties(hairMeshProperties);
    ...

This document was generated using texi2html 1.76.