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 / Green Gandalf's Terrain Texture Blender v2.0????????????????

Author
Message
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 18th Apr 2009 23:39 Edited at: 19th Apr 2009 02:37
Hi, I have been searching for a way to texture my landscapes and found this post ( Along with many other post on texturing a landscape).

http://forum.thegamecreators.com/?m=forum_view&t=90776&b=1

So I downloaded the example. This .FX file works fine if you use this code.


but If I load my own object into this example and REM out the make object plain 1,200,200 then Dark Basic pro crashes. This is the code I am using for this.


My mesh object is in the same Media folder as the .FX file along with all the example textures it came with. The only thing I did was put my mesh object into the folder and loaded the mesh.
Any one have a clue on what is going on? I also opened up the .fx file in notepad to see if there was anything pointing to "make object plain 1,200,200 " I seen nothing pointing to that. I have read that the .FX file can be applied to an object or many objects. I m not sure why it wont for my mesh.

Any help would be great.

EDIT_>>>>>>>>>>>>>>>>>

I went back and tried a few smaller models I made and they loaded fine. I guess there's a limit on the size of the 3D object. My land object is pretty big. So back to the search button I go.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2009 03:10
Quote: "I went back and tried a few smaller models I made and they loaded fine. I guess there's a limit on the size of the 3D object. My land object is pretty big."


That was the first thing I was going to suggest - but you've found out yourself which is good news.

Good luck with this. Any further problems, post back.
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 19th Apr 2009 06:18
I think I got it all but the Blue channel. I have attached an image of a test object I am using to learn what this shader does.

The first texture I call in the shader is the red channel, something like this.



The second texture I call in the shader is the green channel, something like this.


The third texture I call in the shader is the blue channel, some thing like this.



The final texture I call in the shader is the RGB map which tells the shader where to put the 3 textures? My blue channel is not showing for some reason. I might be wrong on how it is working.

Also is there a way to add to this shader using another RGB map.

for example:

I open the .FX file in notepad. I copy, then I paste the code where the original code stops. I load a different texture in the Red, Green, Blue channel. I then load a different RGB map (rgbone map.png). But the second RGB map is colored differently. I tried it but my land object vanished. Im not sure if this can be done or not??? I guess Im trying to get 6 channels on my land map. So I can have a nice texture across it.

ok I will stop here its turning into a book.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2009 12:14
Quote: "The final texture I call in the shader is the RGB map which tells the shader where to put the 3 textures? My blue channel is not showing for some reason. I might be wrong on how it is working."


I need to see the RGB map that you are using. The shader is a very simple one - it just blends the three textures according to the values of the RGB channels of the RGB map. For example, if the RGB map has a pixel RGB = (128, 128, 0) then this gets interpreted by the shader as RGB = (0.5, 0.5, 0) so the final colour is the average of the textures applied to the red and green channels, i.e. detailMap1 and detailMap2 in that shader.

You get best results if you make sure that your colours in the RGB map add up to about 255. If you use RGB = (255, 255, 255), for example, then the shader will add the three textures together and you will probably get "white out". Perhaps that is your problem?

Quote: "I open the .FX file in notepad. I copy, then I paste the code where the original code stops. I load a different texture in the Red, Green, Blue channel. I then load a different RGB map (rgbone map.png). But the second RGB map is colored differently. I tried it but my land object vanished. Im not sure if this can be done or not??? I guess Im trying to get 6 channels on my land map. So I can have a nice texture across it."


It can be done but you need to get the details right or the shader won't compile. If you're going to be experimenting with shaders your best bet is to get DarkShader so you can compile, test and edit them easily. Post your edited FX file and I'll see if it can be easily fixed.
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 19th Apr 2009 16:38
Thxs GG for helping me.

I went back into photoshop to see if my channels added up to 255,255,255 . the red and green did but the blue was 0,0,255. so I change it to 225,225,225 on the areas I wanted the blue channel to effect. I then loaded up the project file to test it. Its still the same. I have uploaded the rgb map I am using along with the red, green,blue channels in the rgb map file. and the code I am using is this, its the same source . FX I only change the png images I want to use for the texture.



Now here is the code I edited to see if I could use two rgb maps with different names.Basicly I just copied and pasted the code again and change the names.



I will look into Darkshader and see if I can get it, because it looks like I will be using shaders alot for my project.

again thank you for your help
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 19th Apr 2009 16:40 Edited at: 19th Apr 2009 16:41
This is the red channel from the rgb map.png if you need the rest of them let me now.
Dream And Death
19
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 19th Apr 2009 17:59
Err, I think you misunderstood GG.

He meant that the total of the three channels should add up to about 255, e.g. (128,128,0) or (200,10,45)

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 19th Apr 2009 18:36
Im not sure I understand.

