Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Normalized Lightmapping

Author
Message
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 2nd Jul 2010 16:06
Hi everybody.
Here are my latest shaders which I have named "Normalized Lightmapping", and "Paralyzed Lightmapping". It is an attempt at faking normal (and parallax) mapping, but in a way which is a bit more efficient than the multi-pass method. It can simulate an infinite number of static lights at speeds which are comparable to using a single light from a standard normal mapping shader.

It does this by using a second set of lightmap textures which (should) depict the angle of the incoming light ray. Because of this, any of the lightmap's pixels which are illuminated by more than one light source can't be accurate since each pixel can only store a single vector. These pixels should store the "average" (probably not the best term) of the incoming light rays.

The result isn't as perfect as standard normal mapping (the inaccuracies are really only noticeable if you know what to look for), but I think it is good enough to be used in a game. Ideally a special program would need be written to calculate these new lightmaps, but I simply used PixPlant to generate them from the lightmaps which Mapscape produced (this is obvious in the ceiling). I personally don't have the skills to write such software, but you can bet I'll be trying in the near future (mabey by modifing Evolved's lightmapping functions). Until such software is written the idea has some additional limitations which I won't go into right now.

I am still getting the hang of HLSL, so I would appreciate it if any of our more experienced members could look over the code for me and see if I have made any obvious mistakes. The first time I compiled these demos, I got so exited that I just had to post it to see what you all think/ how this performs on other people's systems.

Any comments or suggestions would be much appreciated.
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 2nd Jul 2010 16:07
And here are the exes if you can't compile the above demos (you need both files).
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Jul 2010 17:21
This is really impressive!

I'll be studying this for sure!!

Thanks for posting

revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 2nd Jul 2010 17:29
Thanks baxslash! Could you post your FPS/system specs?

Quote: "Thanks for posting"
No Problem.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Jul 2010 18:49 Edited at: 2nd Jul 2010 18:50
Brilliant demos. Nicely done.

Thanks for doing this for us, these should be really ueful. I've been thinking of doing some directional lightmapping for some time but have not had the time to get suitable programs up and running for the lightmaps so it's great that you are having a go at this.

I'll be watching how you get on with this.

Noticed one lightmapping glitch in the "Normalized" demo:



I'll post back when I've had a chance to study the code.
Kryogenik
16
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 2nd Jul 2010 18:53
That looks really nice. I got 810 fps on the normalized demo, 880 without specular. I got 710 on the paralyzed demo, 730 without specular.
Processor: 3.2 Ghz Intel i5 dual core
Ram: 4 GB
Graphics Card:ATI HD Radeon 5670 (1 GB of Video memory)
Nice demo


cout<<"I'm learning C++, and this is all I know \n"
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 2nd Jul 2010 19:39 Edited at: 2nd Jul 2010 19:54
Yep, excellent demo's, revenant chaos!! Just brilliant!

Quote: "I got 810 fps on the normalized demo, 880 without specular. I got 710 on the paralyzed demo, 730 without specular.
Processor: 3.2 Ghz Intel i5 dual core
Ram: 4 GB
Graphics Card:ATI HD Radeon 5670 (1 GB of Video memory)"

That's weird? Why is yours running slower than mine?
I've got between 998 and 1514 FPS on the paralyzed demo, and between 933 and 1448 FPS on the normalized demo.
System specs:
AMD Athlon 64 Dual Core 4400+ 2,30 Ghz
3.00 GB
ATI Radeon HD 3870 512 MB

Cheers

Slayer rules!!! Yeaaah, man!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Jul 2010 19:44
Don't look at the fps on my screenshot.
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 2nd Jul 2010 19:53 Edited at: 2nd Jul 2010 19:55
Quote: "Brilliant demos. Nicely done."
Quote: "That looks really nice... Nice demo"
Quote: "Yep, excellent demo's, revenant chaos!! Just brilliant!"
Thank you all. It took a considerable amount of fumbling around in order to get this working, so it is awesome that others are as exited about the results as I am.

Quote: "Noticed one lightmapping glitch in the "Normalized" demo:"
Are you are talking about the darkness on the top of the doorway? (I hope you aren't picking on me about the light flare)

Your responses make me want to clean up and post some of my other demos which are collecting dust. Most of them aren't as pretty as these, but I have a few other lightmap based effects and stencil shadow demos which I think could be of use to someone.

Quote: "I've been thinking of doing some directional lightmapping"
I did a bit of work with this some time ago. If they are still around, I'll try to find and post them as well. After playing BioShock I started experimenting with lightmap based caustics and a few other things which I haven't seen on the forums.

Quote: "Don't look at the fps on my screenshot."
Good to see that old dinosaur is still kicking.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Jul 2010 21:25 Edited at: 2nd Jul 2010 22:30
Quote: "Good to see that old dinosaur is still kicking."


Nope. That's been mothballed - the fps was my not-quite-so-ancient laptop. [Er, I'm assuming you're referring to the machine not the user.]

Quote: "Are you are talking about the darkness on the top of the doorway?"


I think so. I'm referring to the sharp diagonal change in lighting in the middle of the doorway arch - looks like the edge of a ghosted plain or similar.

I've delved into the shader code a bit and am puzzled by a few things. For example, what's the logic behind mixing the lightmap direction with the pixel's world position in this line?



I assumed that the second lightmap stores the lighting direction using the same tangent space coordinates as a standard normal map. Is that correct?

Edit FPS = 1489 on "Cyborg" at 1680x1050.
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 3rd Jul 2010 04:19
Quote: "I think so. I'm referring to the sharp diagonal change in lighting in the middle of the doorway arch - looks like the edge of a ghosted plain or similar."
So you ARE picking on me about the light flare. I have attached a new .ent file which will solve that issue, so just drop it into the "Media" folder.

Quote: "I've delved into the shader code a bit and am puzzled by a few things. For example, what's the logic behind mixing the lightmap direction with the pixel's world position in this line?
float3 NormV=normalize(mul(LMnorm-IN.WPos,TBN))"


This is basically how the shader became what it is:

1) A Standard Normal Mapping Shader

