Problems with Lightmaps + dynamic lights


#1

Hi ! It seems that dynamic lights + shadow mapping + baked lightmaps doesn’t work properly together… i don’t know what causes this but here’s a picture whats happening :

Left Images : No dynamic lights (OK) - Right : Dynamic lights + lightmap (Wrong)

As you can see some faces are lit and some are not. Also the shadow is not visible on unlit faces…(right bottom pic)
I tried to recalculate normals , turn off cast shadows on level , but it didnt helped.
i’m using the DiffLightMap , Diff , DiffLightmapAlpha , DiffAlpha techniques

Any ideas ? What i want is keep the lightmapped mesh unlit but receiving shadows


Lightmapping
Infested : a survival horror and investigation game
#2

You should be able to set the light mask on your lights and geometry. That way it won’t affect your baked lighting. Then set the shadows on both, and I believe that should do what you want.


#3

Now the dynamic lights are gone , but the shadows are disappeared too…

The shadows are visible on the cube (DiffNormalPacked technique) but not on the level

I tried :

[code]level->SetLightMask(1);
level->SetShadowMask(1);

light->SetLightMask(2);
light->SetShadowMask(1);[/code]


#4

I haven’t tried this…

Try make making a custom technique. Copy and paste the DiffLightmap stuff and omit the light pass.


#5

Hi ! if i remove the line

The effect is the same as on my second picture.The dynamic lighting is disabled but the shadows are not visible either.


#6

Hm… i tried modifying the shader as you suggested but still can’t get it to work… maybe someone who is more into shader programming can help me out.


#7

Arghh… no matter how i modify the LitSolid shader it just won’t work properly… I either end up the scene is unlit but then there’s no shadow mapping at all , or i can get shadows but then the lightmapped mesh is lit. I can’t turn off the light pass and keep the shadows… I just really wish there is a solution for this as its a really commonly used technique in games it would be a really cool if Urho had this feature…

BTW as i mentioed i’m really a beginner in shader programming so any help/ideas are welcome


#8

Hi , i will create a lightmapped mesh tomorrow somehow , right now i have no tools/editor that can export meshes with 2 texture coords and can be used directly with urho…
I have no project on git either , but as i said i can upload an mdl file tomorrow with materials and techniques.


#9

no that’s my custom format (i wrote a whole scene exporter long ago for irrlicht) and i wrote an importer for Urho. Its in .mod format so Urho can’t load them by default

[quote]I did a quick test with a junk lightmap I threw together in 30 seconds, it looks like everything is fine in the shaders out of the box.
Have you tried adjusting the “Brightness Multiplier” of the light. Something like 0.1.[/quote]

Hm i just did a test too in the urho editor.I imported a lightmapped mesh added a cube and a light. If i turn the brightness lower , the shadow cast by the cube also disappears.Also turning the brighness lower would affect models that SHOULD be lit in the scene (e.g characters dynamic objects etc)

This is how it looks Brightness 0.1 :

And brightness 0.75 :


I need a test .mdl file with 2 Texture Coordinates
#10

Quick question Dave82, What software tool are you using in generating Lightmaps? I’ve always been curious with lightmap techniques since this is a big part of asset optimization.

I tried to contribute some samples before but my thread was somehow buried :unamused:

really curious how this turns out.


#11

I’m not sure if these can help in anyway but found some discussion from other engines, this one in Irrlicht forums from member Mel

[quote]I have a suggestion for the dynamic/static shadow blending. Basically, If you use lightmapping, you can multiply the shadowmap by the lightmap, and calculate the luminance of the result to blend it with the ambient lighting. This, obviously, overrides the lightmap color, but almost blends perfectly the shadowmap with the lightmap.

lightmapColor*=shadowmapValue; colorIntensity = (lightmapColor.r+lightmapColor.g+lightmapColor.b)/3.0; lightCol = (1-colorIntensity)*ambient+(colorIntensity)*lightmapColor;

[/quote]

Full Thread:
How to mix static shadow with dynamic shadow
irrlicht.sourceforge.net/forum/v … 70#p259025

About Lightmaps
irrlicht.sourceforge.net/forum/v … hp?t=26220


#12

ow, It looks as problem exist only in calculating for mixing.
In general - it work.

For rasteron:

[spoiler][quote=“rasteron”]Quick question Dave82, What software tool are you using in generating Lightmaps? I’ve always been curious with lightmap techniques since this is a big part of asset optimization.

I tried to contribute some samples before but my thread was somehow buried :unamused:

really curious how this turns out.[/quote]

3DMax , Maya, Blender3D and other programs can do it.

Quick theory from Wiki
http://en.wikipedia.org/wiki/Lightmap