I open up my rgb map in photo shop,and I use the color picker to see what values I have on the red, green, blue channels. The white areas are 255,255,255 and the black areas are 0,0,0 on each channel. So I changed the lvls on each channel using the lvl filter in photo shop so the values in all channels combined do not exceed 255. I recompile my test project to see if it worked. I still have the red, green channels showing the texture but its not as bright. The blue channel is still pure black and the texture doesn't show.I have uploaded everything I have for the test project in a zip file, maybe that will help.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 19th Apr 2009 20:53
You might kick yourself for this, I would in your position...

Look at the line :

Quote: "texture detailMap3 <string ResourceName = "snow,png";>;"


Do you see anything wrong?



I changed that, and it works =)

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2009 22:47 Edited at: 19th Apr 2009 22:50
Monk is right.

Regarding your attempt at 6 channels:

Quote: "Now here is the code I edited to see if I could use two rgb maps with different names.Basicly I just copied and pasted the code again and change the names."


it won't work like that. If it works at all, the shader compiler probably ignores the first set of declarations and uses the last one it sees.

What you need to do is something like the following. Change this:



to this:



Notice that each of the 8 textures and associated samplers has its own name in the above declarations, e.g. you are using two different RGB maps so they need to be given different names, e.g. rgbMap and rgbMap1 and the samplers need different names as well, e.g. rgbSample and rgbSample1.

The next thing to change is the pixel shader code so it uses all 8 textures. Change this:



to this:



The next thing to remember is that the sum of all six RGB components from the two RGB maps must equal 255 (unless you want to make parts of the map especially dark or bright).

That should work (I've checked it compiles but haven't tested it). Any problems post back.

Edit Corrected careless copy and paste.
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 19th Apr 2009 23:27
Monk, You are right. I am digging a hole right now in the back yard to hide in.... . Thank you for seeing that and pointing it out. Something so simple as ( , ) could make someone go crazy.( mainly me).

GG again thank you very much for helping me. I have copied and pasted the code in a text doc and i will work with it. I hope it will achieve what I am after in the texture department. I have seen a post on limbs and textures so I am going to spend some time researching that method as well. i will post back with my results soon.

Thxs

MP3D
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 20th Apr 2009 02:19
Ok it doesn't work. So I started looking at the code.( which my knowledge is very limited but that doesn't stop me from hashing through it to see if I can understand it and make it work.).

I noticed in the second part of the shader code there is no Float4 like in the first part of the shader code, so I put it in there still no eye candy. =( Here is the code now with the changes.


GG you said you complied it and it complied fine. I dont have a shader program to complie this. I opened the shader file in notepad and copied and pasted the new code and saved it. So hopefully this method will do the trick for now untill I can purchase DarkShader.



I have one more question to make sure I understand what your saying about RGBmap.png and RGBMap1.png and the value of 255. When I edit RGBmap.png I make sure that the red= 255,green=255,blue=255
I use pure black ( 0,0,0 ) on the areas I don't want the texture to effect and pure white ( 255,255,255 )on the areas I do want it to cover. This is the same for RGBMap1.png ...I know that I can use light shades of grey to blend the textures together but for now I want them to have shape edges.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 20th Apr 2009 18:38 Edited at: 20th Apr 2009 18:54
Quote: " float4 rgbColours = tex2D(rgbSample,In.UV);
float4 baseColour = tex2D(detailSample1,repeatScale*In.UV)*rgbColours.r;
baseColour += tex2D(detailSample2,repeatScale*In.UV)*rgbColours.g;
baseColour += tex2D(detailSample3,repeatScale*In.UV)*rgbColours.b;

// read the second RGB map and second three textures
rgbColours = tex2D(rgbSample1,In.UV);
baseColour += tex2D(detailSample4,repeatScale*In.UV)*rgbColours.r;
baseColour += tex2D(detailSample5,repeatScale*In.UV)*rgbColours.g;
baseColour += tex2D(detailSample6,repeatScale*In.UV)*rgbColours.b;

"


How come only the first two lines have float4 in front?
Elsewise looks ok.... Ill try it later =) but i have work to do now....
Any chance you could post your current code and shader and pics? Cheers,
Monk

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Apr 2009 22:08 Edited at: 20th Apr 2009 22:09
Quote: "I noticed in the second part of the shader code there is no Float4 like in the first part of the shader code, so I put it in there still no eye candy."


Quote: "How come only the first two lines have float4 in front?"


Because you only need to declare variables once - if you declare a variable twice (within the same scope such as twice within the pixel shader or twice within the vertex shader) you'll get a compilation error like this:



Quote: "I have one more question to make sure I understand what your saying about RGBmap.png and RGBMap1.png and the value of 255. When I edit RGBmap.png I make sure that the red= 255,green=255,blue=255
I use pure black ( 0,0,0 ) on the areas I don't want the texture to effect and pure white ( 255,255,255 )on the areas I do want it to cover. This is the same for RGBMap1.png ...I know that I can use light shades of grey to blend the textures together but for now I want them to have shape edges."


