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 / What is the code to make bump-mapping work?

Author
Message
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th Oct 2008 12:15
I don't have Photoshop. but I have an app that can use photoshop plugins.

When I install that package, I don't get the plugins, I checked the installed folder. I guess it has looked for Photoshop and not found it.

Can anyone help me locate the plugin files dso I can do it manually. Every link I find on Google just refers to the installer.

Morcilla
22
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 16th Oct 2008 12:43
I've found this one interesting as well:

http://forum.thegamecreators.com/?m=forum_view&t=131854&b=8
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Oct 2008 13:56
Quote: "Since heightmaps only depict Z offsets, I find that the normal maps generated from them are generally much smoother than is desired"


Heightmaps are all you need if you have the right heightmap and do your sums right. What other information do you think you need?
trogdor
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: Portsmouth, VA, USA
Posted: 16th Oct 2008 23:05
@BatVink
On nVidia's photoshop download page they have two links.
Current and Legacy.
I have Photoshop CS3 and the current one did not install a plugin. The legacy one worked just fine.

@Vickie
What settings do you use to make your bump map? When I use the photoshop plugin it does not look like the one you've made.

If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.

Attachments

Login to view attachments
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th Oct 2008 09:31
I'd really like to see a tutorial on how to take a high poly model and low poly model, then make a normal map for the low poly from the high poly - but using free software .

I think what revenant is driving at is that a normal map generated from a height map is really still just a heightmap. To get the full benefit of normals maps more control is needed. What if instead of using a greyscale heightmap, a colour map was used instead?

Like red could be the height, green could be the Z strength, and blue could be the smoothing range. That would let you specify sharper edges or smoother ones, and probably wouldn't mean too much work to add onto a normal map generator.


Health, Ammo, and bacon and eggs!
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Oct 2008 14:23
Quote: "I think what revenant is driving at is that a normal map generated from a height map is really still just a heightmap."


What do you mean? All the normal maps used for the blended AT demo on my Shaders for AT thread were calculated from heightmaps which in turn were calculated from the main textures themselves. A normal map is quite different from a heightmap.

I'm not at all convinced that Calcyman's code gives true normal maps since there seems to be no normalizing step - will have a closer look later.

Quote: "Like red could be the height, green could be the Z strength, and blue could be the smoothing range."


I don't see the point about red and green - that's just the heightmap info. The idea of having a component for smoothness is interesting though. My normal generator uses the sum of the red, green and blue components from the heightmap so you get 765 possible values for height. You could probably incorporate your smoothness idea into the alpha component and add it using a free utility like the MS DX9 SDK texture tool DxTex.exe.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th Oct 2008 17:17
What I'm saying is a normal map based on a bump map is just an emulated bump map, a normal map based on a higher polygon model is the only way to make a true normal map. There's no effective way of specifying the parts of your normal map that are sharp or dull, deep or shallow.

I mean, imagine you have a rocky height map and want a sharp square block in the middle. When you create a normal map from it, the square block in the middle would be smoothed out the same as the rocky part - there's no sharpness at all to the square block. My idea is to set the sample range with the blue element, 0 could be no sampling at all, while 255 might be 16 pixels - with 16 pixels the normal map would be really smoothed out. The green element would designate the Z strength, normally this is set as a default, but my idea would be to let you set the strength or virtual depth of the normal map pixel. So a rocky texture with a block in the middle would have a green and blue block in the middle too, so that the Z strength is increased to bring out the block, and also the sample range would be set real low on the block so it's maybe only checking a 1 pixel radius, giving it the maximum sharpness possible.

One option I'd have is to use any sort of image, so you can load a texture and specify 1 or more colour channels to use, even having 3 greyscale images for ease of editing.
This is really more for object textures, like characters where you might want a nice sharp belt buckle but fairly smooth fabric creases, not intended for photo-textures, more for when you draw the whole thing from scratch in layers, and can often use the existing layers to make a coloured heightmap like I'm suggesting.

Really it's something I should investigate then make a post about if I can get it working. Anything that gives more control over normal map creation would be a bonus. I'm thinking that most people just sample 1 pixel around the drawing pixel to calculate the normals, then let the user specify a Z strength - all I'm hoping to do is give this more control on a pixel by pixel basis.


