Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending simple_demo to include render order #190

Merged
merged 7 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion examples/simple_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ void buildScene(ScenePtr _scene)
center->SetMaterial(green);
root->AddChild(center);


//! [red material]
// create red material
MaterialPtr red = _scene->CreateMaterial();
red->SetAmbient(0.5, 0.0, 0.0);
red->SetDiffuse(1.0, 0.0, 0.0);
red->SetSpecular(0.5, 0.5, 0.5);
red->SetShininess(50);
red->SetReflectivity(0);
red->SetRenderOrder(3);
//! [red material]

// create sphere visual
VisualPtr sphere = _scene->CreateVisual();
Expand Down Expand Up @@ -116,12 +118,15 @@ void buildScene(ScenePtr _scene)
box->SetMaterial(blue);
root->AddChild(box);

//! [white material]
// create white material
MaterialPtr white = _scene->CreateMaterial();
white->SetAmbient(0.5, 0.5, 0.5);
white->SetDiffuse(0.8, 0.8, 0.8);
white->SetReceiveShadows(true);
white->SetReflectivity(0);
white->SetRenderOrder(0);
//! [white material]

// create plane visual
VisualPtr plane = _scene->CreateVisual();
Expand All @@ -131,6 +136,15 @@ void buildScene(ScenePtr _scene)
plane->SetMaterial(white);
root->AddChild(plane);

// create plane visual
VisualPtr plane2 = _scene->CreateVisual();
plane2->AddGeometry(_scene->CreatePlane());
plane2->SetLocalScale(5, 8, 1);
plane2->SetLocalPosition(4, 0.5, -0.5);
plane2->Scale(0.1, 0.1, 1);
plane2->SetMaterial(red);
root->AddChild(plane2);

// create axis visual
VisualPtr axis = _scene->CreateAxisVisual();
axis->SetLocalPosition(4.0, 0.5, -0.4);
Expand Down
4 changes: 4 additions & 0 deletions include/ignition/rendering/MeshDescriptor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ namespace ignition
public: const common::Mesh *mesh = nullptr;
IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING

IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
/// \brief Name of the registered Mesh
public: std::string meshName;
IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING

IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
/// \brief Name of the sub-mesh to be loaded. An empty string signifies
/// all sub-meshes should be loaded.
public: std::string subMeshName;
IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief Denotes if the loaded sub-mesh vertices should be centered
public: bool centerSubMesh = false;
Expand Down
2 changes: 1 addition & 1 deletion ogre2/src/Ogre2Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ void Ogre2Material::SetAlphaFromTexture(bool _enabled,
Ogre::HlmsBlendblock block;
if (_enabled)
{
block.setBlendType(Ogre::SBT_TRANSPARENT_ALPHA);
this->ogreDatablock->setAlphaTest(Ogre::CMPF_GREATER_EQUAL);
block.setBlendType(Ogre::SBT_TRANSPARENT_ALPHA);
this->ogreDatablock->setBlendblock(block);
}
else
Expand Down
52 changes: 52 additions & 0 deletions tutorials/21_render_order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
\page render_order Render order

This example shows how to set the render order for coplanar poligons.

The material API allows changing the render order. When polygons are coplanar, you can get problems
with `depth fighting` where the pixels from the two polys compete for the same screen pixel. As you
can see in the following image:

@image html img/render_order_bad.png

The method `SetRenderOrder` in the Material class allows avoiding this issue. The higher value will
be rendered on top of other coplanar polygons.

In the `simple_demo` example you can find two materials with different render orders. The red material
(`SetRenderOrder(3)`) has a higher value than the white material (`SetRenderOrder(3)`).

\snippet examples/render_pass/Main.cc red material

\snippet examples/simple_demo/Main.cc white material

As you can see in the following image the z-fighting issue is resolved.

@image html img/render_order_good.png

You can set this in your SDF file including in the material tag a new tag called `render_order` with
a float value:

```xml
<material>
<render_order>5</render_order>
<ambient>0 0 1 1</ambient>
<diffuse>0 0 1 1</diffuse>
<specular>0 0 1 1</specular>
</material>
```

Clone the source code, create a build directory and use `cmake` and `make` to compile the code:

```{.sh}
git clone https://github.com/ignitionrobotics/ign-rendering
cd ign-rendering/examples/simple_demo
mkdir build
cd build
cmake ..
make
```

Execute the example:

```{.sh}
./simple_demo
```
Binary file added tutorials/img/render_order_bad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/img/render_order_good.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.