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 / Multitextured terrain problem with shaders.

Author
Message
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 10th Jul 2015 03:28
Hi all.
I have a texture painted, segmented terrain in x format, consisting of six different textures. My question is if it is possible to apply some form of normal mapping shader to this model with so many textures applied? Something that has to retain the smooth blends between these six textures, or even more, and if so, which to use?

I know there are several terrain shaders available, but most I have looked at either only support a limited amount of textures, or require you to make the terrain via code using a heightmap, and the program I am using to create my terrain and texture painting does not support exporting heightmaps.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Jul 2015 12:15
Quote: "My question is if it is possible to apply some form of normal mapping shader to this model with so many textures applied? "


Possibly. It depends how the six textures have been applied. If the terrain has been constructed as separate limbs (= segments?) with a different texture for each limb then the answer is yes. If the textures have been applied using multiple materials on single limbs then things are more difficult in DBPro because we are unable to access the different materials natively in DBPro. I'm assuming you will want different normal maps for each of the six textures.

Are you able to export the object in text .X file format? If so, then I could have a quick look at it for you.



Powered by Free Banners
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 10th Jul 2015 17:11 Edited at: 10th Jul 2015 17:19
Hmmm...It seems I am stuck there as well. The program only exports binary .x files, so yet another snag. Sigh.

Terrains are textured by creating various layers and then painting that layer's texture where you need it. I don't know if that helps in any way...

But thank you for the reply and the offer for help, Green Gandalf.

I'll run a checklist for model limbs and see what it comes up with...
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jul 2015 02:32
Quote: "The program only exports binary .x files"