Health, Ammo, and bacon and eggs!
revenant chaos
DBPro Master
18
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 17th Oct 2008 17:32
Quote: "I think what revenant is driving at is that a normal map generated from a height map is really still just a heightmap."

That is pretty much what I was saying. Normalmaps generated from a heightmap only reflect the topology of the texture, not the material (if that makes since). I hadn't tested calcyman's code to see if it worked like I had imagined, but the main concept was there.

Quote: "All the normal maps used for the blended AT demo on my Shaders for AT thread were calculated from heightmaps which in turn were calculated from the main textures themselves."

Except the one I made, which technically was generated from a detail texture.

Ok, I have attached an example to illustrate the difference between a normalmap generated from just a heightmap, and a normalmap generated with the heightmap and diffuse texture in mind.

Sorry for the branded images, but they were generated by a friend of mine. Since I don't own the software that was used, I wouldn't feel right about distributing them otherwise.

Attachments

Login to view attachments
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Oct 2008 00:28 Edited at: 18th Oct 2008 00:29
Quote: "Except the one I made, which technically was generated from a detail texture."


I didn't think I used that one for the forum versions - which demo do you think it was used in?

I think you've all lost sight of the original issues which were:

Quote: "What's a good way of generating a normal map?"


which was quickly followed by:

Quote: "If anyone can pull together a small tutorial of making a normal map, it would make a nice little newsletter feature It would need to use tools that are readily available and free or cheap."


By far the simplest and easiest way of creating a normal map from a texture is to convert it to a heightmap (or its negative) and calculate the normals accordingly, with or without smoothing.

Frankly, that is all that is required for a TGC Newsletter tutorial.

I agree that such normal maps are not suitable for all occasions - for example sharp edges are difficult to reproduce (however these are difficult whatever you do because of the filtering of images that goes on in the rendering pipeline). Another difficulty is that light (or dark) areas in the texture don't necessarily correspond to high spots on the surface - but such issues would take you beyond the requirements of a tutorial.

I've also used normal maps calculated from simple Perlin noise maps and they are very effective. Further elaboration for a beginner is hardly appropriate.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 18th Oct 2008 03:44
I'm not sure if everyone's clear on exactly what a tangent-space normal map is(other than GG), all they do is essentially store the direction(or normal vector) of the surface for each pixel, this gets added to the actual normal of the polygon(which is interpolated from the vertices). Normal maps don't store things like sharpness, power, or anything, all they do is store an angle that is to be added to the normal(or lighting direction) of the surface it's on. Typically normals are only stored in the vertices of an object so as you can imagine, if you have a large floor that's a single quad there's only one lighting direction, and if you add a light it's all going to be lit or not. If you add a normal map it's now calculating the lighting for every pixel, and depending on the resolution of the normal map, every pixel on your floor could have a different normal, meaning when the lighting is calculated, it's as if this surface has thousands of quads each with their different surface angles, except it's still 2 tris.

That said, it is possible to denormalize a normal map as to give it less or more influence over the lighting, but this is really a hack. The only issue with creating a normal map from a heightmap is that you can't reproduce all surfaces that a normal map can store in a heightmap. For example if I had a 1024^2 normal map, and going from left to right I store 45 degree angles(direction is irrelevant) but every other column of pixels is flat(i.e. 0.5,0.5,1.0), then I'd soon run out of RGB values to step up on a heightmap, unless I used a format that stored more than 256 values.

But in most cases the above scenario won't happen as you likely won't simulate very complex detail in a normal map as they aren't intended to. For small details like scratches in a surface or rivets, using a heightmap is fine. I'm not sure what you mean by dullness exactly, if you want your details(like scratches) to be less prominent then you need to reduce the contrast on your heightmap, or add to the blue on your normal map and then normalize it. Perhaps it's more intuitive to visualize the heightmap used to generate the normal map as if it were applied to a terrain, if I add some scratches then parts of my terrain lower, I then get 2 sides to this little trench and these have surface normals, I then read these normals and store them in my normal map, that's all that is done.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Oct 2008 13:56
I agree with everything dark coder has just said.

