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 / Blending Two Textures

Author
Message
The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 19th Apr 2010 05:11
Ok, I know there is "Set Blend Mapping On", although, through everything I have read about it, I have not been able to answer this one question.

I'll explain what I'm hoping to achieve here first: I am making a face generator for my newest game. One part that I really have been focusing on now is the color and tone of the skin. I have 2 textures (light skin, and dark). Now, what I am thinking of doing is having the light skin as the base level, then adjust the transparency of the dark skin to get it to the color you wish. I don't really know how well this method would work. I am stuck on how to adjust the transparency of the second layer in real time.

How would I go about doing this??? is blend mapping the right thing i'm looking for? or should I look elsewhere, AND would adjusting the transparency be the right thing to do? or just make many different textures of all different colors and just add them to the object thus only using 1 texture..?

Thanks for any advise or ideas all

www.myspace.com/norseblod
Benjames8
16
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 19th Apr 2010 05:44
Im not sure how to adjust transparency in real time nor am i sure what shader can be used for multi-textureing. But by using photoshop or some other image program you can test to see if making a parcialy transparent face over another is going to be a good effect. If it does then It might be worth looking into if not then screw it and make like 7 face textures to choose from.
The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 19th Apr 2010 05:52
Yeah... I just tried it out... and it seems to work as one would think. It looks like a nice transition from light to dark. If I can find a way to do this, I will also add an age aspect in which the skin becomes more wrinkled, but first things first. It does look good, but now just need to know how to set transparencies in real time. I am sure a shader might be able to do it, but i'm not shader savvy yet (still). So, still thinking of the blend mapping command... if it's good or not? and how? thanks for the input

www.myspace.com/norseblod
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2010 13:27
You can do this using the "LERP" blending option and a third image which sets the amount of blending between the two images. You can then have a set of small images, e.g. 4x4, for the different levels of blending and switch between them in real-time. At one extreme you could have 256 such images, with colours RGB(0, 0, 0), RGB(1,1,1), ..., RGB(255,255,255) or you could opt for bigger steps such as RGB(0,0,0), RGB(5,5,5), etc.

This method uses an undocumented feature of the set blend mapping on command.

If you're interested I'll see if I can put together a simple demo, in which case could you supply two test skin images for me to play with?
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 19th Apr 2010 18:11
I'd be interested in seeing that GG. You know how I love the SET BLEND MAPPING ON command.

While reading this thread though, the idea that popped into my head was to make an array of the various colors you want to have available. Then use a selector to move up and down the array picking that color. Have a bitmap standing by and just CLS it with that color, grab the image, and retexture the model.

I'm doing something similar that allows the player to choose the color of their ship.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2010 18:43
OK. Just realised you can probably do this yourselves. There's a code snippet provided with DBPro which shows how you can use the LERP option.

Look at Projects/Snippets/LerpingTextures and study the code. The code doesn't explain everything by any means but you should be able to see how to modify the example along the lines I described above.

I'll give you a hand if you're still stuck.

I just love these undocumented features.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 19th Apr 2010 18:46
Or do it the best way

Rawwrr. Sig Fail.

The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 19th Apr 2010 18:54 Edited at: 19th Apr 2010 19:15
Hi guys,

Yes, I would love to see how that would be done GG, unfortunately, I am currently at work and do not have access to the files to send you, although I will make sure I will send them to you as soon as I get home and have a minute tonight. The idea of having only a few small images for transparencies sounds great!

@KisTech, actually, I do have them set as an array. The main reason I am is so that I can easily save and reload the value when you load your previously saved game. Although, instead of clearing the objects texture every loop, I only clear it when the slider bar has been pressed and retexture directly after. This is how I hope to accomplish this, as this is how I accomplished the face/bone manipulations. If I understood what you said properly, that method would have too many this many textures to cycle through, as I have 6 maybe 7 races, 2 genders, varying ages, and then varying skin colors, probably ranging over 1000 images that way.. haha.

EDIT: Ok, sounds good GG, I'll take a look when I get home tonight... thanks!!!

Yes, undocumented features are nice, when they become known of... haha...

www.myspace.com/norseblod
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: 19th Apr 2010 20:07
@The Viking:

I could be wrong or misread what you want to achieve, but instead of adjusting the transparency, maybe you could just as easily change the color? Like, say you have two planes, one plain textured with the face texture, and the other plane on top with just a plain color and ghosted? Then you would see through the colored plain and just change the color to flesh colors or more brown or yellow? Just some thought...

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: 19th Apr 2010 22:41
Mad Nightmare

How does the GIMP help with the real time issue?
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 19th Apr 2010 23:01
Ah you're right. Sorry I misunderstood.

Rawwrr. Sig Fail.

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 19th Apr 2010 23:11
@The Viking,

