Questions about lightmaps and blending Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
Fighter19
Gnoblar
Posts: 6
Joined: Sat Jul 28, 2018 1:40 am
x 3

Questions about lightmaps and blending

Post by Fighter19 »

I'm trying to find a good way to create lightmaps for the .scene format.

Currently the BSP format supports lightmaps and the tools to create them are easily accessible.
(Running "build" automatically creates the BSP with the calculated lightmaps)
Thus it's a pretty great way to quickly create a block-out of the level geometry, while also getting basic lighting.

I intend to use the DotScene format however on a long term for a game of mine.

I've tried to find a good way to use Ogitor while also creating lightmaps.
But the only promising tool I've found is a now abandoned tool called FSRad in ogreaddons.
(https://wiki.ogre3d.org/OGRE+FSRad)

I've also seen https://wiki.ogre3d.org/Light+mapping
Which doesn't really look like what I'm trying to achieve however.

I'd like the shadows to be smooth and to have incorporated the "static" ambient occlusion (and preferably static "drop" shadows as well), similar to the way it works with GtkRadiant.
See this screenshot of Jedi Knight from the Steam page.
https://cdn.akamai.steamstatic.com/stea ... 1586465683
(Not like it's seen in https://wiki.ogre3d.org/Light+mapping, where it's ONLY the drop shadow)

Basically I'd prefer to calculate the light map accurately using for example Blender, and use these lightmaps without big hassle with my scene files.
I wanted to ask if there maybe is a way that does not require me manually exporting the lightmaps and somehow programatically applying them manually to the appropriate level geometry.

Also I'm wondering how to setup blending with dynamic shadows.
I guess I would need to modulate the dynamic drop shadow with the static lightmap,
but I'm unsure how I would set that up (do I do that in the Material file or do I somehow create hooks, which I'm currently unaware of, which influence some internal shadow material?).
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Questions about lightmaps and blending

Post by paroj »

if you bake the lighting in blender like:
https://www.roxlu.com/2019/060/blender- ... -lightmaps

blender2ogre should correctly reference the lightmap on export.
Fighter19
Gnoblar
Posts: 6
Joined: Sat Jul 28, 2018 1:40 am
x 3

Re: Questions about lightmaps and blending

Post by Fighter19 »

Thank you!

I will try that, asap.
Fighter19
Gnoblar
Posts: 6
Joined: Sat Jul 28, 2018 1:40 am
x 3

Re: Questions about lightmaps and blending

Post by Fighter19 »

I have now baked a lightmap and tried to export it using blender2ogre.
For this I've downloaded the current version available on the master branch and installed it with the current Blender version.

Unfortunately, it does not seem to be correctly handled.
Following XML is generated by the tool.

Code: Select all

material Grid_01_Inst {
    receive_shadows on
    technique {
        pass {
            diffuse 0.0 0.0 0.0 1.0
            specular 0.22 0.22 0.22 1.0 57.243
            alpha_to_coverage off
            colour_write on
            depth_check on
            depth_func less_equal
            illumination_stage per_light
            light_clip_planes off
            light_scissor off
            normalise_normals off
            polygon_mode solid
            scene_blend_op add
            shading gouraud
            transparent_sorting on

        }
    }
}
For some reason, the lightmap seems not to be used and generally, the object appears dark (instead of grey, the actual diffuse color was used for specularity). Apparently blender2ogre has a bit of problems when it comes to understanding nodes.

I've tried to override this behaviour by manually using the lightmap as a texture, but I had no success at first.
Apparently the second pair of UVs required for lightmapping did not get assigned properly to the lightmap.
So I removed the first UVs in Blender, leaving only the lightmap UVs.

Now I could see the lightmap, being used as a texture.
However I don't think any of the blend modes work correctly for what I'm trying to achieve with the lightmap.
Plus this material is only valid for this one specific Instance of the model.

Code: Select all