To illustrate what we are both talking about have a look at the attached demo.

It shows four normal mapped cubes. Each cube is textured plain brown. The normal map is a simple normal map created from a simple green-scale heightmap texture (included in the zip file) which in turn was created from a simple transformed Perlin noise function.

I don't see any need to use more than an appropriately constructed heightmap - there is an enormous range of rough or bumpy textures that can be simulated from those and is very standard practice.

Attachments

Login to view attachments
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Oct 2008 15:01
My idea was never to have dullness etc on the actual normal map. If you take a normal bump map, 256 shades of gray - but then say instead of using gray, the source bump map would be coloured with red representing the height, green representing the Z variable, and blue representing the sample range.

Right now I gather that most bump map to normal map conversions sample pixels around each point and the Z variable is usually set by the user.

So instead of the user specifying the sample range and Z setting for the whole conversion, each pixel could have it's own settings. If the part of the bump map is rough, you might want that to generate smoother normals so more of the actual texture is controlling the lighting. In the same sense, you might want sharper details to have more Z strength and a small sample range to bring them out.

But that's the 3rd time I've tried to explain myself, probably best just to stay out of it and get on with what I want to do.


Health, Ammo, and bacon and eggs!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Oct 2008 17:23
OK, example attached of my colour bumpmap idea.

Taken a dirt texture with bits of leaf and grass, and taking that as the red channel which represents the height, then the details like grass and that leaf get filled out in green to represent the sharpness or sample range. Then the whole lot gets combined into a blue channel which has a low contrast and bright which represents the strength of the angles.

So the dirt gets a higher sample range to make it smoother, the leaves get a lower sample range to make them sharper, and also a bit more strength to the angles calculated, making this high would exagerate the angles based on the point samples.

Code attached, will attach a screenie in the next post - but I'm sure you'll agree that the leaves and stuff pop out a lot more. This is all really just to give me some control over the end result.


Health, Ammo, and bacon and eggs!

Attachments

Login to view attachments
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Oct 2008 17:28
Here's a screenie.

Remember I'm not saying this is the best method or anything like that, it's an idea is all - why not mess around with it a little and see what it can do.


Health, Ammo, and bacon and eggs!

Attachments

Login to view attachments
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Oct 2008 18:13
When a normal map is created from a heightmap one of the things you need to specify is the relative height of the heightmap - which seems to be one of the things you are suggesting. For example, when I made the normal map I included in the earlier demo I specified that the highest point was 5% of the image width. There is no need to re-invent the wheel here.

Quote: "Remember I'm not saying this is the best method or anything like that"


Neither of the images RGB or GREYSCALE in your image are valid normal maps as normally ( ) understood and give very poor results if you try to use them as such (unless you decide to write special code to use them which you are free to do of course).
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Oct 2008 18:32
So what are the standard rules for creating a normal map then?

Tell me what I'm doing wrong when creating the RGB elements and I'll be your friend forever


Health, Ammo, and bacon and eggs!
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 18th Oct 2008 19:13 Edited at: 18th Oct 2008 19:13
But the left image could be made with a heightmap, just as the right could. Well... almost, neither of those images are valid normal maps as they aren't normalized, but they otherwise could be. The difference is that your greyscale image isn't a heightmap, it's just a greyscale image, if you were to get an actual heightmap of that dirt picture then you would be able to generate very accurate normal data for it, far more accurate than you could derive from any single colour map. Your method may work for certain images but when you rely on colour channels for certain things then it's clear that not all images will work, if the image lacks any red then you wouldn't even get any varying normal data. Also the beauty of heightmaps is that they are very intuitive to edit, brighter = higher, if you need something to be smoother then just blur it, or sharpen etc, they are very easy to edit and work fine 99% of the time.

[edit] OK I should F5 the page before posting after going AFK! Seems GG already covered this .

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Oct 2008 21:35 Edited at: 18th Oct 2008 21:38
Quote: "So what are the standard rules for creating a normal map then?"


The basic idea is as follows - and normal maps can be created using different, but similar, conventions.

The easiest to follow, but not the one I used earlier, uses world or object space normals, i.e. XYZ are the usual world or object coords.