You've confused me in exactly the same way as you confused Dream And Death yesterday. I said quite clearly:

Quote: "The next thing to remember is that the sum of all six RGB components from the two RGB maps must equal 255 (unless you want to make parts of the map especially dark or bright)."


It should be obvious from that sentence that if "I make sure that the red= 255,green=255,blue=255" then the sum of those three components alone will be 255+255+255 = 765. You'll get an even larger figure when you add in the three values from the second map.

Quote: "I use pure black ( 0,0,0 ) on the areas I don't want the texture to effect and pure white ( 255,255,255 )on the areas I do want it to cover."


I don't know what you mean by that. Where do black and white come in? Your demo used red, green and blue which is correct if you want three separate textures without mixing.

If you want a pixel to get the colour of the fifth texture, i.e. detailMap5, then you must, for that pixel, set the rgbMap pixel to black, i.e. RGB = (0, 0, 0) and the rgbMap1 pixel to green, i.e. RGB = (0, 255, 0).

The sum of those six colour components is ... 255 (255 = 0 + 0 + 0 + 0 + 255 + 0). What do you think it is?

Quote: "Ok it doesn't work."


Yes it does. See screenshot in my next post. But your version doesn't - you've deleted the vertex shader and several other things as well. Why? Did you check what you'd done?
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Apr 2009 22:10 Edited at: 20th Apr 2009 22:11
Working screenshot showing six textures:

Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 20th Apr 2009 22:41
Any chance you can post the shader that you used GG?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Apr 2009 01:54
I didn't realise two copy and pastes to MP3D's working version of my original code were so tricky.

Here it is. I've also updated the comment at the start in case anyone gets confused by that as well. For the screenshot I changed the value of repeatScale to 1.

MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 21st Apr 2009 02:05 Edited at: 21st Apr 2009 02:12
Thxs for the reply guys. I just got home from work and haven't checked what I did wrong on the shader. And if I have confused anyone I am sorry. My lack of knowledge on this is very limited, so I am trying to use the right terminology to explain what I'm asking and not confuse anyone. And in the process learn.

GG I really appreciate the time you are spending to help me with this, Please bare with me, as I stumble through this. I don't want to down load the shader you have that works but I want to work on the code you gave me and make it work. So monk PM GG to see if he will give it to you. I really don't want it in this post. I will get it to work, it will take me some time to see were I went wrong...I WILLLLLL make it work.....I hope...lolol

You ask where the black color comes into play.This is what I mean.
I open up my RGBmap in photo shop CS .I click on the channels button.This displays the red, green, blue channels for that picture. I paint on the channels them self's. not the actual map. and those channels are black and white. so i use a black and white paint brush to paint on the channels...I hope I didn't confuse you...Why do I do this.........um I don't know, I just do..


I will post back my results soon, and hopefully a screen shot of 6 textures on my world map.
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 21st Apr 2009 03:34
ok I got it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thxs GG......I will post my WIP... tomorrow night. My next step is to learn how to blend the textures so when they cross each other it's not so bright in that area. I am thinking of darking those areas so they blend/darken.

Monk do you want me to post the shader.......or.......do you want to make it work????? Your choice its more rewarding if you figure it out......let me know what you want to do.....
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Apr 2009 14:07
Quote: "You ask where the black color comes into play.This is what I mean.
I open up my RGBmap in photo shop CS .I click on the channels button.This displays the red, green, blue channels for that picture. I paint on the channels them self's. not the actual map. and those channels are black and white. so i use a black and white paint brush to paint on the channels...I hope I didn't confuse you...Why do I do this.........um I don't know, I just do.."


Thanks. I understand what you mean now. I don't have PhotoShop so didn't realise how it works.

Quote: "its more rewarding if you figure it out"


I agree - but poor Monk was getting so upset by my failure to post the whole thing that I thought I'd better calm him down and post it.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 21st Apr 2009 18:28
I feel much more complete now you've posted that. Thanks =)

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Apr 2009 00:05
Quote: "I feel much more complete now you've posted that."


MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 22nd Apr 2009 02:03
yes GG, some time's the most simplest things can be really hard to figure out. lol... Again thank you very much for helping me. And also not posting the .FX file that did work before I had a chance to figure it out on my on my own. It was worth the hair loss even tho it was just a matter of coping ans pasting your code in the right spot. I still have the hole in my back yard so I am going to go lay in it for awhile. lol................... I don't have time to post what I have right now but I will.


And Monk...enjoy the fruit my friend....
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Apr 2009 02:13
Quote: "I don't have time to post what I have right now but I will."


I dread to think how many times I have said that - and not done it.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 22nd Apr 2009 21:02
Quote: "I dread to think how many times I have said that - and not done it. "


