Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (howardR, AndrewAMD, EternallyCurious, Petra, 1 invisible), 791 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 5 of 11 1 2 3 4 5 6 7 10 11
Re: Dumb terrain question.. Cannot get it to move... [Re: EvilSOB] #386331
11/01/11 18:52
11/01/11 18:52
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
thankyou very much for the idea of vertex normals, i probably would not have thought that on my own and kept trying different flags and mabe even some shaders and stuff before giving up!

Here is a video of the new look thanks to modifying normals:
http://www.youtube.com/watch?v=6RvUfXQ8_ZA

an example code for how I implemented one of the edges (works for terrains with 33x33 vertexs)
Code:
void avg_normals_N(int x, int y)//NORTH EDGE SMOOTH NORMALS (SHADOWS)
{
	int tx; //vector counter
	VECTOR nml[2];
	VECTOR mid_nml; //average height of touching vertex's
	CONTACT* c1; //contact vertex for Terrain
	
	
	if(y<TERRAIN_COUNT-1)
	{
		for(tx=1;tx<32;tx++)
		{
			vec_set(mid_nml,nullvector);
			vec_for_normal(nml[0],Terrain[x][y],1+tx);
			vec_for_normal(nml[1],Terrain[x][y+1],1057+tx);
			vec_add(mid_nml,nml[0]);
			vec_add(mid_nml,nml[1]);
			vec_normalize(mid_nml,1);
			
			c1 = ent_getvertex(Terrain[x][y],NULL,1+tx);
			//vec_set(c1.v.nx,mid_nml);
			c1.v.nx=mid_nml.x;
			c1.v.ny=mid_nml.z;
			c1.v.nz=mid_nml.y;
			ent_setvertex(Terrain[x][y],c1,1+tx);
			
			c1 = ent_getvertex(Terrain[x][y+1],NULL,1057+tx);
			//vec_set(c1.v.nx,mid_nml);
			c1.v.nx=mid_nml.x;
			c1.v.ny=mid_nml.z;
			c1.v.nz=mid_nml.y;
			ent_setvertex(Terrain[x][y+1],c1,1057+tx);
		}
	}
}



notice how I commented this line:
//vec_set(c1.v.nx,mid_nml);
I forgot ent_setvetex uses dx coordinate system so z and y are swapped. I was getting really odd results till I realized and simply setting the parameters manually changing the axsis solved everything:
c1.v.nx=mid_nml.x;
c1.v.ny=mid_nml.z;
c1.v.nz=mid_nml.y;

The corners get more complicated though, here is an example of one of my corner functions:
Click to reveal..
void avg_normals_SE(int x, int y)
{
int tv; //vector counter
VECTOR nml[4];
VECTOR mid_nml; //average height of touching vertex's
int nml_count;
CONTACT* c1; //contact vertex for Terrain


vec_for_normal(nml[0],Terrain[x][y],1089);
nml_count=1;
if(x<TERRAIN_COUNT-1)
{
vec_for_normal(nml[1],Terrain[x+1][y],1057);
nml_count++;
}
if(y>0)
{
vec_for_normal(nml[2],Terrain[x][y-1],33);
nml_count++;
}
if(x<TERRAIN_COUNT-1 && y>0)
{
vec_for_normal(nml[3],Terrain[x+1][y-1],1);
nml_count++;
}

if(nml_count>1)
{
vec_set(mid_nml,nullvector);
for(tv=0;tv<nml_count;tv++)
{
vec_add(mid_nml,nml[tv]);
}
vec_normalize(mid_nml,1);

c1 = ent_getvertex(Terrain[x][y],NULL,1089);
//vec_set(c1.v.nx,mid_nml);
c1.v.nx=mid_nml.x;
c1.v.ny=mid_nml.z;
c1.v.nz=mid_nml.y;
ent_setvertex(Terrain[x][y],c1,1089);

if(x<TERRAIN_COUNT-1)
{
c1 = ent_getvertex(Terrain[x+1][y],NULL,1057);
//vec_set(c1.v.nx,mid_nml);
c1.v.nx=mid_nml.x;
c1.v.ny=mid_nml.z;
c1.v.nz=mid_nml.y;
ent_setvertex(Terrain[x+1][y],c1,1057);
}
if(y>0)
{
c1 = ent_getvertex(Terrain[x][y-1],NULL,33);
//vec_set(c1.v.nx,mid_nml);
c1.v.nx=mid_nml.x;
c1.v.ny=mid_nml.z;
c1.v.nz=mid_nml.y;
ent_setvertex(Terrain[x][y-1],c1,33);
}
if(x<TERRAIN_COUNT-1 && y>0)
{
c1 = ent_getvertex(Terrain[x+1][y-1],NULL,1);
//vec_set(c1.v.nx,mid_nml);
c1.v.nx=mid_nml.x;
c1.v.ny=mid_nml.z;
c1.v.nz=mid_nml.y;
ent_setvertex(Terrain[x+1][y-1],c1,1);
}
}
}