material Grid_01_Inst_test {
    receive_shadows on
    technique {
        pass {
            // diffuse 0.0 0.0 0.0 1.0
            // specular 0.22 0.22 0.22 1.0 57.243
            alpha_to_coverage off
            colour_write on
            depth_check on
            depth_func less_equal
            illumination_stage per_light
            light_clip_planes off
            light_scissor off
            normalise_normals off
            polygon_mode solid
            scene_blend_op add
            shading gouraud
            transparent_sorting on

            texture_unit {
                texture lightmap.png
                tex_address_mode wrap
                colour_op modulate
            }
        }
    }
}
Basically, I'm struggling on how to setup the material in a way that correctly blends with dynamic shadows.
(I'd like to achieve the "color dodge" effect from GIMP in respect to the shadows, where only the "darkest" shadow actually is being used).

So I have these questions I'm trying to figure out:
  1. How do I apply the texture unit to a certain set of UV coords?
  2. Is it possible to save different "sub-models" into multiple files and merge them? (e.g save the UV coords into seperate files, so that the mesh itself can be re-used at various positions throughout the game)
  3. What is the correct setup for masking received shadows that are brighter than the ones store in the lightmap?
  4. How do I prevent default shading from taking place, as the "self-shading" part was already handled by blender?
  5. How do I prevent shadows present in the lightmap from being redundantly cast again?
My thought process was as following. Please correct me if I'm wrong, if I'm trying to over-complicate things or if I'm trying to do things that are not directly supported:
  • OGRE uses a light as a camera and uses that for rendering the shadow map for that camera.
  • The shadow maps of multiple lights get used and combined into a lightmap by casting it onto the receiver material.
  • This lightmap is being somehow blended with other attributes and textures and we have the resulting image.
  • I'd like to avoid rendering all visible objects from the light, except for the ones that are mutable. I'd also like more artistic control over the shadows.
    To do this, I'd have to disable a group objects that share a lightmap from appearing together in a shadow map calculation. To simplify it, it would be enough if no static objects are used for the shadow map calculation.
  • I think I could merge dynamic shadows with the lightmap properly by using a special colour_op together with my lightmap, instead of modulating.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Questions about lightmaps and blending

Post by paroj »

Fighter19 wrote: Mon Jul 26, 2021 11:17 pm Apparently blender2ogre has a bit of problems when it comes to understanding nodes.
It only handles the PrincipledBSDF Surface type correctly. If you connect the lightmap to the basecolor slot, everything should work.
Fighter19 wrote: Mon Jul 26, 2021 11:17 pm Basically, I'm struggling on how to setup the material in a way that correctly blends with dynamic shadows.
(I'd like to achieve the "color dodge" effect from GIMP in respect to the shadows, where only the "darkest" shadow actually is being used).
ColorDodge is available via the RTSS as:
https://ogrecave.github.io/ogre/api/lat ... ered_blend

However, if you are after maximal artistic control, writing the shader yourself could be the way to go.
Fighter19
Gnoblar
Posts: 6
Joined: Sat Jul 28, 2018 1:40 am
x 3

Re: Questions about lightmaps and blending

Post by Fighter19 »

Thank you!
Yes, that's how I managed to export it in the end.

I will look into the RTSS as it seems promising.

From my understanding, the Shadow Receiver material affects every Material that receives shadows.
But in my case I only need a few objects to use a different approach when receiving shadows.
In that case I thought the CSMShadow demo looked promising, however I'm currently unable to run it,
as I've compiled it without Cg Program Manager.

I'm confident however that the CSMShadow demo helps with the rest, once I've recompiled OGRE.

Once again,
thank you for your help!
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Questions about lightmaps and blending

Post by paroj »

you can also set a shadow receiver per technique:
https://ogrecave.github.io/ogre/api/lat ... otoc_md108

the CSM demo just shows the respective shadow camera setup and thus will not help you with lightmaps.

You could look at the Terrain Component which combines real-time shadows and lightmaps using custom shaders - but that code is not easy to read.
Fighter19
Gnoblar
Posts: 6
Joined: Sat Jul 28, 2018 1:40 am
x 3

Re: Questions about lightmaps and blending

Post by Fighter19 »

That sounds awesome, I gave the Terrain sample a quick test and it mostly behaves the way I imagined it,
with the exception that the terrain itself doesn't cast a shadow on the houses.

At least I have a starting point now, that I can work with.
Thank you so much for that!
Post Reply