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 / Mapping a normal map to an object?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Apr 2010 03:34
Hi,

What's the best way to map a normal map to an object?

I tried all mapping commands and set bump mapping on looks the best, but the object is all gooey. Here's a screenshot to show what it looks like:



Is that the correct command, or is there a better way to do it? Or is my graphics card too old to support this stuff?

TheComet

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 3rd Apr 2010 16:54
Use a normal mapping shader
http://www.evolved-software.com/shaders/Shaders_BumpMapping.html

If it hasn't exploded yet, I haven't touched it.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 3rd Apr 2010 17:51
set blend mapping on OBJID, 0, NORMIMG, 3, 24
set blend mapping on OBJID, 1, TEXTURE, 3, 4

If you have specular or emissive textures let me know and I can help with that.

OR use a shader. I've got one that does Normal, Specular, and Emissive I can give you if you want.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Apr 2010 01:24
@Madscientist

Looks cool, will check

@KISTech

I only have the normal map texture and the object texture. I tried what you said, and it looks just as it should. The only thing annoying me now is that it shades too sharply into a black shade... How can I brighten that up?



TheComet

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 4th Apr 2010 04:40
Change the 4 to a 5 on the second set blend mapping on command.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Apr 2010 18:44 Edited at: 4th Apr 2010 18:56
Thanks, that worked

[EDIT] Another problem. I have a part of the level where the lighting is pink, and another part where the lighting is yellow. And for some reason Mewtwo turns black when he enters the yellow part. Why is this?

TheComet

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 5th Apr 2010 02:53
Something would have to be altering the model's texture, or the lighting is changed in there. Is it a direct walk from one to the other, or does it involve loading a level and entering?

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Apr 2010 11:26
It's a direct walk. There's like a barrier there, and any part of the model after the barrier is just black.

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Apr 2010 15:33
Are you using directional or positional lights?
How are you changing the light colours?
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 5th Apr 2010 17:50
Could the barrier be blocking the light?

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Apr 2010 18:30
Sorry I'm confusing you all, I'll post a pic and a video of what's happening:



http://www.youtube.com/watch?v=6mq3KoCgpHs

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Apr 2010 20:18
I don't feel confused - yet. I don't think we can help you unless you tell us:

1. whether you are using positional or directional lights (my guess is directional);
2. the code you are using to change the light from pink to yellow;
3. whether you are using different lights, e.g. light 0 and light 1;
4. anything else light related that I haven't thought of ().
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Apr 2010 20:29
Ah, sorry.

1. The level has 5 directional lights (1-5), light 0 is ambient and colored black.

2. The lights don't change, so I don't have any code.

3. The strongest lights are light 1 and 2, light 1 is the pink light shining from the left, and light 2 the yellow light shining from the right. Light 3 and 4 are pointing upwards on the walls from both sides of the castle and Light 5 is shining on the background.

4. They all have different colors, range, angle and brightness.

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Apr 2010 22:38
I'm as baffled as you are. Perhaps KISTech has an idea.

By the way, that video was an excellent demonstration of the problem.
mike5424
17
Years of Service
User Offline
Joined: 30th Mar 2009
Location:
Posted: 5th Apr 2010 23:43
Quote: "light 0 is ambient and colored black."

have you tried changing the color of this light?

---
Math89
22
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 6th Apr 2010 01:29
I strongly advise you not to use blend mapping for normal mapping because of the way it works: it takes the surface colour of the object (diffuse + lights) and dot products in with the normal map. This means that the colour of your surface determines the virtual light direction (so an object under a green light will behave differently to an object in a red light). This also means that the normals of your object aren't taken in account, but because of the previous problem it's already a big crap anyway, and shouldn't be use for any kind scene other than a blueish plain in the vacuum with no light and a 100% ambient light (which ruins the point of normal mapping).
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Apr 2010 01:41
I don't see that when I try it. In fact I don't see the light colour having any effect at all. In any case, why would what you describe have the symptoms shown in the video - i.e. what is so special about that "barrier" that TheComet describes?
Math89
22
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 6th Apr 2010 02:03
Last time I tried was a few years ago, but I'm pretty sure that light colours had an impact. But I may be wrong (especially since a lot has happened to DBPro since then).
But the barrier could be due to the fact that it no longer receives enough blue light. If the blue component drops below 128, it is considered as being backlit (and thus, not lit at all). This is obviously based on the assumption that I was right about the light colour having an impact.
Jeff Miller
21
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 6th Apr 2010 02:04
I don't think light(0) can be ambient. I think the ambient light is a separate matter, and there can only be one color and intensity setting(as as percentage) for it. You may have inadvertently set another type of light to black, and that can have an effect. A year or two ago some skillful fellow used a "black light" to create shadows of bouncing balls, in the code snippets I think.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 6th Apr 2010 02:24
From my tests, light 0 is the ambient light. If you