A normal vector, (Nx, Ny, Nz) say, has length 1, i.e. Nx^2+Ny^2+Nz^2 = 1, and indicates the direction perpendicular to the surface.

Since the vector can, in general, be pointing in any direction the components are coded into the colour byte range (0 to 255) as follows:

R = 128+127.0*Nx
G = 128+127.0*Ny
B = 128+127.0*Nz

Put another way, for a normal map to be valid its RGB values should approximately satisfy

(R-128)^2+(G-128)^2+(B-128)^2 = 127^2 = 16129

(exact equality isn't usually possible because we are working with bytes).

All normal maps are coded this way (although some people might use the multiplier 128 instead of 127 in which case the value 256 would have to be reduced to 255 to give a valid byte).

For example, a typical pixel, e.g. (u, v) = (237, 235) near the centre of the image, from the normal map I posted earlier has RGB values (57, 34, 178). This gives

(R-128)^2+(G-128)^2+(B-128)^2 = 127^2 = 16377

(which rather suggests I used the multiplier 128 rather than 127 ).

When the normal map is read by a shader the values are scaled into the range 0 to 1 with 128 corresponding to 0.5 - but they need to be scaled again so each component is in the range -1 to 1. Hence you'll see things like the following in most normal mapping shaders:



The "tex2D" bit is just reading a colour value from the normal map and each RGBA component is in the range 0 to 1 initially. The rest of the calculation is just re-scaling to the range -1 to 1. The "float3" bit just means that we are ignoring the alpha component in this case.

That's the easy part.

There's one more complication I haven't mentioned so far. Most normal mapping shaders use "texture space" coordinates rather than world or object space coordinates. In this system the values Nx, Ny and Nz are coded into colour bytes as described above - but the coordinates are interpreted differently.

In this system, "X" (or "red") corresponds to the "U" texture coordinate direction in the object's polygons (this will almost always correspond to different directions in world or object space for different polys).

The "Y" (or "green") component corresponds to the polygon's "V" coordinate - which is a common source of error because V coords increase as you go "down" an image whereas "Y" in world or object coordinates usually increase in the "up" direction. (My early normal maps got this the wrong way round. )

The "Z" (or "blue")coordinate corresponds to the direction perpendicular to the polygon, with positive values pointing away from the object. For this reason most normal maps will have blue bytes in the range 128 to 255 - values less than 128 are legitimate but not really sensible as they would make the surface appear dark or black when the lighting calculation is done.

I'll spare you, for now, the details of how shaders convert the world light direction into texture space coords for a given polygon.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Oct 2008 03:25
Ahh, thanks for that GG.

I think it's better now, been a cheap ass and used vectors to normalize the XYZ floats. Gonna make a new example (with a proper height map). Z value is still just based on the height, but it does fall within the 128-255 range so hopefully that's ok.


Cheers again.


Health, Ammo, and bacon and eggs!
Dreamon Star
18
Years of Service
User Offline
Joined: 24th Feb 2007
Location: The Frozen Wasteland
Posted: 19th Oct 2008 21:10
Hey all, decided to try using some of the shaders from the ultimate shader package. The one thing i'm not getting is why is it when i use it in my own program the lighting either is too dark or too bright, and the objects do not appear to be affected by any lights.

I even made a new project which uses my x files and textures and the exact same code used in the demo for the shader, but there is no lighting. But when i used my objects in the shader demo.. .there was.... can anyone explain this... I am completely new to this shader thing... but would like to learn it, and have tried searching this problem already... no luck.

Thanks

www.myspace.com/norseblod, www.myspace.com/9thorigin

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Oct 2008 01:13
Better results now I think.

The right normal map is a dot3 (as best as I could make one at least), and the left normal map has the colour channels sharpening the point samples and Z depth has it's own colour channel. The actual height map is the same.


Health, Ammo, and bacon and eggs!

Attachments

Login to view attachments
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Oct 2008 03:08 Edited at: 20th Oct 2008 03:08
Van B

That's much better.

The right hand image is a better normal map - but both work.

Login to post a reply

Server time is: 2025-06-12 11:20:28
Your offset time is: 2025-06-12 11:20:28