Questions from a beginner

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


segfaulting
Gnoblar
Posts: 7
Joined: Wed Aug 21, 2024 6:54 pm
Location: Germany

Questions from a beginner

Post by segfaulting »

Hello guys,

so I've been playing around with the new Ogre Next 4.0.0 branch lately, and need some help.
I want to preface this by saying I'm not an expert at 3D graphics programming, so a lot of my questions likely just boil down to inexperience with 3D in general.

I'm at a point where I'd like to add terrain to my game. I am aware of the Sample_Tutorial_Terrain, but can't get it to work on my machine with recent commit 40514676df.

Code: Select all

Vertex Shader: 100000013VertexShader_vs
Fragment Shader: 100000013PixelShader_ps
 GLSL validation result : 
active samplers with a different type refer to the same texture image unit
WARNING: GraphicsSystem::deinitialize() not called!!!
An exception has occured: OGRE EXCEPTION(5:ItemIdentityException): Parameter called blueNoiseTex does not exist.  in GpuProgramParameters::_findNamedConstantDefinition at XYZ (line 2207)

I reckon I could try to fix the sample for my machine, but before delving into that I'd like to ask a few fundamental questions about Ogre Next and it's inner workings.

1. How would I render 2D elements?
I know that the examples render 2D text on the screen, but couldn't figure out where, and even more so how.
In general, how do you draw something to the screen and have it appear in front of all other objects in a orthographic view?

2. What is the compositor?
I've read that the compositor is usually used for post-processing effects.
So say I'd like to add chromatic abberation or a vignette effect, this is what I'd want to use?
Can you stack compositors and enable/disable them on the fly?

3. What would I have to do to write a simple vertex shader for terrain displacement?
I could just use the Terrain example, but I don't think I'd learn much about working in tandem with Ogre if I did that.
So I figured I might as well just ask.

I'm aware that generating a terrain basically boils down to rendering a plane with reasonable amount of vertices and displacing them by sampling a heightmap in the vertex shader, and this is what I'd like to do for now.
But I truly don't know how to go on from here, how do I write these shaders and get them into Ogre? I've read something about shader pieces in the docs, but that's about it.

4. In regards to materials, what is the preferred workflow nowadays? .material.json or .material scripts?

5. Grass rendering.
I'd love to try billboarding to render a large amount of grass patches. From what I took away from a few posts on here, is that Ogre tries to use instancing with SCENE_STATIC whenever possible.
So would this take advantage of this instancing and uphold a high framerate?

Create a BillboardSet
Add 3 Billboard's to this set
Attach a unlit material
Create a bunch of SceneNodes for this BillboardSet with SCENE_STATIC and add differing positions

6. RenderQueue's
How do I move an object to a different RenderQueue? I've read on a few posts here that terrain is supposed to be rendered last, but how do you actually enforce this?

Thank you for your patience.

Note: Sorry about the formatting, unfamiliar with the BB syntax and couldn't quite get it to look like I wanted.

segfaulting
Gnoblar
Posts: 7
Joined: Wed Aug 21, 2024 6:54 pm
Location: Germany

Re: Questions from a beginner

Post by segfaulting »

So I've been trying to figure out how to get custom shaders into Ogre Next to display a large number of grass meshes, but I just can't get it to work.
As far as I can tell, there currently are two ways to get custom shaders into Ogre Next:

  • A custom Hlms implementation that defines it's own VertexShader_vs.glsl and PixelShader_ps.glsl
  • The old material system with a material script that defines vertex_program_refand fragment_program_ref

A custom Hlms implementation seems really complicated, and I've read somewhere on here that more than 4 different Hlms implementations are unsupported? In that case it seems like a waste to dedicate one Hlms slot to just rendering grass.

On a separate occasion, I've read that the old material system is slow and not suited for a large number of entities, I'm really torn on what to do now.
Hlms seems really complicated to get implemented correctly, and from what I can tell the old material system is unsuited for millions of entities on screen.

I've tried adapting / copying the old material script & shader from Tutorial_SSAO, but can't get that to work either.
Can someone point me out in the right direction?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: Questions from a beginner

Post by dark_sylinc »

Hi!

segfaulting wrote: Thu Aug 29, 2024 5:35 pm

I'm at a point where I'd like to add terrain to my game. I am aware of the Sample_Tutorial_Terrain, but can't get it to work on my machine with recent commit 40514676df.

Code: Select all

Vertex Shader: 100000013VertexShader_vs
Fragment Shader: 100000013PixelShader_ps
 GLSL validation result : 
active samplers with a different type refer to the same texture image unit
WARNING: GraphicsSystem::deinitialize() not called!!!
An exception has occured: OGRE EXCEPTION(5:ItemIdentityException): Parameter called blueNoiseTex does not exist.  in GpuProgramParameters::_findNamedConstantDefinition at XYZ (line 2207)

I reckon I could try to fix the sample for my machine, but before delving into that I'd like to ask a few fundamental questions about Ogre Next and it's inner workings.