Any X file is better than none - I might be able to convert it to the text format (it used to be possible but several DirectX SDK utilities for such things don't seem to work correctly on Windows 7. With luck I won't need the text format - it just makes things easier because you can actually read the code and see what's going on.

Quote: "Terrains are textured by creating various layers and then painting that layer's texture where you need it. I don't know if that helps in any way..."


It does - and it doesn't. It sounds as if your model uses multiple materials which display correctly in DBPro. However, such models cause problems when you need several texture stages.

I can still try the model and see what I can come up with.



Powered by Free Banners
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 12th Jul 2015 13:30
Thank you again, Green Gandalf, for wanting to help. I have, however, decided to give up on using terrains created with this program, as from what I have seen after running the checklist for object limbs, all of the texture layers share the same name, simply "Material_layer", duplicated five more times for each layer in each sector of the terrain. Also, the program (an alpha build of a program no longer being developed) is prone to crashes at inopportune moments.

So, I have decided to use something else. My question now is, what would be a good alternative of creating very large, diverse terrains that support shaders?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jul 2015 15:17 Edited at: 12th Jul 2015 15:18
You could look at Blitz Terrain (= BT).

However, I usually use my own terrains built using a grid of high poly plains. If you have Matrix1 utilities installed (I highly recommend them) you can use its version of the make object plain command. I find that simpler - and more predictable - than using Advanced Terrain objects. You then need to change the vertices in some way to get the overall terrain. I usually use a heightmap.

However, my solution requires more coding on your part whereas applications like BT do all the hard work for you. I'm a masochist though and prefer the extra control provided by doing it all myself.

BT supports shaders though I haven't tried them myself with BT.

If you're interested in the DIY solution I can probably dig out a simple demo to get you started. Here are two sample screenshots from a demo of mine:





Powered by Free Banners

Attachments

Login to view attachments
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 12th Jul 2015 15:33 Edited at: 12th Jul 2015 15:39
Those look amazing!
I would be very interested in seeing the DIY method you describe. I really don't mind the extra coding lol.

Matrix1Utils was one of the first plugins I downloaded for DBPro, and that particular collection has helped me in so many ways.

I also have the free version of Blitz Terrain, and have played around with it a bit, but I would need the full version of it for the scope of levels I am creating, and I just do not have the funds to buy any new software at this point in time.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jul 2015 16:23
Quote: "I would be very interested in seeing the DIY method you describe."


OK. I'll see what I can dig out.



Powered by Free Banners
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 12th Jul 2015 16:32
Thank you very much.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jul 2015 17:00
Just to keep you going, here's a simple "no shader" demo using a previously constructed terrain stored as a DBO object. It uses four blending stages with stage 0 giving the overall colour and the other three stages giving extra detail up close to the terrain. You can experiment using different detail textures for the three detail blending stages.

I think this model was constructed from textures used in the original Advanced Terrain demo - the dbo object was constructed using the method I described earlier.

Still on the hunt for a simple demo of that method.



Powered by Free Banners

Attachments

Login to view attachments
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 12th Jul 2015 18:00
Thanks for that, Green Gandalf. I am enjoying playing around with various detail textures for the time being.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jul 2015 19:21
Quote: "Thanks for that, Green Gandalf."


You're welcome.

Here's a simple demo of what I was talking about. There are two DBPro projects:

1. "limbed terrain v2.dbpro"

This creates a terrain object using the heightmap name hard-coded into the file (memo to self: make a simple UI for this ). If you run it as is it uses the sample heightmap "broken land v004.png" and creates a DBO object saved as "broken land v004.dbo". This program displays the terrain object with a single texture and different lighting effects.

2. "limbed terrain v2 test.dbpro"

This loads a previously created dbo object and displays it using different shader and textures. Again the filename is hard-coded (sorry!) and set to "broken land v004" as in 1.

Be warned: the first program can take some time to calculate the ambient occlusion. And, of course, you must run 1. at least once before running 2.

Any questions, just ask. (There are bound to be some as this was code written for myself and last visited a few years ago .)



Powered by Free Banners

Attachments

Login to view attachments
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 12th Jul 2015 20:01
Once again, thank you so much for this. You have been extremely helpful. I have tried out the code and I love the results. The hard-coded filenames are not an issue, since they are really easy to change.

I can definitely see myself using this technique for my project!

Many thanks!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jul 2015 21:39
Hope you post screenshots of some of your results.



Powered by Free Banners
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 13th Jul 2015 10:08
Two screenshots of some of my results with your method, Green Gandalf.



Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 13th Jul 2015 11:30
One thing I've been thinking of trying is to use combined textures... having the texutres repeated on a 2x2 grid then wrapping the UV coordinates. Like, the texture for each layer would consist of the diffuse texture, specular, emissive, and normal map - each one repeated on a 2x2 grid. Then I would wrap the UV coordinate so that it's within a 0.0-0.5 range on X and Y, effectively using only the top left section of the texture. Then the normal map might be at the top right, specular could be at the bottom left, and emissive (maybe) at the bottom right. So 4 textures contained in 1 image, each one repeated so that the UV coordinates can wrap around and most likely created from standard images within DBPro. The UV coordinates can be customised to work this way on a mesh level within DBPro, so sampling the normal map for instance would be a case of using the same texture but adding 0.5 to the X component of the UV coord. Probably best to sample the normals along with the diffuse. With the extra textures, allowing for 2 RGB map images, that would give 6 textures with normal and specular plus an extra texture, would make for a fairly pretty terrain I think without needing duplicate terrain meshes with alpha blending.

My main concern is that all the logic might make the shader a bit slow, anyway if it works, I'll be sure to upload a demo.

Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 13th Jul 2015 14:51
Van B, that sounds like a very interesting approach indeed.
If your experimentation with this bears fruit, I would love to see the results.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 13th Jul 2015 21:25 Edited at: 14th Jul 2015 00:04
Hopefully it'll work out, shaders are often a group effort here, so I'm sure someone like GG will be able to help if I get stuck

Been thinking, as I'll use a diffuse, normal, and specular texture, instead of emissive, maybe a relief heightmap texture could be jammed in. Now that would make for some truly jaw dropping terrains, like blending normals and relief heights... that's like Cryengine terrains but with smoother texture blending (Cryengine use vertex blending, bleh!). If I can get something like the relief mapped pebbles in The Forrest, then I'll be over the moon.

EDIT:
Turns out I don't need a 2x2 grid of each texture, instead the texture is scaled to 480x480, then a seamless border is added. The shader uses the world position so there's no issue with UV mapping (thankfully). Anyway I have the terrain using just 1 quarter of the image, so it should be possible to sample the other sections for normal mapping etc... happy days

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2015 12:28 Edited at: 15th Jul 2015 14:11
The problem you'll probably encounter at some point is that you'll get strange seams appearing when the textures try to repeat - unless you've already taken steps to avoid this of course.

The issue was discussed at some length by myself and AtomR (?) on the Learning to write shaders sticky. I'm not sure how the discussion ended but I think we found both the cause and solution. The problem involved mipmapping and the fact that the built-in hardware choice of mipmap went haywire as you crossed a texture boundary.

I'll see if I can locate a relevant post in that discussion and post back.

Edit Found the discussion but it's hard to point you at a specific post. It was a LONG discussion around March/April 2009 .

Anyway I've done some digging in my files and found the attached demo which I believe is AtomR's successful conclusion of the discussion. I haven't delved too far into the code (supposed to be doing something else today ) but I believe the main points are:

1. use the tex2Dgrad() texture lookup in the shader so you have total control over mipmapping;

2. use an atlas where the component tiles are enlarged slightly to include part of the wrapped texture along each edge, i.e. an original tile might be 64x64 pixels but is padded out with wrapped bits to say 80x80 pixels. This avoids (or at least reduces) seams caused by filtering artefacts from adjacent tiles.

Hope this helps.



Powered by Free Banners

Attachments

Login to view attachments
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Jul 2015 14:02
I did have a weird black line, just didn't make sense - then I adjusted the UV coordinates to get rid - using an fmod command like FMOD(In.UV,0.9995) to wrap the UV coordinates to 0.0-1.0 range, before dividing that for the texture atlas. It's weird, should be impossible for a seam to show up, as the texture has a 16pt border all around and it repeats just fine.
Anyway I don't understand why I had to do that, but it seems to work, and I can't spot any issues caused by it now - it will bite me in the butt at some point, but the shader has lots of work left to be added, so I'll re-visit it again once that's done.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2015 14:20
Our posts crossed.

Quote: "I did have a weird black line"


There you go.

Quote: "then I adjusted the UV coordinates to get rid - using an fmod command like FMOD(In.UV,0.9995) to wrap the UV coordinates to 0.0-1.0 range, before dividing that for the texture atlas"


Not quite sure why that works. Food for thought as it seems to be a simple solution. Perhaps you're fooling the hardware mipmapping by avoiding the sudden switch from 1 to 0?

Quote: "it will bite me in the butt at some point,"


I'm sure it will - but no screenshots please.



Powered by Free Banners
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Jul 2015 14:44
Cheers GG, that'll help when the issue does come back
One thing I did change was that I set the shader texturing modes to clamp, as they no longer need to wrap - not sure if that would help prevent the edge line... maybe the edge line is still there but I just haven't found it - it's a big terrain, so maybe the edge lines are just moved much further out.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2015 14:58
Quote: "One thing I did change was that I set the shader texturing modes to clamp"


That should only be relevant when you're reading the edges of the source image so it would only help when you read the outer edges of your extra borders - if I've understood you correctly.

Quote: "it's a big terrain, so maybe the edge lines are just moved much further out."


The seam effect wasn't always very noticeable - it tends to show only when there's a big change in colour between mipmap levels (because the relevant tile has a lot of variation?).

Quote: "that'll help when the issue does come back"


Yes, no need to fix it if the issue doesn't arise in your application.



Powered by Free Banners
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2015 15:06
@Kafoolwho

Quote: "Two screenshots of some of my results with your method, Green Gandalf."


Great screen shots. Thanks for posting.



Powered by Free Banners
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 15th Jul 2015 19:45
Thank you, GG.
And best of luck with your ideas, Van B.

Now I just need to figure one tiny little detail out for my terrain.
In my original terrains I had texture painted some paths onto my terrains, which connected certain key areas of the map visually. Do you think it would be possible to do some form of texture overlay using a mask or something?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2015 20:21 Edited at: 15th Jul 2015 20:41
Quote: "Do you think it would be possible to do some form of texture overlay using a mask or something?"


Yes it would.

As you suggest, you just add some minor changes to the shader and apply two new textures or new sectors in a texture atlas if you want to go down the route discussed in the last few posts. There are many variations of the basic idea and I posted a demo with roads several years ago. You might be able to find it using a search - it might have been on a thread by VanB. I'll have a quick look myself as well.

Edit Found one version. Attached. I'm sure it can be improved by using a better terrain object - but the basic method of using a road mask is shown there. Screenshot, warts and all, in next post.



Powered by Free Banners

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2015 20:46 Edited at: 15th Jul 2015 20:48
Screenshot for previous post.



Edit: I never expected these old demos to see the light of day again.



Powered by Free Banners

Attachments

Login to view attachments
Kafoolwho
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 15th Jul 2015 22:57
Once again, thanks.
Hehehe. I actually sort of came to the same conclusion playing around with it myself.
Your examples have been a great help to me, and I think I am all set to continue with that aspect of my project.
cheers!

Login to post a reply

Server time is: 2024-04-23 17:51:42
Your offset time is: 2024-04-23 17:51:42