Urho3D Wiki
(Created page with "== Customize materials (per code) & different materials per model == Normally you assign materials like this: <syntaxhighlight lang="cpp"> StaticModel* boxObject=boxNode_->Cr...")
Tags: Visual edit apiedit
 
No edit summary
Tags: Visual edit apiedit
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Customize materials (per code) & different materials per model ==
 
 
Normally you assign materials like this:
 
Normally you assign materials like this:
   

Latest revision as of 03:51, 21 February 2016

Normally you assign materials like this:

StaticModel* boxObject=boxNode_->CreateComponent<StaticModel>();
boxObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
boxObject->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));

You can also load materials, copy them, and/or change parameters:

Material* mat1=cache->GetResource<Material>("Materials/Stone.xml");
Material* mat2=mat1->Clone();    // copy material
// change the ciffuse color
mat2->SetShaderParameter("MatDiffColor",Color(0.1,0.4,0.9));
boxObject->SetMaterial(mat2);

You can use this to make every model unique by randomizing colors or color models in a team color. You can also pass custom parameters to control things like current weather or different (localized) lighting scenes.

An example of 400 uniquely colored cubes:

Copy material