How to draw background?
-
- Goblin
- Posts: 248
- Joined: Thu Aug 12, 2021 10:06 pm
- Location: San Diego, CA, USA
- x 18
How to draw background?
I've seen the class Overlay and friends for drawing on top of most content, but what if you want to draw a background? I've seen Sample_TutorialSky_Postprocess for drawing a cubemap texture in the background, but is there something simpler to just draw a flat image in the background?
-
- OGRE Team Member
- Posts: 5436
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1343
Re: How to draw background?
Off the top of my head you could:
- Use a render_quad pass, but with a basic material like Ogre/Copy/4xFP32 to copy whatever contents from the 2D image into the screen
- SceneManager::createRectangle2D, and use a Rectangle2D to render 2D to the screen (probably also using Ogre/Copy/4xFP32)
-
- Goblin
- Posts: 248
- Joined: Thu Aug 12, 2021 10:06 pm
- Location: San Diego, CA, USA
- x 18
Re: How to draw background?
So, if I were to use SceneManager::createRectangle2D, what is it that makes the rectangle render behind everything else? Is that something built into Rectangle2D, or a feature of the material, or something else? I see that Copyback.material takes steps to turn off reading and writing the depth buffer, but there would need to be something to make the rectangle render before other stuff.
-
- OGRE Team Member
- Posts: 5436
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1343
Re: How to draw background?
MovableObject::setRenderQueueGroup (and Renderable::setRenderQueueSubGroup) controls order of rendering objects.
That way you can always guarantee an object is rendered first or last. Though for best performance it's always best to render background after all opaques (relying on the depth buffer) and before all transparents.
See RenderQueue docs on default ranges.
That way you can always guarantee an object is rendered first or last. Though for best performance it's always best to render background after all opaques (relying on the depth buffer) and before all transparents.
See RenderQueue docs on default ranges.
-
- Goblin
- Posts: 248
- Joined: Thu Aug 12, 2021 10:06 pm
- Location: San Diego, CA, USA
- x 18
Re: How to draw background?
I'm confused about your statement that "it's always best to render background after all opaques (relying on the depth buffer)". If I'm going to rely on the depth buffer, then I need to make my background write the correct depth, and how would I do that? That doesn't seem consistent with your suggestion to use Ogre/Copy/4xFP32, in which I see:
Thanks for your patience.
Code: Select all
depth_check off
depth_write off
-
- OGRE Team Member
- Posts: 5436
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1343
Re: How to draw background?
Rectangle2D never sets Z, so the vertex shader must do that. If you do:
Code: Select all
outputPos.xyzw = mul( worldViewProj, float4( inputPos.xy, -1.0f, 1.0f ) );
I chose Ogre/Copy/4xFP32 because it was conveniently available. But yes, you need to turn depth_check on and leave depth_write off to get the background between opaque and transparent objects. I assume that you explicitly set transparent objects RenderQueue IDs to be done after. Ogre automatically reorders objects within the same ID so that transparents always come after opaque; but it could be troublesome to specify exactly you want the BG after opaque and before transparents without specifying Render Group IDs to all these groups.jwwalker wrote: ↑Wed Dec 01, 2021 1:00 am That doesn't seem consistent with your suggestion to use Ogre/Copy/4xFP32, in which I see:
Code: Select all
depth_check off depth_write off