hide light 0

instead of changing it's color to black, that might do the trick.

It's also possible that the Yellow light doesn't point in the direction you think it's pointing. It's pretty dark in that area, and given the location of the light I would expect some dark areas around the pillar anyway.

You also may not have the color bright enough. What RGB values did you set the Yellow light to?

If it's below 255,255,128, then try that.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Apr 2010 02:41
Quote: " light 0 is the ambient light"


It isn't.

Try this:

Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 6th Apr 2010 04:30 Edited at: 6th Apr 2010 04:34
I tried normal mapping a while back without much sucess. Seemed it just worked with one light, and didn't use ambient.

I imagine your character only responds to the pink light, and therefore once it is out of range, it will be black. Try switching the light numbers for the pink and yellow lights. I imagine then he will be yellow near the yellow light, and black otherwise.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Apr 2010 12:47
Yes, that's my guess too - but he still hasn't told us what kind of light he's using. It seems that the answers to my earlier questions are Dark Secrets.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 6th Apr 2010 15:06


I don't know how other I shall explain. Maybe code will help:



TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Apr 2010 16:00 Edited at: 6th Apr 2010 17:33


Quite a clue there don't you think? You're using spot lights with a limited range. Have you checked the ranges against the location of your problem? Also, since you are using spot lights, if they are facing the wrong way then your object won't be lit until it gets inside the "cone" of light. I suggest you check the values you are using. What light number are you using for the pink light?

What about the default light 0? Are you using that?

Edit Sorry, I somehow forgot your post ( ) when you said:

Quote: "1. The level has 5 directional lights (1-5), light 0 is ambient and colored black.

2. The lights don't change, so I don't have any code.

3. The strongest lights are light 1 and 2, light 1 is the pink light shining from the left, and light 2 the yellow light shining from the right. Light 3 and 4 are pointing upwards on the walls from both sides of the castle and Light 5 is shining on the background.

4. They all have different colors, range, angle and brightness."


You are NOT using directional lights. You are using spot lights as is clear from your snippet - and as I suggested earlier in this post I think you need to check the values you've used for things like position, angle and range.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 6th Apr 2010 18:02
Quote: "It isn't."


I sit corrected..

Need more ..

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Apr 2010 00:48
OK, I played around with the values, and yes, the are all pointed correctly and all angles are correct. And it seems as soon as the player leaves pink light range, it goes black. But what I didn't understand was why the player was still glowing when I took out the pink light?

Anyway, I am going to try and approach this from another angle. Is it possible to create a texture out of the normal map and the base texture? Attached is the normal map and the texture, if anyone could fuse them together I'd be much appreciative.

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Apr 2010 01:11
Quote: "OK, I played around with the values, and yes, the are all pointed correctly and all angles are correct"


What about positioning?

I've had difficulty getting KISTech's blending code to work correctly myself - in fact I'd like to know how you got it working before the "barrier". All my attempts result in a black image with a few specular highlights. The new (i.e. U7.3 upgrade ) version of the blending command allows greater access to the DirectX constants and blending states so it may be possible to get things working correctly that way - once I've worked out how to use the new version.

Quote: "Anyway, I am going to try and approach this from another angle. Is it possible to create a texture out of the normal map and the base texture? Attached is the normal map and the texture, if anyone could fuse them together I'd be much appreciative."


