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 / Evolveds Terrrain Shader

Author
Message
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 15th Oct 2009 20:08 Edited at: 15th Oct 2009 20:09
Hello,

I've recently been looking into the terrain shader that comes with evolveds advanced lighting commands and shaders.

It runs fine and looks even better

but i'm strugling to work out how to make my own terrains

basically what i've worked out is it uses 4 images to make the terrain (see below)...

and diffuse and normal textures to texture the terrain at different stages...

but I dont understand what the 4 images used to make the terrain are made, so I can make my own terrains.

The 4 images are as follows :









I know that :
the 3rd is the Heightmap,
the last is the normal map,
and i think the 2nd is the detail map.

but I have no idea what the first one is, and how to make one

any help is welcomed

yours
N3wton

Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 15th Oct 2009 20:12
Have you made the terrain model? and it does not work just putting all the maps in the same folder as you load the terrain model from??

The byte chrunchers are coming...
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 15th Oct 2009 20:16 Edited at: 15th Oct 2009 20:17
It runs fine using them images, but I want to use my own terrains,

So I have my terrains textures, and Heightmap...

I can make a normal map, but I dont know how to make the first image...

Terrain Demo Using Defaut Images

Yours
N3wton

Attachments

Login to view attachments
Serial Velocity
15
Years of Service
User Offline
Joined: 24th Aug 2008
Location:
Posted: 15th Oct 2009 20:22 Edited at: 15th Oct 2009 20:22
I think that RGB texture is like a texture mask kind of thing. For example, the Red part of that texture is where the Rock texture goes, and the Blue part of that texture is where the Grass texture goes, and so on.

N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 15th Oct 2009 20:26
That makes sense actually good thinking... Now I have to work out how to make one

any ideas?

Yours N3wton

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Oct 2009 20:34
You can do it in an art package, I'd probably use 3 layers and have them additive, or whatever works - so that the 3 layers can overlap without wiping eachother out.

If you plan to use it in a project then I'd suggest making a terrain painter, would make life easier in the long run, although have you tried Evolveds terrain editor? - not sure if that's released but it's probably what he used.


Health, Ammo, and bacon and eggs!
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 15th Oct 2009 20:40
Yer, i was going to use it in my map maker, thus it would need to generate one from a height map... hmmm... I'll start messing around...

If i just make dark colors be red,
middle colors blue,
and high colors green,

That should work...

Also he's scrapped his landscape some bug with DBpro means he cant do it

Yours
N3wton

N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 15th Oct 2009 21:09
Ok, That didnt take to long

can people please let me know if this is the right sort of thing

also if you could let me know how long it took

Heres the function



Attached is the exe with a heightmap

Yours
N3wton

Attachments

Login to view attachments
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 15th Oct 2009 23:51 Edited at: 15th Oct 2009 23:52
ok, I've got normal map making, texture map making, and hightmap to .dbo making...

if i use evolveds hightmap and terrain.dbo, but my genorated normal map and texture map it works...

but if i use mine it doesnt work unless my terrain is the exact same size as evolveds terrain... around 3000, 500, 3000 in size...

so I went looking throught the code... nothing

but in the shader theres a TerrainVec tweakable... so can a shader expert ... (GG ) try explain the shader abit to me, cos I really dont get it

The Shader


Yours
N3wton

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Oct 2009 00:17
I think the clue is in the following sections of EVOLVED's code:



and



UV is just the U and V texture coordinates for the main untiled textures of the terrain - i.e. the ones that align with the heightmap. Since they are untiled the values must range from 0 to 1 with the four corners of the terrain having UV values (0, 0), (0, 1), (1, 0) and (1, 1). The other four UV values are just tiled versions for the 4 detail maps. The tiling of those four isn't critical. The important one is the variable UV itself. Since EVOLVED's shader doesn't assume the terrain has UV coords it has to create them - and this is done using the the world XZ values of the terrain suitably scaled to the range 0 to 1. That's what TerrainVec is doing in the line:



So you just need to work out what the right values are for the four corners of your terrain to get the four pairs of UV values mentioned above.
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 16th Oct 2009 00:38
Sounds Silly I prefer your shader GG but evolveds works better with his shadows, so I guess i'll have to learn

Thanks allot GG

N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 16th Oct 2009 14:58 Edited at: 16th Oct 2009 16:14
Right... I've palyed with the shader, but I still have no idea how to do it lol...

If i understand you GG, I have to some how get the forur corners of the terrain and put the coords in...

float2 Terrain1UV={32,32};
float2 Terrain2UV={32,32};
float2 Terrain3UV={16,16};
float2 Terrain4UV={64,64};