Fixed! Thanks!

segfaulting wrote: Thu Aug 29, 2024 5:35 pm

1. How would I render 2D elements?
I know that the examples render 2D text on the screen, but couldn't figure out where, and even more so how.
In general, how do you draw something to the screen and have it appear in front of all other objects in a orthographic view?

Note: Before I start explaining, OgreNext 2D facilities are quite lack luster and could be made more useful. Ok now that I've clarified this:

We have a very old Wiki article that explained the math behind it but unfortunately most of it is dead.

Anyway, the quick answer is just use ColibriGui (note: I am the writer and maintainer of ColibriGui).

The sample "OffScreenCanvas3D" shows how to draw text in 3D, although it may waste quite a chunk of memory (since it creates a TextureGpu for every block of 3D text you want to render, instead of drawing the 3D glyphs on the fly), so proper consideration needs to be taken (e.g. one simple solution is to have a fixed max amount of text you can show in 3D at any given time).

2. What is the compositor?
I've read that the compositor is usually used for post-processing effects.

The compositor can be used post processing effects, but it can also be used to do advanced stuff like only rendering a portion of your objects and in any order you want; because Compositor passes ask you for render queue ID ranges and scene manager visibility masks.

This lets you control render order (e.g. draw object A -> some effect -> draw object B) and whether some objects are triggered off en-masse.

Our manual has a dedicated section for the Compositor.

Because our Compositor concept is heavily influenced by Blender's, I suggest that you watch some of Blender's tutorials to get an idea:

The main difference though, is that in some cases you have to write your own shaders to combine the renders instead of having a visual node editor.

So say I'd like to add chromatic abberation or a vignette effect, this is what I'd want to use?

Yes, but you can do much more than that.

Can you stack compositors and enable/disable them on the fly?

Yes, but because our Compositor likes to bake a lot of stuff, you need to think about some design choices so that it is easy to toggle nodes on/off easily and without hitches.
The Postprocessing example shows an approach on how to do that (although not necessarily the only way).

3. What would I have to do to write a simple vertex shader for terrain displacement?
I could just use the Terrain example, but I don't think I'd learn much about working in tandem with Ogre if I did that.
So I figured I might as well just ask.

I would actually place that in mid-to-advanced level. Not because displacing is hard (that's the easy part), but because Terrain vertex shaders can get quite complex.

Specially because our Terrain system uses Vertex Shader Tricks by Bill Bilodeau (video) to render the terrain without an actual vertex buffer.

Nonetheless, you may want to first look at Tutorial_Hlms02_CustomizationPerObj which shows how to customize shaders for Pbs and add a (very lame) "wind" displacement.

Then proceed to try something similar on Terrain, or into the terrain's shader directly (i.e. Media/Hlms/Terra/Any/800.VertexShader_piece_vs.any).

4. In regards to materials, what is the preferred workflow nowadays? .material.json or .material scripts?

Personally for simple materials I write by hand I use .material scripts since they're quicker and easier.
But when using advanced functionality only supported by .material.json or materials written by external tools, I use material.json.

5. Grass rendering.
I'd love to try billboarding to render a large amount of grass patches. From what I took away from a few posts on here, is that Ogre tries to use instancing with SCENE_STATIC whenever possible.
So would this take advantage of this instancing and uphold a high framerate?

Create a BillboardSet
Add 3 Billboard's to this set
Attach a unlit material
Create a bunch of SceneNodes for this BillboardSet with SCENE_STATIC and add differing positions

That would work. In 4.0 I wrote BillboardSet2 (see Samples/2.0/ApiUsage/ParticleFX2 sample), perhaps it will lead you to higher performance.

However rendering LOTS of grass, specially in the far distance, may require using more than one technique, which we are not providing out of the box at this time.

6. RenderQueue's
How do I move an object to a different RenderQueue? I've read on a few posts here that terrain is supposed to be rendered last, but how do you actually enforce this?

Just call MovableObject::setRenderQueueGroup.

Note that the queue ID must be placed in the right mode, i.e. see sceneManager->getRenderQueue()->setRenderQueueMode().

Normally render passes will render stuff in queue ID 0...255, in that order. However you could in theory use the compositor to e.g. use render pass to first render IDs 100...200 then IDs 10...150. Notice I did some overlap (objs 100...150 are rendered twice), out of order, and objects 0...9 and 200...255 are never rendered.

However for your best organization, you should stick to rendering things in order otherwise it becomes a mess.

Cheers

segfaulting
Gnoblar
Posts: 7
Joined: Wed Aug 21, 2024 6:54 pm
Location: Germany

Re: Questions from a beginner

Post by segfaulting »

Hey dark_sylinc,

thank you for taking the time and for providing very useful tips, I've read the compositor manual a few times but couldn't really wrap my head around it.
I guess I'll just learn by trial and error when the need for it arises.

And thank you for pointing out Tutorial_Hlms02_CustomizationPerObj to me, this seems to do exactly what I want to try right now!
Looking forwarding to building with Ogre Next!