Yes. Just use any normal mapping shader (Evolved's, mine, various others?). Apply that and the textures to a plain and take a screenshot. Simples.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 7th Apr 2010 01:17
Quote: "I've had difficulty getting KISTech's blending code to work correctly myself"


So have I..

Many hours of trial and error were involved.

I can't say I've ever experienced the issue where only one light works with it though. Then again, I've been working in space, and there's only been one light source there.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Apr 2010 01:44 Edited at: 7th Apr 2010 02:14
Quote: "I can't say I've ever experienced the issue where only one light works with it though. Then again, I've been working in space, and there's only been one light source there."


I can't even get it to work predictably with one light. Which light is it using anyway? I wish I understood what Math89 said earlier because I think he might be on the right track.

I suspect you can't get it working correctly in DBPro. I found a demo on dot3 bumpmapping demo which suggests you need to do a lot more work per vertex than is done behind the scenes in DBPro. In fact it seems to use steps very similar to the ones used by the various bumpmapping shaders so you might as well stick with one of those since they are simpler. Why don't you use one? There are people here who can help.

Edit A few tests suggest Math89 is on to something. I just fail to see what exactly at the moment.
Jeff Miller
21
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 7th Apr 2010 02:38
I can't find in his code where he sets light 0 (which he thinks is ambient) to black, which can be a projected color and not an absence of color if he used negative RGB values.

If he means to remove the influence of the default light 0, then Hide Light would be the proper command, rather than setting its color to black (which he said he did). The code seems to deal with lights 1+.

I incorrectly suggested above that the black light projection example was in the Snippets. It's not, it's the last code example of the first post in a thread in the 20-Line forum here:

http://forum.thegamecreators.com/?m=forum_view&t=125577&b=11

This might be interfering with the intended result.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Apr 2010 13:18
Quote: "I can't find in his code where he sets light 0 (which he thinks is ambient) to black, which can be a projected color and not an absence of color if he used negative RGB values."


*Face-desk*

I forgot, it should be:



In the editor all of the values are therefor 0, so the range, angle, and color are 0. I also didn't set light 0 to a spot light in case that's important.

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Apr 2010 14:38
Quote: "Edit A few tests suggest Math89 is on to something. I just fail to see what exactly at the moment"


I was being very dense yesterday .

Math89 explained exactly what was wrong in his post. The problem is that to work correctly the "lighting" needs to be computed and interpreted as light direction vectors in tangent space. This is exactly what is done in a standard normal mapping shader and can't be done easily in DBPro directly.

What's happening in your case is that the blending dot3 operation thinks that the diffuse lighting has been computed that way so two things happen. First, both the normal map texture value and the diffuse component are biased downwards by 128 so values less than 128 correspond to negative directions. The resulting direction vectors are then combined in a dot product operation to give the final diffuse value per pixel. Unfortunately this gives the wrong result in this case because the diffuse component is provided in the wrong form and is the usual diffuse value per pixel. If you change any of your lights to include blue values above 128 then you should see a lighting effect on your object - but the lighting won't be calculated correctly.

I think the simple solution is to use a shader. I can help you with that.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 7th Apr 2010 20:25
Given all of that, I would tend to agree. Use a shader. Your framerate will be higher with a shader anyway.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Apr 2010 21:37
Quote: "I can help you with that. "


That'd be great

TheComet

Latch
20
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Apr 2010 00:26
How about baking the textures before hand for the characters with all of the bump mapping and such? That would be a performance boost.

Enjoy your day.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Apr 2010 01:50
It certainly would - but would look odd if the objects from one light area to another or turned around. Pre-baked lighting images need to be used carefully and sparingly. It's best to avoid them altogether if possible.

Quote: "That'd be great"


Have you got one already which we can work from? Evolved has posted several in various places (or on his website) and I've got one or two lying around (not for spot lights yet - but that should be fixable).
Latch
20
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Apr 2010 02:39
Quote: "Pre-baked lighting images need to be used carefully and sparingly. It's best to avoid them altogether if possible."

Not to argue or anything, but texture baking and light mapping is a standard - especially when desiring rendered like output in games where performance is an issue.

Enjoy your day.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Apr 2010 03:04
Quote: "but texture baking and light mapping is a standard "


It certainly is, for things like scenery and buildings - but not for the main objects in the scene such as players.

I probably worded my statement rather badly. Certainly the trend is for increasingly realistic lighting which means a move away from lightmaps. The games I play probably use lightmaps and reserve dynamic lighting for the central characters - for example, the main character might walk across a town square with a shadow underneath them, but the minor characters in the scene might not have any shadows. If you watch closely you'll see such things - which is probably why I keep getting killed .
Latch
20
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Apr 2010 03:26
Quote: "which is probably why I keep getting killed "

hmmm... there's no shadow under that character's arm. And there's no highlight on the back of it's neck... OH! the monster just ate me!

Enjoy your day.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Apr 2010 12:51
Exactly.

I also seem () to be on the lookout for ugly seams as well - noticed several in Dragon Agerigins and now I keep looking for them instead of paying attention.

Anyway, back on topic, I've decided to write a simple bump mapping shader which uses the DOT3 blending operation instead of a pixel shader. I'm doing this as a learning exercise as much as anything (I don't usually make much use of the fixed pipeline states and operations) - it'll also be interesting to see how its performance compares with a full shader solution. The first draft is working and I'll post it here when I've finished.

Login to post a reply

Server time is: 2026-07-26 15:31:52
Your offset time is: 2026-07-26 15:31:52