Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
6 registered members (AndrewAMD, Ayumi, degenerate_762, 7th_zorro, VoroneTZ, HoopyDerFrood), 1,268 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 1 of 2 1 2
Another grass solution #58264
11/01/05 06:38
11/01/05 06:38
Joined: Jun 2003
Posts: 1,017
Germany
T
Thomas_Nitschke Offline OP
Senior Developer
Thomas_Nitschke  Offline OP
Senior Developer
T

Joined: Jun 2003
Posts: 1,017
Germany
Hi at all!
I was recently messing around quite a lot with grass scripts and their performance. Unfortunately, none of the scripts I was able to find on these forums or to create by myself seemed to be fast enough. So I thought 'why not use one big grass model instead of hundreds'?
I must say it turned out to be a complete success regarding speed, although this method is a tiny little bit harder to implement. Here's what I do, anyway.

EDIT: Get the comfortable version (customizable via WED) - click here!

Copy and paste the following into your script:

define highest_vertex,skill1;
define lowest_vertex,skill2;

material mat_vegetation
{
//whatever material definitions go here
effect = "
dword mtlSkill1;
texture mtlSkin1;

technique alphaTestMaterial{
pass p0{
zWriteEnable=true;
AlphaBlendEnable=true;
alphaTestEnable=true;
AlphaFunc=greater;
AlphaRef=<mtlSkill1>;
cullMode=ccw;}}

technique fallback{pass p0{}}";

}

//uses: highest_vertex lowest_vertex
action vegetation_
{
var i;
var maxVerts; //used to store the total number of vertices in the model
var height;
var current[3]; //used to store the current position of a vertex
var new[3]; //used to store the new (i.e. target) position of a vertex
var old[3]; //like current, but contains global instead of local coordinates

my.material = mat_vegetation; //assign a material
my.invisible = 1; //make the whole thingy invisible so one cannot watch the grass deform
my.transparent = 1;
my.flare = 0;
my.passable = 1;

maxVerts = ent_vertices(my) + 1; //this makes sure every vertex in the model is processed
height = my.highest_vertex - my.lowest_vertex; //calculate the height of the model from the coords of the lowest/highest vertex

while(i < maxVerts)
{
//calculate vertex positions (vec_for_vertex is used for global, vec_for_mesh for local coords)
vec_for_vertex(old,my,i);
vec_for_vertex(temp,my,i);
vec_for_mesh(new,my,i);
vec_for_mesh(current,my,i);
//scan 5000 quants down
temp.z -= 5000;

//if this is one of the bottom vertices
if(int(current.z) == my.lowest_vertex){
//lower it to the ground by tracing down
new.z -= c_trace(old,temp,ignore_me+ignore_sprites+ignore_passable);
vec_to_mesh(new,me,i);}
//if this is one of the top vertices
if(int(current.z) == my.highest_vertex){
//lower it to the ground but add the model height
new.z -= c_trace(old,temp,ignore_me+ignore_sprites+ignore_passable) - height;
//finally randomly in-/decrease the z coords of the vertex to make this look more interesting
new.z += (random(40) - 20);
vec_to_mesh(new,me,i);}

//finally, increment i
i += 1;
}
//when done, switch invisibility off
my.invisible = 0;
}