Hehe

I was wondering, for my game that I've started, could something like this shader be adapted to act as a tree map, that is, have a picture with dots where I wish to position trees, and then change the shader so that it positions the object there?

Or is there another way to do that?

The tricky bit is, I'm trying to place the trees so they don't cover the whole level, but make it tricky in places, and provide cover in others.... And until I get that right, the location of the trees will keep changing, so I need a fairly simple way to pass the tree positions to the game. I could do it by hand, but if there are shortcuts, it would be easier =)

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Apr 2009 22:23
Quote: "I was wondering, for my game that I've started, could something like this shader be adapted to act as a tree map, that is, have a picture with dots where I wish to position trees, and then change the shader so that it positions the object there?"


I'm 99% sure you can't using PS2 or PS3 - but you might be able to with PS4 since it allows "geometry shaders", i.e. you can build vertices and so on in the shader. But I have no experience of PS3 or PS4 yet (and DBPro doesn't support PS4 which requires DX10).

Quote: "Or is there another way to do that?"


Yes. If the trees are simple objects then when you load your level just scan the tree map to store the positions of the trees in an array and position the trees in the usual way.

Quote: "The tricky bit is, I'm trying to place the trees so they don't cover the whole level, but make it tricky in places, and provide cover in others.... And until I get that right, the location of the trees will keep changing, so I need a fairly simple way to pass the tree positions to the game. I could do it by hand, but if there are shortcuts, it would be easier"


Not sure I understand. Are the positions of the trees fixed? If so then there is no problem.
MP3D
18
Years of Service
User Offline
Joined: 26th Jan 2007
Location:
Posted: 23rd Apr 2009 02:12
Monk, What I do to position any object on my world is this ( not sure if this is a good method but it works for me.)

I build the whole world as one object in my 3D modeler, placing all my objects on the world map where they need to be. Then I start to export my world objects as groups, trees, buildings, bridges, my world map ect...
This stores the position of each object as a group. Now I open up DarkBasic pro and load my world object. I place/position object 1,0,0,0 which is my world map, then I start to load all my other grouped objects and position object 2,3,4,5,6,7 ect at 0.0.0 . Because we did all the positioning in our 3D modeler we do not need to find the positions on the world map...=)

Now the bad thing that could happen doing it this way. ( sorry but I got to tell you.) The poly/vertices count can get really high doing this and the .X and .3ds format only supports 65.000 polyies when you export it. ( I have to recheck the limit on those formats, I think I might be wrong but I am close.) There are a few things you can do to keep this form happening.

1:You can use a few objects for each group, instead of grouping 50 trees together only group 25. So you will have more objects/groups to load. Which wouldn't change anything on the world map. everything would still be placed in the right spot.

2: you can export the whole group, then import it into a poly reduction tool to reduce the poly count....The draw back to this is, in some cases you will lose detail on how the mesh looks. It becomes more blocky. For a free tool that will do this (Goggle) MeshLab. Its free and works great. If you have any more questions concerning 3D modeling let me know. I can help you on that.

Hope this helps.
MP3D
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 23rd Apr 2009 09:32
Sounds like a good idea Mp3D.

Unfortunately, I think that loading them as one object would kill my pc, Im trying to position about 1000 trees of about 400 polys each, on a terrain made of 31 20k tiles....Its a big level. Ill keep working with the idea. =)

What I was trying to say GG, was that my problem at the moment, is trying to decide upon the position of the trees, I havent decided the best position for gameplay yet. Hence, I was looking for a way that can change the position of the trees easily, ie A tree map.

Ill try it with an array, as long as there isnt an array max size, I should be fine.

Thanks for your help guys,
Monk

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd Apr 2009 13:58
You could use a normal image, load in as a bitmap and check for a certain color pixel, then get it's x/z position and position it on the world after scaling it to match.

For example, on the bitmap look at a random pixel, if it's (for example) white, place a tree on the map. if it isn't then don't. And, to maintain uniformity, you you always use the same random seed, the trees will always be in the same place.

This is the way the unreal engine does it. This way, you can also alter object colours based on images to provide some variation to the objects without having to create many textures for them.

Your signature has been erased by a mod because it is way too awesome!
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Apr 2009 14:27
Quote: "You could use a normal image, load in as a bitmap and check for a certain color pixel, then get it's x/z position and position it on the world after scaling it to match."


That's what I had in mind - you just scan the map once and store the positions in an array.
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd Apr 2009 14:32
Indeed. Great minds hey! lol

Your signature has been erased by a mod because it is way too awesome!
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 23rd Apr 2009 18:13
That looks like the way I'm gonna do it. =)

Cheers guys!

Login to post a reply

Server time is: 2025-08-09 02:28:35
Your offset time is: 2025-08-09 02:28:35