but the coords are in 3 dimensions not 2?

I'm really comfused

EDIT

right i've put together a small project so people can see why im getting comfused lol...

its attached, it also asks you some questions, but if you leave the values at default then we all get the same terrain


Yours
N3wton

Attachments

Login to view attachments
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 16th Oct 2009 16:49
Umm, I could be wrong(I can`t remember and having difficulty downloading via my wireless connection so cannot test) but I think each of the float2 values relate to tiling in the x and z direction of your terrain for each texture. The float3 values break up so the first 2(-1600,-1600) act as the world x and z coords for the bottom left corner of your terrain, followed by the world size of the terrain(3200) so the shader can auto generate the top right uv coords from the size of the terrain. You may have to play a little with the values as I forget if the world values are based around 0,0,0 or the objects position. On the other hand I culd be wrong..
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Oct 2009 16:58
Those will be repeat values, like texture 1 will be repeated 32x32 times over the terrain. That's how all these terrain shaders work, it's like there's a standard almost for blending textures on terrain, the main difference in them is what else they can do, like normal maps, automation, more textures, fog etc etc. It's worth trying them all out and finding the best solution for what you need to do. I mean, I love Evolved's work but I'm petrified of using it - I can't imagine any project running nicely on my PC that uses his shaders.

Anyhoo, the shader probably multiplies the UV coordinates by these values, so really the most important thing is how you UV map the terrain. Personally I set the UV's with code when I mould my terrain chunks to suit the heightmap - simply based on the X and Z location divided by the total terrain size to give a 0.0 to 1.0 range. Then the shader will multiply that by 32, so the texture is repeated 32 times. An advanced terrain probably has the appropriate UV map to suit the colour map - really this is a concern for your own terrains, I mean make sure you can UV map them to suit the shader, if not, look at doing it with code.


Health, Ammo, and bacon and eggs!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Oct 2009 17:12
N3wton

Quote: "but the coords are in 3 dimensions not 2?"


I think I answered your question when I said:

Quote: "and this is done using the the world XZ values of the terrain suitably scaled to the range 0 to 1"


(my emphasis).

The Y coordinate of the terrain is not used.

Each vertex's world position has three coordinates: X, Y and Z.

Each vertex's texture coordinate has two coordinates: U and V.

EVOLVED's shader calculates the two texture coordinates U and V from the two world coordinates X and Z. The vector TerrainVec is just a handy place to store the constants needed for the conversion. If your terrain is not square you'll need four constants.

As an example, suppose the left and right hand edges of the terrain have X = 1000 and 3200 respectively. Suppose you also want the left and right hand edges to correspond to the left and right hand edges of your images then you'll need to set

U = (X - 1000)/2200.

That will ensure that the left hand edge has U = 0 and the right hand edge U = 1.
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 16th Oct 2009 21:44
ok, I might understand but how the hell do i work out the coords of the left and right of the terrain?

Yours
N3wton

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Oct 2009 23:25
Well, you made it. If you don't know I'm sure no one else will.

Of course you could do it the hard way (as I did with some of my terrain demos) and search through all vertices to find the extreme X and Z values.
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 16th Oct 2009 23:31
The terrain is made from the heightmap using AT, so i guess i'll have to scan through all the verts

yours
N3wton

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Oct 2009 00:04
In that case you might as well use the code from one of my AT demos on this thread:

Shaders for Advanced Terrain

I'm not sure which ones off-hand.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 17th Oct 2009 06:05
Quote: "but how the hell do i work out the coords of the left and right of the terrain?"

You could use the commands object size X() and object size Z(). When an AT terrain is created, one of the corners is at 0,0 (x,z) and the rest of the object expands into positive world space. Unless you are re-positioning your terrain object (and assuming your terrain is square), then you could just set the TerrainVec to {0,0,object size X(TerrainID)}.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Oct 2009 13:34
That should work. I didn't try it because I don't trust the accuracy of the object size commands. Perhaps it's time for me to have another look.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Oct 2009 15:16
Advanced terrains are the size of the heightmap multiplied by the scale values.

So if your heightmaps are 512x512 and the scale is 1x1x1 then the terrain will be 512(X) by 512(Z).

Your signature has been erased by a mod because we're sadistic losers with nothing better to do. (joke)
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 17th Oct 2009 16:13
Quote: "So if your heightmaps are 512x512 and the scale is 1x1x1 then the terrain will be 512(X) by 512(Z)."

That is only if you count the vertices that get clipped off by AT, but for this sort of thing that would be plenty accurate.
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 18th Oct 2009 14:17 Edited at: 19th Oct 2009 17:44
Ok,

I changed the shader to terrainvec to { 0, 0, 3190 } and it still doesnt look right, tho its very close...

I'll post a screen shot asap, but my stupid vista laptop blue screened and died so i had to wipe it... on windows 7 now so once i get DBPro back on and get my code from my backup i'll put a screen shot out

At this point although were not at a conclusion, I would like to say thankyou to every whom has tried to help, this community is truely the best i know

EDIT:

Sorry for the delay in putting screen shots up...


As you can see from that image parts of the terrain are nearly ok, but...


go round the corner and its miles off

Yours
N3wton

N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 19th Oct 2009 17:56
Times like this i wish i had evolveds phone number

yours
n3wton

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 19th Oct 2009 18:36
Here Newton, try these shaders. They are the ones that I am using in my project, and thus have been changed a bit.

The main difference is that the UV coordinates are taken from the terrain object (instead of calculated from world coordinates). The "Terrain Normals" shader gets it's normals from the object itself instead of a normal map, and allows you to apply a "Normal Variance Map" (which makes the terrain look bumpier than normal). Another difference is that there are only three diffuse/normal textures (evolved's shaders also use the blendmap's alpha channel for a fourth). You will have to look at the shaders to see what stages to apply which textures to, since I am quite sure they aren't the same as evolved's versions.

Attachments

Login to view attachments
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Oct 2009 18:37
There is a different shader, I'm looking at his demo with the terrain, water, reflecting sunlight, trees etc - and there's no reference to terrainvec in the shaders. It appears to take everything it needs from the UV coordinates.

Here is the shader I'm looking at for detail:



And normals version:



The water in the demo I'm looking at looks similar, but with the sun reflecting down, I think it's been improved since then.

Anyhoo, I think that you need to resort to vertex data, to work out the actual size of the terrain and assign UV coords to it yourself. I have code to load a heightmap and make a limbed terrain object from it, works fine with my shader so it should be fine for Evolveds - plus you have to remember that the whole AT terrain gets converted to a mesh, so looses any culling benefit anyway. I'll see if I can take Evolveds shader and apply it to the way I make terrains, it might involve a scaling though as I tend to make my terrain tiles 100x100 units. Anyhoo I'll let you know if I can get it working.


Health, Ammo, and bacon and eggs!
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 21st Oct 2009 18:22
@revenant chaos

I've looked into your mod of it, and now my head really hurts, I really really strugle to understand shaders and chance of a small example of what limbs are textured with what texture?

Thank
N3wton

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 22nd Oct 2009 16:14
Hi Newton, I just realized that you are using Evolved's new "Advanced Lighting" instead of the old version that I am using. I looked over his new version(s), and decided that it would be less work to just modify the new version(s) of the shader to get the UV coodinates and normals from the terrain object itself. I'll hopefully get time to work on that today, but you might have to wait until tomorrow.
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 24th Oct 2009 20:32
Ok thanks revenant chaos, you rock

Yours
N3wton

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 25th Oct 2009 08:37
Ok, I finally got around to this today. I am working with dial-up so I didn't include any media, but you can just unpack this rar into the "Advanced Lighting" directory, and it should work fine. Let me know if you have any problems.

Attachments

Login to view attachments
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 25th Oct 2009 14:28
You Legend

I owe you like a pizza or something



Just onething to say revenant chaos, in one of your comments you say you position it relative to 0, 0, 0. but you dont you position the terrains relative to 0, waterheight#, 0... didn't know if this effected anything?

Thankyou to everyone

Yours
N3wton

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 25th Oct 2009 16:57 Edited at: 25th Oct 2009 16:59
Quote: "Just onething to say revenant chaos, in one of your comments you say you position it relative to 0, 0, 0. but you dont you position the terrains relative to 0, waterheight#, 0... didn't know if this effected anything?"


Nope, you can position your terrains any way you want. The reason the code doesn't say position object terrain,0,0,0 is because (like I said before) when an AT terrain is created, one of the corners is at 0,0 (x,z) and the rest of the object expands into positive world space. The comment should have said: "Position the terrain objects so their centers are at 0,0 (X,Z)". The Y positioning was just so half of the terrain would stick out of the water. The X and Z positioning of the terrain really doesn't effect anything (besides precision with huge coordinates), I only did it out of habit.
N3wton
14
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 25th Oct 2009 17:00
ok thanks again

Yours
N3wton

Login to post a reply

Server time is: 2024-05-07 10:37:27
Your offset time is: 2024-05-07 10:37:27