Now assign the "vegetation_" action to your grass model.
Make sure that:
  • The grass model's top is a plane, i.e. no single bushes or things like that should be higher or less high than the others. Basically, the model has to look like this: Click here
  • The grass model is not too big (you've got to mess around with this a bit in order to find out how your graphics card will deal with it) - even with this method, use multiple models (3 will be satisfying for a rather small level I guess).


Now open your grass model in MED, zoom as close as possible and move your mouse over the highest vertex of the model. Keep the mouse there and have a look at MED's status line at the very bottom of the program. The fourth box from the right indicates the mouse's z-position. Put the integer part of what you see there into the action's skill1 (highest_vertex). Do the same for the lowest vertex of the model and skill2 (lowest_vertex).


Hope this helps someone

If anything doesn't work or behave the way it should, please let me know!

Last edited by The Matrix; 11/01/05 20:37.

Formerly known as The Matrix - ICQ 170408644 I've been here for much longer than most people think. So where's my "Expert" status?
Re: Another grass solution [Re: Thomas_Nitschke] #58265
11/01/05 18:04
11/01/05 18:04
Joined: Jun 2003
Posts: 1,017
Germany
T
Thomas_Nitschke Offline OP
Senior Developer
Thomas_Nitschke  Offline OP
Senior Developer
T

Joined: Jun 2003
Posts: 1,017
Germany
So what, 92 views and not a single reply? Some review on how this is working for you would really be nice since I'm still trying to improve it wherever I can!

Maybe I should rename the thread to something more spectacular, say "ULTIMATE GRASS SOLUTION, MORE THAN 100% FASTER THAN EARLIER ONES" or something like that

No seriously, I'd be really glad if you, in case you're giving it a try, were leaving a small comment here. Oh, btw!
100% faster (<<--- extra bold) is a value I honestly measured on my PC!

Last edited by The Matrix; 11/01/05 18:05.

Formerly known as The Matrix - ICQ 170408644 I've been here for much longer than most people think. So where's my "Expert" status?
Re: Another grass solution [Re: Thomas_Nitschke] #58266
11/01/05 18:37
11/01/05 18:37
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
I read through your code. Although your declaration is confusing (old,new,..? find better names) you should add more comments. And it is obvious that you missed to tell the reader HOW a grass model should look like to work with your script!

Your script tooks the model and "projects" it on the surface. Like when you have a soft rubber pad that is layed on a hand: it deforms as the shape of the hand. Like that your script does the job..

But the very reason why your solution is superior (on the one hand) is that you have got a lot of grass (sprites? polys? etc?) inside one model. So it renders fast cause it is only a small amount of entities instead of having lots of grass spikes

But it is also inferior, because even if you have a speed increase, it decreases on wide scaled levels and areas. This is because you have to have different shapes of your grass sprite to fit the flexibility of nature. Nevertheless you have a lot of entities and polys too. So you need nevertheless a more flexible system.

Search for "dynamic tree solution" here and try it with smaller mdls with grass bunches. This works fine!

ciao
christian

Last edited by HeelX; 11/01/05 18:38.
Re: Another grass solution [Re: HeelX] #58267
11/01/05 18:52
11/01/05 18:52
Joined: Jun 2003
Posts: 1,017
Germany
T
Thomas_Nitschke Offline OP
Senior Developer
Thomas_Nitschke  Offline OP
Senior Developer
T

Joined: Jun 2003
Posts: 1,017
Germany
First of all, thanks for replying

Antwort auf:

But it is also inferior, because even if you have a speed increase, it decreases on wide scaled levels and areas. This is because you have to have different shapes of your grass sprite to fit the flexibility of nature. Nevertheless you have a lot of entities and polys too. So you need nevertheless a more flexible system.

Search for "dynamic tree solution" here and try it with smaller mdls with grass bunches. This works fine!




Yep I already saw that and I know it's working well. Anyway, I believe that this method is better as it is limited only by the graphics card (the only impact noticeable in the status panel will be the "ref" value which means -in this case- the time needed by the GPU to perform the alpha test), not by the CPU or any other means.

However, you've got a point when it comes to pretty big levels. In that case, you'd need more models than you would with some that are generated around the player, and only there. I think you would never need so many that it would really hit fps badly, but if you do, I can't help it since this is clearly the code's major disadvantage.

Maybe I'll combine this and have only one model that always follows the player and is deformed in realtime since deforming seems to be really fast...

Last but not least,as for the code itself, I'll try adding some comments. This was intended to be used as a whole so I thought you probably would'nt need this. But if one wanted to tweak something on his own, he'd obviously need comments, so I'm going to add some.


Formerly known as The Matrix - ICQ 170408644 I've been here for much longer than most people think. So where's my "Expert" status?
Re: Another grass solution [Re: Thomas_Nitschke] #58268
11/01/05 21:10
11/01/05 21:10
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline
Expert
XNASorcerer  Offline
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
Can you make a litle demo showing this working?

Re: Another grass solution [Re: XNASorcerer] #58269
11/01/05 22:07
11/01/05 22:07
Joined: Jun 2003
Posts: 1,017
Germany
T
Thomas_Nitschke Offline OP
Senior Developer
Thomas_Nitschke  Offline OP
Senior Developer
T

Joined: Jun 2003
Posts: 1,017
Germany
Yep, of course. I'll see that I have a demo up until, say, end of the week. Sorry for not being able to provide one earlier but I'm pretty busy at the moment...


Formerly known as The Matrix - ICQ 170408644 I've been here for much longer than most people think. So where's my "Expert" status?
Re: Another grass solution [Re: Thomas_Nitschke] #58270
11/02/05 07:37
11/02/05 07:37
Joined: Jun 2003
Posts: 1,017
Germany
T
Thomas_Nitschke Offline OP
Senior Developer
Thomas_Nitschke  Offline OP
Senior Developer
T

Joined: Jun 2003
Posts: 1,017
Germany
Allright, seems I found some time much earlier than I originally expected!

Here it is: Grass Deform Demo (3.2 MB)

Note: Press the space bar to deform and make visible the grass entity!

Last edited by The Matrix; 11/02/05 07:38.

Formerly known as The Matrix - ICQ 170408644 I've been here for much longer than most people think. So where's my "Expert" status?
Re: Another grass solution [Re: Thomas_Nitschke] #58271
11/02/05 18:25
11/02/05 18:25
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Nice environment and the grass is applied very good, I like it. But nevertheless you have to keep somekind of shape in your grass mdl and this is a bit time consuming to create, isnt it? Did you tried it with bushes, trees and so on? I really like it. For test-reasons one could create a mdl for the whole level and after finishing one could seperate the mdl for different parts of the map. Additionally you could write code to optimize switching on and off the grass bunches.

Good job.

Re: Another grass solution [Re: HeelX] #58272
11/03/05 12:41
11/03/05 12:41
Joined: Jun 2003
Posts: 1,017
Germany
T
Thomas_Nitschke Offline OP
Senior Developer
Thomas_Nitschke  Offline OP
Senior Developer
T

Joined: Jun 2003
Posts: 1,017
Germany
Thanks for your kind words
Actually, what you describe is exactly what I'm currently trying to do. And, you're right there, it definitely is a bit more difficult to create the grass MDLs... to have them shaped properly, I usually create a bunch of blocks where I want the grass to be, paste them, delete them, create a new level and insert the blocks, then save the whole thingy and open it in MED to insert grass models along the blocks's shape.

As for your question: No, I didn't try it with bushes and trees yet, but will do in the near future. I don't think this could be used for trees though, as a tree has a far too complex shape - but with bushes this should work quite well.

Last edited by The Matrix; 11/03/05 12:41.

Formerly known as The Matrix - ICQ 170408644 I've been here for much longer than most people think. So where's my "Expert" status?
Re: Another grass solution [Re: Thomas_Nitschke] #58273
11/03/05 15:25
11/03/05 15:25
Joined: Aug 2002
Posts: 673
Las Cruces, NM
JimFox Offline
User
JimFox  Offline
User

Joined: Aug 2002
Posts: 673
Las Cruces, NM
Hi Matrix,
I downloaded the demo and read the code. I must say that it looks promising.
I am a bit confused about one thing. One poster to this thread said that the model automatically conforms itself to the surface. Is that right?
You mentioned the use of blocks to position the model, so that seems to be saying something different.
Anyway, I would appreciate your clarification of that point.
Many thanks for contributing this. I think the idea of many grass plants combined in one model is a brilliant stroke, btw.
Best regards,


Jim
Page 1 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

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