Lightmap can be baked directly to Diffuse texture in 3D editor.
In this case is not necessary for game engine calculate mix for Diffuse and Lightmap.
It can be used if you not want change static lights/objects positions.

Lightmap can be baked separatly to other UV coordinates.
Object need have one UV for Diffuse and other UV for Lightmap.
In this case, game engine calculate mix Diffuse/Lightmap by himself.
But, you have the ability to change only Lightmap when change level to level.
Level “morning” <-to-> Level "evening"
or in realtime.

If litemaps used for shadows only it can be greyscale (limited number of colors)
This textures lightweight for hardware loading process than loading diffuse textures.
Additionally this textures can be used for specular calculating or other targets.

Blender "blender lightmap"
http://www.youtube.com/results?search_query=blender+lightmap
Blender "blender bake"
http://www.youtube.com/results?search_query=blender+bake
Variants for Blender "TextureAtlas Add-on"
http://www.blendernation.com/2012/09/13/textureatlas-add-on-baking-entire-scenes/
Introduction to Baking in Cycles
http://www.blenderguru.com/tutorials/introduction-baking-cycles/[/spoiler]
Look also to:

Warboat (Local Multiplayer Boat Battle)
Use Blender and Urho3D for shadowmap.
http://forums.tigsource.com/index.php?topic=41689.20


#13

I’m using lots of softwares , but my favorite is 3ds max. I’m using it 7-8 years now and i think it gives the best results. It’s a really big optimisation but the reason i really like static lightmaps is that literally everything is possible.You can bake Global illumination + color bleeding + edge detection + soft shadows in one lightmap texture. I mean dynamic lighting with dynamic shadow mapping looks really great but not even close to baked global illumination.Thats the main reason why i want to use static lightmaps.

Me too :smiley: but the more i think about this the more i came to a conclusion that is impossible to do it…
The shadow mapping is not “Rendering dark shadows on top of the level” but "rendering light on top of the level and leave out the shadowed areas"
So shadows in fact are non-lit parts of the scene.
So it goes something like this :

1 render the scene unlit (pass1)
2 render the scene lit and calculate shadows (pass2)

This would be possible only if we could render the level non lit with lightmap texture , and on top of that render shadow maps (subtract from current frame)
So what we will have is completely the oposite , but this way we can specify custom shadow color>

1 render the scene unlit
2 render the scene but instead of calculating the lighting we simply use black color for the whole image EXCEPT where the shadows should be.There we can use shadowColor

Here’s my idea :

Is possible to do something like this with shaders ??? This way the lightmapped meshes are unaffected by lights still dynamic shadows will be possible.


#14

It’s not directly possible without engine code modifications, because like you say now the purpose of light pass is to add light.

Some engines like Unity build a shadow mask texture for the screen, which may allow more versatility in the shadow blending equation. But it doesn’t allow unlimited amount of shadowed lights because of limited channels (RGBA) in the shadow mask.


#15

Yeah now that i’m thinking further it will disable lighting in the whole engine as each material would use this approach , which disables lighting…


#16

@globus

Thanks for the reference. I’m already very familiar and knowledgeable with lightmapping process, in fact it is one of my favorite topics when it comes to engine and game optimization. :smiley: I’m not a shader guy though…

This one I did for testing months ago:

It is the pipeline and the technique of blending dynamic shadows and static lightmaps with Urho3D that I’m curious with, which is why I was planning to contribute to as samples, and apparently this has not been a feature with the engine [yet]. :wink:


#17

Same reason here and I couldn’t agree more. Not a fan of using dynamic shadow mapping on all objects as well :smiley:

Realtime GI and other lighting effects is really nice but if you can save up and another reason not to make the graphic card or system overheat, it is a must have.


#18

I tried to work on a small demo with Godot engine for a bit, particularly when I found out that they got their baked GI working months ago. It was really awesome but still having problems with their editor and it’s only GLES2 for Godot at the moment :unamused: so I stopped my work there and got back to my old engine. :slight_smile:

Here’s the Godot editor interface with their baked GI feature…


#19

Well i just give it up… i will just simply disable the lightpass on lighmapped meshes and use a simple blob shadow under the character’s feet.
It is unfortunate that a feature like this not included in Urho3d


#20

I fully support your attitude towards optimization.
Lightmapping big step in that direction.

I like the old style of game engines. (Old-Gen engines)
There are a lot of old games that are fun to replay again.
Previously, developers were limited in resources and do miracles of optimization.

And there’s a huge mass of modern games they look very best
but with mercilessly loaded hardware and which are not fun to play.

[spoiler]

Also, Fable: The Lost Chapters, Rune and mass of other old games.

Not very old but well optimized:
COD: Modern Warfare 2 and Dead Space 2-3[/spoiler]