In the VS:
float3 LightPos=LightPosition_1-WPos;
OUT.LightVec=mul(LightPos,TBN);
Shortened to:
OUT.LightVec=mul(LightPosition_1-WPos,TBN);


2) In the original pixel shader:
float3 LightV=normalize(IN.LightVec);

Since I moved the calculations from the vertex shader to the pixel shader
I was able to further shorten it to:
float3 LightV=normalize(mul(LightPosition_1-WPos,TBN));

Because there is no light position I intended to use the normalized lightmap to fake a light direction vector, but since it will actually be from a normal map I renamed "LightV" to "NormV".

float3 NormV=normalize(mul(LightPosition_1-WPos,TBN));

3) This is the part which required the bit of playing around with. I intended to use the normal map to obtain a set of coordinates relative to the pixel's world position, and use this to fake the light vector. My original logic produced some crazy results and it was only through trial and error that I stumbled upon the final calculation which you see in the shader.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Jul 2010 17:57
I still don't understand the logic.

The last line of code you give is



I have no quarrel with that (in simple normal mapping) - it simply gives the negatived light direction vector in tangent space, prior to "dotting", etc, with the normal map which will usually be in the same space. My problem is the change to



which among other things implies that LMnorm is in world coordinates. Is it?

Your final paragraph is more or less what I expected, i.e. LMnorm is a light direction presumably coded in tangent space or world space depending on how you coded it. If you used tangent space then LMnorm shouldn't need to be transformed before being combined with the other transformed lighting variables such as the normal vector from the normal map. If you used world space when you created the lightmap I'd expect to see something like



to take it into texture space ready for the diffuse and specular calculations. But you'd probably have a problem with light attenuation (or lack of it) in that case.

Unfortunately I'm not sure how you've coded the second lightmap so I can't be more specific about how to use it.

I would have coded the lightmap so that, for example,

(a) RGB = (128, 128, 128) corresponds to no light, i.e. black,

(b) RGB = (255, 128, 128) corresponds to full light in the direction of the X axis (in whatever coord system you're using)

and

(c) RGB = (192, 128, 128) corresponds to roughly 50% attenuation of a light in the X axis direction.

If done that way there is no need for normalization and attenuation is automatically allowed for in the lightmap.

Perhaps you could clarify exactly what the values in your lightmap represent?
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 4th Jul 2010 02:40
Quote: "float3 NormV=normalize(mul(LMnorm-IN.WPos,TBN))
which among other things implies that LMnorm is in world coordinates. Is it?
"


I intend to use world space lightmaps(_n) in the end, but the ones in the demo are indeed tangent-space normal maps (which where generated with PixPlant).

To be honest I was rather suprised when the demo worked with the media I had used. I had atttempted to convert it to world space in the shader, but I couldn't get anything close to working. Do you know how this could be done?

In the first post I had mentioned that I am planning to eventually write a program to genetate the lightmaps and their normalmaps (world space), but until then I am not doing anything special to create the textures.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Jul 2010 15:46 Edited at: 5th Jul 2010 02:58
Quote: "In the first post I had mentioned that I am planning to eventually write a program to genetate the lightmaps and their normalmaps (world space), but until then I am not doing anything special to create the textures."


As it happens I was thinking of doing something like that today - and like you I'll probably use world space coordinates because they are simpler. I'll be using the following strategy (unless I encounter a hitch I've overlooked ):

Step 1: Use DarkLIGHTS to create a lightmapped object. If I recall correctly that will give us the UV coordinates we need for mapping the new lightmap.

Step 2: Work through all the polygons of the lightmapped object and use interpolated vertex coordinates to calculate the direction of the nearest light, and interpolated lightmap stage UV coords to reference the appropriate pixel in the new lightmap.

Quote: "To be honest I was rather suprised when the demo worked with the media I had used. I had atttempted to convert it to world space in the shader, but I couldn't get anything close to working. Do you know how this could be done?"


You should be able to work with either space. For lightmapped objects which don't move (as here presumably) world space normal maps should be more efficient since you don't need the extra code for converting everything to tangent space. The downside is that you'd need a different normal map for different surfaces even if they had the same base texture. There shouldn't be any problem combining a world space directional lightmap with a tangent space normal map - you should just be able to use the decoded direction from the lightmap in the usual way with very few other changes to the shader.

Well, that's the theory. I couldn't get your demo working in the way I expected either - I probably need to go through the shader code more carefully (or write my own from scratch - might be quicker ). I'll have another look since your code suggests the directional lightmap is in world space whereas your latest comment suggests it is uses tangent space.

However, even though I'm not yet sure why your demo works, it plainly does and looks very good.

late Edit Here's my current offering. You need DarkLIGHTS and IanM's Matrix1 plugins. The demo creates a simple lightmapped object using DarkLIGHTS. Then creates a new directional lightmap using world space coordinates. The demo finally displays the same object using my own version of a shader for this.

The dba code briefly highlights some problems with this version. It is, hopefully, work-in-progress rather than a dead-end. Don't forget to press <space> as soon as the DarkLIGHTS lightmapped object appears - but my part unfortunately takes a lot longer. Room for improvement/re-thinking .
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Jul 2010 10:29
Quote: "stencil shadow demos which I think could be of use to someone"

I wouldn't mind trying an alternative to the in built stencil shadow effect...

Login to post a reply

Server time is: 2026-07-25 12:40:28
Your offset time is: 2026-07-25 12:40:28