Hope this helps and saves you headache and time for when you get to that part in your version.
You are not alone either grin

And thanks again for pointing me in the right direction!

Your LOD idea is pretty good though im not sure I will implement something like that. I am going for a cartoony/goofy look to my game. Mainly for 2 reasons, its more friendly for an indie's time budget, and because with simpler models I can load tons more. My trees will probably be a deformed low poly cylinder for the stump, and either a deformed low poly cone or sphere for the leaves. My trees will probably have less polygons than a low LOD tree normally has in one branch.


Uploaded with ImageShack.us
(and I'm considering lowering the poly count even more, LOL!)


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Dumb terrain question.. Cannot get it to move... [Re: Carlos3DGS] #386374
11/02/11 06:53
11/02/11 06:53
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Ive set this thread to watched, and I HOPE I will remember to come back here
when I reach this point. This code WILL be useful. Thank you.

And Im glad to have helped you out... The video looks MUCH better now.

And you think your code is tricky at corners? I cant wait tongue to get to
trying to stich together entities of differing LOD levels...
One has half the vertices of the other...

And I need my LOD's because my view-range is like 25,000 to 50,000 quants,
depending on users available horsepower.
And Im aiming at NEAR-photo-realistic graphics. (terrain anyway)


I look forward to seeing your progression. So if you need help, or just
want to "show off" your progression, feel free to PM me.

Best of luck, and keep up the good work. grin


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Dumb terrain question.. Cannot get it to move... [Re: EvilSOB] #386385
11/02/11 10:59
11/02/11 10:59
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
I see your problem there, but cannot think of a solution even for the first sewing/splicing step.


Code:
high detail terrain viewed from side:
.    .    .
 .  . .  .
  ..   ..

low detail terrain viewed from side:
.    .    .

both terrains spliced/sewn:
.____.____.
 .  . .  .
  ..   ..
(lines represent low vertex count terrain result)




How are you going to achieve that if they have a different amount of vertex?


EDIT: I just came up with an idea that might help. Since we are not working with terrains but with models that look like them... You have an advantage over terrains, you don't need to make all the rows the same.

Code:
Low detail terrain:
.  .  .  .  .  .

.  .  .  .  .  .

.  .  .  .  .  .

.  .  .  .  .  .

Mid terrain (used for between HighLOD and LowLOD for splicing):
.  .  .  .  .  .

. . . .  . . . .

. . . .  . . . .
................
................

High detail terrain:
................
................
................
................
................
................
................
................



the vetex calculations for the middle terrain will be a pain, but it should be achievable this way.
The array (or whatever) holding the height data should be the same as any high detail terrain for all of them. on the high detail one loading is strightforward, on the low detail just skip x vertexses in the height data for each row, and also skip x rows in between. The tough part will be the middle terrain that is used to connect one LOD step to the other. The values to take and skip from the height array will probably have to be hardcoded (at least per row)

to make the coding simpler each LOD sep must be a multiple of the prevois one. and in the middle terrain each row must be a multiple of the previous rows... and you will special versions of these "middle terrains" for the corner terrains.
And if you plan on having several LOD steps, than that is just going to be h3ll to program and get working, but it should be possible (painfull, but possible)

Last edited by Carlos3DGS; 11/02/11 11:28.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Dumb terrain question.. Cannot get it to move... [Re: Carlos3DGS] #386387
11/02/11 11:26
11/02/11 11:26
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I think Im just going to 'average' them, by sewing the points I have,
and ignoring the points I dont.

The LODS vertices-per-side is like so...
LOD_0=256(+1), LOD_1=128(+1), LOD_2=64(+1), LOD_3=32(+1)
So EVERY lod vertices line up with the higher lod vertices...
Like so.
Code:
LOD_0 =    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
LOD_1 =    *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
LOD_2 =    *       *       *       *       *       *       *       *       *
LOD_3 =    *               *               *               *               *



Also, the 'border' between lod_0 and lod_1 is 4,000 quants MINIMUM away from the camera,
so I think its unlikely to be noticable to the player.

If it ends up that is IS noticable, I'll think of some way of hiding it.
For example, when stitching low-poly to higher-poly, the low-poly's vertices
get their z-height "halved" so ALL its edge is below the 'horizon' created by the
high-poly terrain.
Like so...
Code:
Side View...

       /            _    /--\___     ____   _____     /---
camera*        ____/ \__/       \___/      /     \___/    \_____  
       \                                  /                 
               +------ high poly -------+ +------ low poly ----+
                                          ^^ left-most vertex dragged downward




[EDIT]Hehe, you came up with a new idea, WHILE I was typing up how Im ALREADY doing it...


Last edited by EvilSOB; 11/02/11 11:28.

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Dumb terrain question.. Cannot get it to move... [Re: EvilSOB] #386388
11/02/11 11:35
11/02/11 11:35
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
when I started with terrains (before i learned to splice them) i saw that no matter how far away a blue(or whatever sky texture you use) line (or even a tiny dot) in the middle of terrains is very noticable.

I think your idea of the border vertex z value halved to hide the seams is the best option. even if they are not sewn together it will look like it, and will be much less painfull than using those "mid terrains" i talked about to sew them perfectly. I would go with that, because your concept is much simpler to program and probably achieves a good result also


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Dumb terrain question.. Cannot get it to move... [Re: Carlos3DGS] #386391
11/02/11 11:45
11/02/11 11:45
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I'll see when I get there, thats my usual workflow...

One question though... how do you re-calculate the normals for the terrain/entity
once youve finished setting all the vertex heights?

You posted code of how you do the 'edges', but what about the main-body of the entity?

Im not working on this ATM, but small trials in the past using ent_fixnormals just
kept resetting all the new heights back to zero. (ie before re-heighting)
Was I using ent_fixnormal badly? Did I need a wait between the re-heighting and the fixnormal?

I know its do-able, cause Ive done it in the past, and I spent very little time on this test,
as the test was primarily to test setting heights in a second 'thread', which was a fail.

I cant show code, cause its gone... Deleted in order to streamline workflow, and
avoid re-hashing dead-end tests.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Dumb terrain question.. Cannot get it to move... [Re: Carlos3DGS] #386394
11/02/11 12:25
11/02/11 12:25
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
now I am running into another problem... Painting the terrains.

Since they are randomly generated during runtime there are no masks etc textures created beforehand for any shader to work with.

and i am thinking that if i have to create the masks at runtime and then pass them to the shaders... i would rather direclty generate the final bmaps myself and save a step!

the problem is I dont know how. I already have my separate textures i want to use (and they are the same size as each terrain).

My idea is this:

create at runtime empty bmap for each terrain, assign each one as skin to each terrain, and then for each bmap do the folowwing:

1. fill its full texture to the base texture (grass for example).
2. going through the bitmap comparing to the respective height data, set any part lower than (for example 16) to sand. (for beach, river lines, and uderwater terrain).
3. set any part of the bmap covering a part of the terrain with a height > 50 to my rocky texture.
4. set any part of the bmap covering terrain height > 100 to my snowy texture.
5 go through the whole terrain again and replace any part with a slope angle > 60º with my cliff texture.

The bmaps i want to use for my terrains are 512x512, my terrains are 33x33 vertixes with a spacing of 16q between each vertex (which also gives 512x512 size). That was planned beforehand to have the size of the terrains = the size of their texture and not nned any tiling of textures or anything.

My problem is the height data... I dont have 512x512 height data, i only have 33x33 height data. How do I know what to paint on the spaces in between my height data? and how do I detect what parts have an angle > 60º?

The first solution that came to my mind was using c_trace to detect heights of each pixel and also calculate angles with those c_trace... but it seems crazy... it will mean 252144 c_trace instructions per terrain just to get the data to draw the texture.

I thought of averaging out the diference between each point based on distance from any vertex, but i realized that the calculations would be wrong in most cases. as illustrated below the program would assume from A to B everything was the same height. i also thought of calculating the mid point but that does not work either. Any ideas would be greatly apreciated, I have hit a brick wall and cannot see around it!



"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Dumb terrain question.. Cannot get it to move... [Re: Carlos3DGS] #386395
11/02/11 12:35
11/02/11 12:35
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
have a look at vec_lerp for its height and vec_dot for its angle

Re: Dumb terrain question.. Cannot get it to move... [Re: EvilSOB] #386397
11/02/11 12:39
11/02/11 12:39
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
Quote:
One question though... how do you re-calculate the normals for the terrain/entity
once youve finished setting all the vertex heights?
You posted code of how you do the 'edges', but what about the main-body of the entity?

Mabe when you fix the normals you forget the frame? Or are using the wrong frame? (use .frame to be sure you are editing normals for the frame the entity is at at this moment)

first I use my algorithm to load random height for each height-data array

for(x=0;x<32;x++)
{
for(y=0;y<32;y++)
{
diamond_square_fractals(x*32,y*32,random(200)+25);
}
}

then i load the hieght data to each terrain vertex:
for(x=0;x<32;x++)
{
for(y=0;y<32;y++)
{
load_to_terrain(Terrain[x][y],x*32,y*32);
}
}

after that is done I just set the normals with ent_fixnormals:
for(x=0;x<32;x++)
{
for(y=0;y<32;y++)
{
c_updatehull(Terrain[x][y],Terrain[x][y].frame);
ent_fixnormals(Terrain[x][y],Terrain[x][y].frame);//BODY NORMALS
}
}

(NOTE: code up to here is how i got the ugly shadows on the edges)

Then all I have to do is fix the corners and edges with my functions:
for(x=0;x<32;x++)
{
for(y=0;y<32;y++)
{
avg_normals_NE(x,y);//CORNER NORMALS
avg_normals_NW(x,y);//CORNER NORMALS
avg_normals_SE(x,y);//CORNER NORMALS
avg_normals_SW(x,y);//CORNER NORMALS
avg_normals_N(x,y);//SIDE NORMALS
avg_normals_E(x,y);//SIDE NORMALS
avg_normals_S(x,y);//SIDE NORMALS
avg_normals_W(x,y);(x,y);//SIDE NORMALS

}
}
NOTE: notice I dont have any wait calls in between my loops for function calls (and I dont have any wait() inside those functions either).

EDIT: after posting and seeing the result I have to say... WOW what a colorfull post!

Last edited by Carlos3DGS; 11/02/11 13:03.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Dumb terrain question.. Cannot get it to move... [Re: Carlos3DGS] #386402
11/02/11 13:03
11/02/11 13:03
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Carlos: OK no waits or anything I get, and thanks for the code of your flow...
I think my problem boils down to the frame.

Which frame? Its an un-animated entity pretending to be a terrain.. so where
the hell does a frame number come from? Do you assign it one at some point or what?
I am really in-experienced with animations, so I always thought that ".frame"
was ONLY for animated entities... Obviously thats incorrect...

As for your current problem, I think MrGuest has got it for the heights, but I
have no idea how to get the normals using vec_dot... Im noob with normals...


I am watching with baited breath for more details from MrGuest about how to best
implement the vec_lerp because later I'll need to to similar.
My 256X256 terrains need building from 128x128 height-data...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 5 of 11 1 2 3 4 5 6 7 10 11

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1