gazebosim / gazebosim/gz-rendering
How to use a custom shader with a OGRE 2 rendering camera?
- Dominant language
- C++
- Stars
- 81
- Forks
- 90
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 10
Description
Hi there, I'm using Gazebo Harmonic, and I'm trying to create a custom sensor that works like a depth-normal camera, to enable the development of a sonar simulation sensor/system plugin. My first idea was to use a shader into a camera, in the same way that the [custom_shaders](https://github.com/gazebosim/gz-rendering/tree/gz-rendering8/examples/custom_shaders) does. However, when I changed the [rendering engine of this custom_shaders example](https://github.com/gazebosim/gz-rendering/blob/gz-rendering8/examples/custom_shaders/custom_shaders.cc#L51) to OGRE 2, even updating the shaders to the 330 version, it's completely ignored by the camera that seems the scene with no shader.
Another example is changing the [custom_shader_uniforms](https://github.com/gazebosim/gz-rendering/tree/gz-rendering8/examples/custom_shaders_uniforms) to use the shader in the camera instead of in the box model, and update the `fragColor` to be red. When I run with OGRE 1 the camera sees the box in red color:
But when I run with OGRE 2 it doesn't:
I also tried a custom variation of the [ogre2_demo](https://github.com/gazebosim/gz-rendering/tree/gz-rendering8/examples/ogre2_demo), by adding a normal mapping of a brick wall in the pump model, and making the camera use a depth shader, and the behavior is the same: with OGRE 1 it's using the shader:
But with OGRE 2 doesn't.
I see no warnings/errors when running all those examples with OGRE 2 and shaders in the camera. Am I missing something or doing something wrong? Is that an example similar to `custom_shader` (which is a simple rendering camera with a shader) but using OGRE 2?
Git diff of `custom_shaders_uniforms`:
```diff
diff --git a/examples/custom_shaders_uniforms/Main.cc b/examples/custom_shaders_uniforms/Main.cc
index 093de95b..6d5f69d0 100644
--- a/examples/custom_shaders_uniforms/Main.cc
+++ b/examples/custom_shaders_uniforms/Main.cc
@@ -115,7 +115,7 @@ void buildScene(ScenePtr _scene,
box->SetOrigin(0.0, 0.0, 0.0);
box->SetLocalPosition(0, 1, 0);
box->SetLocalScale(2, 2, 2);
- box->SetMaterial(shader);
+ // box->SetMaterial(shader);
root->AddChild(box);
// create camera
@@ -127,6 +127,7 @@ void buildScene(ScenePtr _scene,
camera->SetAntiAliasing(2);
camera->SetAspectRatio(1.333);
camera->SetHFOV(GZ_PI / 2);
+ camera->SetMaterial(shader);
root->AddChild(camera);
// track target
diff --git a/examples/custom_shaders_uniforms/media/fragment_shader.glsl b/examples/custom_shaders_uniforms/media/fragment_shader.glsl
index f4a62a90..6040bc15 100644
--- a/examples/custom_shaders_uniforms/media/fragment_shader.glsl
+++ b/examples/custom_shaders_uniforms/media/fragment_shader.glsl
@@ -35,5 +35,6 @@ void main()
vec2 normalizedFragCoord = b / u_resolution;
vec3 color = vec3(random(normalizedFragCoord, float(u_seed)));
- gl_FragColor = vec4(color * u_color, 1.0);
+ // gl_FragColor = vec4(color * u_color, 1.0);
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
diff --git a/examples/custom_shaders_uniforms/media/fragment_shader_330.glsl b/examples/custom_shaders_uniforms/media/fragment_shader_330.glsl
index 9e7b2a7d..a6c63559 100644
--- a/examples/custom_shaders_uniforms/media/fragment_shader_330.glsl
+++ b/examples/custom_shaders_uniforms/media/fragment_shader_330.glsl
@@ -39,5 +39,6 @@ void main()
vec2 normalizedFragCoord = b / u_resolution;
vec3 color = vec3(random(normalizedFragCoord, float(u_seed)));
- fragColor = vec4(color * u_color, 1.0);
+ // fragColor = vec4(color * u_color, 1.0);
+ fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.