Actually, the method I described would only be updated if the slider were moved, and there would only be 1 texture. You would be making the texture yourself in real-time based on the color value in the array.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Apr 2010 00:47
Try the attached (couldn't wait for the rest of you any longer - I need a beer ).

Press and hold "b" to change the blending between the left and right images in real time.
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 20th Apr 2010 01:27
Now that's cool Green Gandalf! Is there anything you can't do with Blend Mapping?
The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 20th Apr 2010 01:38
@GG, once again, you never cease to amaze me... I would buy you that beer if it were possible! But, since I'm here and you're there, this is the best I could do, I think

On topic: That worked great, and looks just as I had hoped. I didn't get time to look it over, yet, but I would think I could add more than just the 2 layers if I wished, and with some tampering? I guess I'll find out when I get around to looking at it. Thank you very much again!!!!

www.myspace.com/norseblod
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Apr 2010 01:40
Thanks.

Quote: "Is there anything you can't do with Blend Mapping?"


I've often wondered that myself. DirectX9 allows up to 8 texture blending stages which should allow plenty of scope for the imagination. That demo uses only three.
The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 20th Apr 2010 02:27
Quote: "I've often wondered that myself. DirectX9 allows up to 8 texture blending stages which should allow plenty of scope for the imagination."


That's great! It means that I should have no problem with getting my 3 textures going and maybe a 4th one. I finally got time to go look through it.

www.myspace.com/norseblod
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 20th Apr 2010 02:50
GG, nicely done.

The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 20th Apr 2010 04:38 Edited at: 20th Apr 2010 06:27
It appears that when I apply this to a 3d model, the texture looks very blocky and greyscale. I've noticed this before when attempting to do this before. Also, it appears that the UV mapping disappears... I could attach an image if you need it, but I think it's self explanatory. Any advise would be appreciated VERY VERY much.

EDIT: As a side note, the images I am using work perfectly on the planes in the example that GG made, and a single texture works just fine also.

EDIT... AGAIN: OOOPS, stupid error... wrong image file... no wonder why... thanks again all!!

www.myspace.com/norseblod
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 25th Apr 2010 02:58 Edited at: 25th Apr 2010 03:02
@Green Gandalf.

I'm making my own particle engine. I was wondering if there was a way of doing something similar to this, but to simply colourise a texture from a simple RGB value, not from 2 textures? For example I want to be able to blend the particle colour over time, using defined settings, but with only 1 texture file and a colour value. The "over time" bit is easy but I'm not sure how to do the blending efficiently enough to be used for a particle engine

PS I hope that makes sense
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 25th Apr 2010 08:50
how about using dark shader. it will be much easier for you.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Apr 2010 13:54 Edited at: 25th Apr 2010 14:59
Quote: "For example I want to be able to blend the particle colour over time, using defined settings, but with only 1 texture file and a colour value."


That ought to be simple but I can't think of a way using DBPro commands off-hand. Any particular reason for doing it that way? You could just modify my earlier demo of course.

I usually do all this sort of thing with a shader as basjak suggests. Much simpler than trying to grapple with the blend modes.

Edit

Quote: "That ought to be simple but I can't think of a way using DBPro commands off-hand."


I think there is a way. Watch this space (although I don't think "simple" is the right word).

That's blown another quiet Sunday's game playing.

Edit2

Here's my best offering for now. It uses two images, one for the actual image (a red circle on a green backgrond in the demo), another for the chosen colour value (blue in the demo). The amount of blending is controlled by the lighting and blending commands.



By some strange coincidence it's a variation of my earlier demo...
The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 25th Apr 2010 15:26 Edited at: 25th Apr 2010 16:22
Hey, do you think there is a way to get the blend mapping to work with a bump/specular/normalmap shader? or could it just be adding a normal mapping layer for this method?

EDIT: The main problem I can see is that I don't just have 2 textures which it blends, I now have 4... so to do normal mapping it would have to blend between 2 different normal maps.

www.myspace.com/norseblod
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 25th Apr 2010 16:28 Edited at: 25th Apr 2010 16:44
Ooo thanks Green Gandalf, I'll test this as soon as I cure a slight bug in my particle system.

Quote: "I usually do all this sort of thing with a shader as basjak suggests. Much simpler than trying to grapple with the blend modes. "


Hmmm. Which would you say would be the most efficient (blend/ shader)? I've not added any shaders to my game as yet (after I've added this particle engine to my game that's the next stage) and have very little experience with them. As I'm sure you'll know with a particle engine efficiency is key.

Quote: "That's blown another quiet Sunday's game playing"


Sorry


EDIT - Bug cured, so I'll get to adding this very soon
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Apr 2010 16:47 Edited at: 25th Apr 2010 16:49
Quote: "Hey, do you think there is a way to get the blend mapping to work with a bump/specular/normalmap shader?"


You'd have to do the blending in the shader as far as I know.

There's an example of this (using 8 textures, i.e. 4 base textures plus 4 normal maps) in one of my terrain shaders on this thread:

shaders for advanced terrain

[Edit: added initial quote to make it clear who I was talking to ]
The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 25th Apr 2010 18:01 Edited at: 25th Apr 2010 18:05
@GG, that does look good. I tried compiling it and continued to get a syntax error at:


Ok, now it says that it must be integer when referencing an array

www.myspace.com/norseblod
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Apr 2010 18:29
Those demos use some of IanM's Matrix1 functions, e.g. max, min, etc. "min" just calculates the minimum of the two arguments.
The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 26th Apr 2010 03:24
Ok, that makes sense then. I got it working and it looks good. For now, i'll just keep it as it is, until I figure out how much normal/bump mapping i really do want in the game, since I'm making my own textures, and they are not that good (they are painted textures) i may need this to help make it look better.

thanks again for help.

www.myspace.com/norseblod

Login to post a reply

Server time is: 2026-07-26 04:28:11
Your offset time is: 2026-07-26 04:28:11