Skip to content

Instantly share code, notes, and snippets.

@Enhex
Last active August 20, 2017 19:48
Show Gist options
  • Save Enhex/158a37ad94cd06d6070fedbccf139c70 to your computer and use it in GitHub Desktop.
Save Enhex/158a37ad94cd06d6070fedbccf139c70 to your computer and use it in GitHub Desktop.
Urho3D render order in front
Node* planeNode = scene_->CreateChild("Plane");
planeNode->SetScale(Vector3(100.0f, 1.0f, 100.0f));
StaticModel* planeObject = planeNode->CreateComponent<StaticModel>();
planeObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
auto mat = cache->GetResource<Material>("Materials/StoneTiled.xml")->Clone();
mat->SetRenderOrder(100); // Lower render order to render first
auto tecs = mat->GetTechniques();
for (size_t i = 0; i < tecs.Size(); ++i)
{
auto tec = mat->GetTechnique(i)->Clone();
auto passes = tec->GetPasses();
for (auto pass : passes)
pass->SetDepthWrite(false);
mat->SetTechnique(i, tec);
}
planeObject->SetMaterial(mat);
Node* planeNode = scene_->CreateChild("Plane");
planeNode->SetScale(Vector3(100.0f, 1.0f, 100.0f));
StaticModel* planeObject = planeNode->CreateComponent<StaticModel>();
planeObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
auto mat = cache->GetResource<Material>("Materials/StoneTiled.xml")->Clone();
mat->SetRenderOrder(200); // Higher render order to render last
auto tecs = mat->GetTechniques();
for (size_t i = 0; i < tecs.Size(); ++i)
{
auto tec = mat->GetTechnique(i)->Clone();
auto passes = tec->GetPasses();
for (auto pass : passes)
pass->SetDepthTestMode(CMP_ALWAYS); // Always pass depth test
mat->SetTechnique(i, tec);
}
planeObject->SetMaterial(mat);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment