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.

Code Snippets / [GDK] - Procedure for making a normal map

Author
Message
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 10th Jan 2012 01:28
I found it hard to get and even when I found something on it, it was in DBP. This is as simple as I can make it:

As stated in the first line, you will have to make the FindFreeImage(); function yourself. It's simple if you don't already use it:


The fastest code is the code never written.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jan 2012 17:55
What sort of normal map is that and what sort of source image are you assuming?

I can't see how that code can give anything useful at all.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 20th Jan 2012 14:41 Edited at: 20th Jan 2012 14:45
It takes a texture image and makes a simple normal map.

Here is an example of input image (left) and output image (right):

The fastest code is the code never written.

Attachments

Login to view attachments
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 20th Jan 2012 15:21
Pretty cool. How long does it take to process?

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 20th Jan 2012 15:40
It's VERY fast. Of course the actual speed is determined by the size of the texture, but your not going to do this each frame. This is intended to be done before your game loop and is used to reduce the amount of textures you have stored in your game directory.

It's not perfect, but it works well enough for my needs (for now). I would love to see someone else's code that would do a better job because comparing my results to ones I have seen on the internet show mine to look a little "dull". It's kinda hard to explain what I mean, but the source texture I posted came from Evolved. They have a bump that looks amazing compared to mine. I wish I knew what method they used to make it....

The fastest code is the code never written.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jan 2012 17:52
Quote: "It takes a texture image and makes a simple normal map."


That's what I expected your code to do.

I've just had another look at your code and I now see that I must have misread it when I made my earlier comment. I'm sorry about that. Please ignore that post.

One thing that occurs to me is that you haven't normalized the result before coding the output pixel. Whether or not that matters depends on the shader or function that uses the map. Some shaders decode the pixel of the normal map and then normalize the result. In those cases your code should be fine and is certainly a simple way of doing it. In other cases you might find that strange results are obtained depending on how the normal map direction is processed. For example, if the shader is calculating light intensity by using the dot product of the light direction with the normal decoded from your normal map then your code might give too bright a result. Even stranger results might be obtained if it's used in something like a reflection calculation.

The other thing is that, if I've understood your code correctly, you are using only the blue channel to calculate your normal direction. Nothing wrong with that in itself (I usually use the total or average of the three colour components but that's a fairly arbitrary choice) but if the blue component in your source image happens not to vary much then you might not get exciting results.

I'll try a DBPro version of your code and see how I get on.

There was a post on this board (or the WIP board perhaps ) by david w a while back which discussed the same issue. Might be worth a look there. That thread discussed both GDK/C++ and DBPro versions if I recall correctly. Also, I think he found that smoothing gave better results.

Quote: "I would love to see someone else's code that would do a better job because comparing my results to ones I have seen on the internet show mine to look a little "dull"."


So would I because I've experienced similar problems with my own code which in some ways is very similar to yours. The maps produced by something like Texture Maker look much better. It could just be down to the smoothing but I'm not convinced.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jan 2012 20:05
GG if you come up with something that comes out better, please post it here.

On my other computer (which was stolen), I had a DOT3 converter that I downloaded. I think it may have even had the source code. I have tried to re-find it with no luck. That converter was AWESOME!

The fastest code is the code never written.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jan 2012 02:10
Quote: "GG if you come up with something that comes out better, please post it here."


I will. At the moment my best offering is comparable to yours judging by your posted images. No time to look into this properly right now but might have time in a day or so.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Jan 2012 03:50 Edited at: 22nd Jan 2012 03:57
@Hawkblood - What you've got at the moment is quite impressive. An approximation of the normal map is probably going to be the best you're going to get for the time being. I've been searching a number of times today through tons of other forums on the same subject and there doesn't seem to be anything else out there yet to improve on what you've already come up with.

Sooner or later I'll be whipping this if you don't mind...

EDIT: I did notice that some recommendations were to alter the colours of the image as well as brightness and contrast to emphasize the end resulting normal map.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jan 2012 21:08
Hawkblood

Just realised that a simple way of modifying your code to enhance the bumpmapping effect might be to replace this line



with something like



where flatness is a byte in the range 1 to 255. Values less than 255 should give more bumpy looking textures, i.e. higher values look flatter.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jan 2012 22:41
What would you do with "flatness"? Would you just make a constant, or would you use the texture to get the value? I have tried both approaches with wierd results. I will look at that again. Thanks.

The fastest code is the code never written.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jan 2012 23:31
Oops! I should have said use values in the range 129 to 255 (values less than 128 would mean the normal was pointing down into the surface not away from it and I believe 128 is the central value which would make the normal horizontal to the surface).

Quote: "Would you just make a constant"


That's what I had in mind but you could try the other way (bearing in mind the valid range just mentioned).
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jan 2012 23:52
I tried several values for it and I even tried this:

Doing anything other than 255 causes it to look yellowish.....

The fastest code is the code never written.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Jan 2012 00:58
Not quite sure what you're doing with "intensity".

Anyway I'll test this tomorrow to see what I get with DBPro.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Jan 2012 01:26
Thanks for helping.

The fastest code is the code never written.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Jan 2012 14:17 Edited at: 23rd Jan 2012 14:21
I can't reproduce your problem. The "flatness" variable works exactly the way I expected it to. Here's the code I used:



Here are some typical screenshots using one of my shaders in Dark Shader:



Edit Forgot to mention that the shader normalizes the input value from the normal map as I discussed in an earlier post.

Attachments

Login to view attachments
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Jan 2012 14:25
I understood the concept of the blue value being the "flatness". The problem was that I couldn't duplicate the results of Evolved's normal map.

The left is mine and the right is Evolved's.

The fastest code is the code never written.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Jan 2012 17:40 Edited at: 23rd Jan 2012 18:32
I'd say his had been normalized - and he'd probably used an adjustable flatness (or bumpiness) parameter as well.

My maps look far more pixelated than yours. However that may be because I used the stone wall image in your earlier post and that might be a lower quality version caused by the forum. I'll see if I've got Evolved's original image lurking somewhere and report back.

Edit Just remembered that you're using just the blue component (which I simply followed) and that could be part of the problem. I've found an image "Stone wall.jpg" from one of Evolved's old demos (c. 2005!) which seems to match the one you posted but that gives similar results using my DBPro version of your code. How did you get such smooth results?

Edit2 Done a bit more experimenting and the only explanation I can offer is that Evolved's normal map was constructed from a different image, a height map perhaps, and that his stone wall image was constructed using that heightmap plus a stone texture. That would explain why his normal map is smoother than mine (I tried using Texture Maker as well but got similar results). However that theory doesn't explain why my normal maps look much more pixelated than yours - even when I use my DBPro version of your original code. Any ideas what I've done wrong - or have you added something to your code? Here's a comparison of your original normal map with mine:

Attachments

Login to view attachments
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Jan 2012 22:03
Full disclosure: I first made a gray-scale version, then smoothed it a bit, then made the bump from that. I have tried doing it in as many ways as I can with varying degrees of smoothing and even tried to sharpen it before bumping. When I didn't use the smoothing I got the pixelation that you get.
I think Evolved used a mesh to make the normal map or some other type of math to make his.....?

The fastest code is the code never written.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Jan 2012 00:40
Ah! Thanks. That explains everything. I was trying something similar using Texture Maker but haven't yet found a combination of settings that looks like Evolved's image. I'll try a bit more experimenting and report back if I can find anything useful.

Quote: "I think Evolved used a mesh to make the normal map or some other type of math to make his.....?"


Yes I think so. It certainly doesn't look like simple processing of his stone wall image.

For some reason it's quite an art to get decent artwork ...
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Jan 2012 02:57
As I stated earlier, I had found a program that made very good normal maps using dot3 math. I have searched for with no luck. I guess I didn't ask the right question on google.

The fastest code is the code never written.
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 26th Jan 2012 12:28
hmm i have no experience on normalmaps or such so this might be a stupid question, but could i use that code (converted to DBP) to make my 2D TD games map look "3D"? how would i make the light?

my game runs at 1200 fps atm so speed is not the issue ( unless ofcourse this is really slow) and as this is a TD i dont really need even the 60fps
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Jan 2012 14:12
What's "TD"?

This is really only good for 3D games. If you make a 2.5D game, then it will work fine. I have a DBP example:
http://forum.thegamecreators.com/?m=forum_view&t=166885&b=5
It's a side scroller (traditionally done as 2D), with 3D objects.

The fastest code is the code never written.
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 26th Jan 2012 14:15
TD = tower defence

and no its not 3D but pure 2D... well just thinking

but thanks
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Jan 2012 19:18
Normal mapping is related to lighting effects, so you'd need a 2D lighting effect applied to 2D images using hard code or a 2d light normal-map plugin if one exists.

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Feb 2012 17:45
Evolved could have used a heightmap, as the heightmap could be used again for parallax mapping - using a texture is a good start, but it's always best to make a heightmap version for normal maps, affords you much more control.

For 2D, I would suggest just going for a fake 2D engine, using plains, at least that way you can make a mesh for your map, and gain some performance back from not having to draw tiles. I even used ImageKit to make a 2D paste image system with normal mapping, works pretty nicely but might be a little slow compared to using plains. I just thought it would be cool to have a normal map tile sheet to match a map tile sheet, add a new spin on 2D engines, good lighting, shaders etc.

Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2024-03-29 14:15:39
Your offset time is: 2024-03-29 14:15:39