How to draw background?

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

How to draw background?

Post by jwwalker »

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?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: How to draw background?

Post by dark_sylinc »

Off the top of my head you could:
  1. 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
  2. SceneManager::createRectangle2D, and use a Rectangle2D to render 2D to the screen (probably also using Ogre/Copy/4xFP32)
Cheers
jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

Re: How to draw background?

Post by jwwalker »

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.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: How to draw background?

Post by dark_sylinc »

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.
jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

Re: How to draw background?

Post by jwwalker »

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:

Code: Select all

depth_check off
depth_write off
Thanks for your patience.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: How to draw background?

Post by dark_sylinc »

jwwalker wrote: Wed Dec 01, 2021 1:00 am 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?
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 ) );
You'll automatically set the Z to the most-back. Right now Quad_vs is relying on default API behavior where .z is set to 0, which is not what you want (d'oh I just realized that's probably why Ogre/Copy/4xFP32 sets depth check off)
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
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.