[WIP]Interactive Grass

Post » Sat Jan 15, 2011 3:27 am

If you have eyepos, it should do good for some time, eventually we can get player pos.

What is the progress, can you move any grass yet, in any form?
User avatar
josie treuberg
 
Posts: 3572
Joined: Wed Feb 07, 2007 7:56 am

Post » Fri Jan 14, 2011 11:07 pm

If you have eyepos, it should do good for some time, eventually we can get player pos.

What is the progress, can you move any grass yet?

Not yet. I'm trying to modify all variables available to see dissect more exactly how grass works. I'm not sure I understand the original code borrowed from the people I asked for help fully tho.

I think my biggest problem right now is getting it to react when player get's close, after that I can worry about how the reaction is supposed to look. Right now I can't even seem to change the windspeed of the grass within the If statement, either it never enters the loop or alternatively it doesn't execute the code properly upon the grass itself.

I was hoping I could get the same code with only a modification to wind and reworked into an if block for checking distance to make it appear as if the windspeed is higher once you get close however that too seems to fail, I suspect Eyevec is the culprit.

Finally I have no idea how big units are in shaders, so if i say:
if (proxydist < 30)
{
float3 worldpos = mul(IN.pos, world);
float3 shift = worldpos.xy - EyePos.xy;
shift /= 10;
worldpos += shift;
}

How much is 30 units???


EDIT: After some simple research I can confirm that it is the calculation of distance between grass and eyepos that is never hittin that magic "30" so it never enters the loop.
User avatar
Cool Man Sam
 
Posts: 3392
Joined: Thu May 10, 2007 1:19 pm

Post » Sat Jan 15, 2011 3:50 am

My first attempt for vertex shaders, guess what:
I am moving the grass as I walk over them. :)

Now if I can bend them properly...
User avatar
Shaylee Shaw
 
Posts: 3457
Joined: Wed Feb 21, 2007 8:55 pm

Post » Sat Jan 15, 2011 4:37 am

My first attempt for vertex shaders, guess what:
I am moving the grass as I walk over them. :)

Now if I can bend them properly...

Obviously you now really have to tell me what I'm doing wrong, haha =)

That's awesome man!

If you read through Liztails post that I reposted in the first post, He said something about a linear function, that will be vital for moving them properly.
User avatar
Ebou Suso
 
Posts: 3604
Joined: Thu May 03, 2007 5:28 am

Post » Sat Jan 15, 2011 1:26 pm

Currently it looks like this.
GrassVertOut GrassVS( GrassVertIn IN ) {
...................
float4 worldpos = mul(IN.pos, worldmat);
float gdist = length(worldpos.xyz - EyePos.xyz);
...................

...................
worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;
if ( gdist < 200 ) {
//remove wind - why not? :)
worldpos.xy = worldpos.xy / wind;
worldpos.xy += 20 * height * 10;
}

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

There are couple of iterations, I am adding those to first two iterations for now. I am changing the value 20. I lowered it a lot, I haven't test it yet.

First I want to get the maximum bending state, from there I can add scaling from eyepos.

Well, in which direction does grass bend, x, y, xy?
User avatar
Russell Davies
 
Posts: 3429
Joined: Wed Nov 07, 2007 5:01 am

Post » Sat Jan 15, 2011 12:37 am

Currently it looks like this.

There are couple of iterations, I am adding those to first two iterations for now. I am changing the value 20. I lowered it a lot, I haven't test it yet.

First I want to get the maximum bending state, from there I can add scaling from eyepos.

Well, in which direction does grass bend, x, y, xy?

Naturally speaking grass and flora would first move away and then to the sides and back to neutral position. Will try the code and see if I can figure something out =)

Also, what is worldmat? I don't seem to have that o_O

EDIT:
Haha, it works, altho the version you provide is a bit whacko! I can see that the only thing I really did wrong was using distance instead of length. The rest is math from now on =) Thank you for tackling this man.
User avatar
CYCO JO-NATE
 
Posts: 3431
Joined: Fri Sep 21, 2007 12:41 pm

Post » Sat Jan 15, 2011 11:27 am

lol, my first thought with the title of the thread was "so we're gonna be able to cut grass now?" lawnmowers of morrowind...
User avatar
YO MAma
 
Posts: 3321
Joined: Thu Dec 21, 2006 8:24 am

Post » Fri Jan 14, 2011 11:36 pm

Naturally speaking grass and flora would first move away and then to the sides and back to neutral position. Will try the code and see if I can figure something out =)

Also, what is worldmat? I don't seem to have that o_O

This is Hrnchamd's ingame.fx file, I think. But it is based on phal's, AFAIK.

Edit: It is there, in one of the iterations, I am doing it for the first two iterations. But I think I should do it for all iterations. The code repeats 4-5 times I think.
User avatar
Sebrina Johnstone
 
Posts: 3456
Joined: Sat Jun 24, 2006 12:58 pm

Post » Sat Jan 15, 2011 10:22 am

This is Hrnchamd's ingame.fx file, I think. But it is based on phal's, AFAIK.

Same here I think...

Oh well.

Right now the grass looks like lazers shooting off into the distance hehe.
User avatar
Charles Weber
 
Posts: 3447
Joined: Wed Aug 08, 2007 5:14 pm

Post » Sat Jan 15, 2011 2:06 pm

Oh well.

Right now the grass looks like lazers shooting off into the distance hehe.

Maybe it is the wind removal line. I will disable it. Instead of inserting constant numbers, I will try to create a new postick with 2000 maybe. And try new values. On the other hand it is normal, because vertex shader treats them as vertex points instead of individual grass objects. And that may be a problem. Extending if distance to range might fix it though.
Edit: My first try made them float above me. Hehe.
User avatar
Sarah Knight
 
Posts: 3416
Joined: Mon Jun 19, 2006 5:02 am

Post » Sat Jan 15, 2011 6:03 am

Maybe it is the wind removal line. I will disable it. Instead of inserting constant numbers, I will try to create a new postick with 2000 maybe. And try new values. On the other hand it is normal, because vertex shader treats them as vertex points instead of individual grass objects. And that may be a problem. Extending if distance to range might fix it though.
Edit: My first try made them float above me. Hehe.

I'm experimenting with trying to get a natural movement through the sin/cos calculation. If those calculations can be done on single x an y components, things could start to get interesting =) This is exciting!

Good luck with tweaking and testing my friend!

EDIT: One way to figure out direction to bend away from camera is making if statements and check them against the x and y of Eyevec and have an individual set of movement for each possibility, very tedious.

EDIT2: The two biggest problems atm, how to get the angle to bend from, and how to make it gradual with a linear function so it doesn't just pop into place.
User avatar
Marcin Tomkow
 
Posts: 3399
Joined: Sun Aug 05, 2007 12:31 pm

Post » Sat Jan 15, 2011 6:34 am

I'm experimenting with trying to get a natural movement through the sin/cos calculation. If those calculations can be done on single x an y components, things could start to get interesting =) This is exciting!

Good luck with tweaking and testing my friend!

EDIT: One way to figure out direction to bend away from camera is making if statements and check them against the x and y of Eyevec and have an individual set of movement for each possibility, very tedious.

EDIT2: The two biggest problems atm, how to get the angle to bend from, and how to make it gradual with a linear function so it doesn't just pop into place.

I did the wind removal right this time and manage to bend them. Now they are bending to left with 45 degrees. And for gradual, it should be set in math instead of changing the if function.

First I will try to bend them forward, and add some gradual.

Edit3:

//Animate grass	float height = clamp(IN.pos.z, 0, 100) / 100;		float2 wind = WindVec / 6;	half3 eyevec = normalize(EyePos.xyz - IN.pos.xyz);		float2 pos_ticks1 = worldpos.xy / 1000 + ticks;	float2 pos_ticks2 = worldpos.xy / 750 + ticks * 2;	float2 pos_ticks3 = worldpos.xy / 500 + ticks * 3;	float2 pos_ticks4 = worldpos.xy / 250 + ticks * 4;		float2 bend_ticks1 = worldpos.xy / 100000 + 1;	float2 bend_ticks2 = worldpos.xy / 75000 + 1 * 2;	float2 bend_ticks3 = worldpos.xy / 50000 + 1 * 3;	float2 bend_ticks4 = worldpos.xy / 20000 + 1 * 4;		worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;		if ( gdist < 200 ) {		//remove wind - why not? :)		worldpos.xy -= ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;		worldpos.xy += ( sin(bend_ticks1) + cos(bend_ticks2) + sin(bend_ticks3) + cos(bend_ticks4) ) * height * (1/gdist) * 15000;	}


Eyevec to put somewhere, but where?

I am off to sleep. Most probably this is going to have been completed before I wake up. :)
User avatar
Brentleah Jeffs
 
Posts: 3341
Joined: Tue Feb 13, 2007 12:21 am

Post » Sat Jan 15, 2011 10:59 am

I did the wind removal right this time and manage to bend them. Now they are bending to left with 45 degrees. And for gradual, it should be set in math instead of changing the if function.

First I will try to bend them forward, and add some gradual.

Edit3:

//Animate grass	float height = clamp(IN.pos.z, 0, 100) / 100;		float2 wind = WindVec / 6;	half3 eyevec = normalize(EyePos.xyz - IN.pos.xyz);		float2 pos_ticks1 = worldpos.xy / 1000 + ticks;	float2 pos_ticks2 = worldpos.xy / 750 + ticks * 2;	float2 pos_ticks3 = worldpos.xy / 500 + ticks * 3;	float2 pos_ticks4 = worldpos.xy / 250 + ticks * 4;		float2 bend_ticks1 = worldpos.xy / 100000 + 1;	float2 bend_ticks2 = worldpos.xy / 75000 + 1 * 2;	float2 bend_ticks3 = worldpos.xy / 50000 + 1 * 3;	float2 bend_ticks4 = worldpos.xy / 20000 + 1 * 4;		worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;		if ( gdist < 200 ) {		//remove wind - why not? :)		worldpos.xy -= ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;		worldpos.xy += ( sin(bend_ticks1) + cos(bend_ticks2) + sin(bend_ticks3) + cos(bend_ticks4) ) * height * (1/gdist) * 15000;	}


Eyevec to put somewhere, but where?

I am off to sleep. Most probably this is going to have been completed before I wake up. :)

That's interesting. It did kind of fix the popping issue.

I tried mixing the eyevec into the calculation but it seems to almost always result in crashes. Wondering if it's the half3 normalize part that is doing something weird. Oh daymn it all, I really don't understand squat of this! Well actually I do understand some parts but meh, it's absolutely above my league.
User avatar
Kellymarie Heppell
 
Posts: 3456
Joined: Mon Jul 24, 2006 4:37 am

Post » Sat Jan 15, 2011 6:14 am

That's interesting. It did kind of fix the popping issue.

I tried mixing the eyevec into the calculation but it seems to almost always result in crashes. Wondering if it's the half3 normalize part that is doing something weird. Oh daymn it all, I really don't understand squat of this! Well actually I do understand some parts but meh, it's absolutely above my league.

We are doing good.

1/gdist is doing the gradient but I am not close to maximum bend yet, and I think we can find a way to bend the grass without using eyevec. They should always bend away from the player. Eyepos should be enough for this.

Regarding the code, pos_ticks are predefined bending states which bind to time, they are always bending, wind only changes the intensity.
User avatar
natalie mccormick
 
Posts: 3415
Joined: Fri Aug 18, 2006 8:36 am

Post » Sat Jan 15, 2011 4:19 am

That's interesting. It did kind of fix the popping issue.

I tried mixing the eyevec into the calculation but it seems to almost always result in crashes. Wondering if it's the half3 normalize part that is doing something weird. Oh daymn it all, I really don't understand squat of this! Well actually I do understand some parts but meh, it's absolutely above my league.

You might want to try declaring eyevec normalize as float3 instead. -_-
[edit] on second thought, it's probably more in how you're trying to apply the variable into the worlpos.xy calculation... try calculating it in as eyevec.xy


I've found that the flexing looks more natural if the cos(pos_ticks) are calculated as negative values, i.e:
worldpos.xy += ( sin(pos_ticks1) - cos(pos_ticks2) + sin(pos_ticks3) - cos(pos_ticks4) ) * height * wind * 10;
That will make grass/trees/flora bend more with the wind direction, flex back a bit against the wind, then settle at original position before repeating. With positive cos calcs, the reactive flex back into the wind is greater than the initial bend with the wind.
User avatar
Anthony Rand
 
Posts: 3439
Joined: Wed May 09, 2007 5:02 am

Post » Sat Jan 15, 2011 8:56 am

You might want to try declaring eyevec normalize as float3 instead. -_-
[edit] on second thought, it's probably more in how you're trying to apply the variable into the worlpos.xy calculation... try calculating it in as eyevec.xy


I've found that the flexing looks more natural if the cos(pos_ticks) are calculated as negative values, i.e:
worldpos.xy += ( sin(pos_ticks1) - cos(pos_ticks2) + sin(pos_ticks3) - cos(pos_ticks4) ) * height * wind * 10;
That will make grass/trees/flora bend more with the wind direction, flex back a bit against the wind, then settle at original position before repeating. With positive cos calcs, the reactive flex back into the wind is greater than the initial bend with the wind.

Will definitely try some of this stuff and play with it.
Thanks.

Lol this is really a huge joint effort if you look at it.

Liztail, Peachykeen is the base of code I have worked with, Vtastek found out one of the biggest issue, that I was using "distance" instead of "length". And here and now people can freely chime in with whatever developments they come up with =)

Awesome!
User avatar
The Time Car
 
Posts: 3435
Joined: Sat Oct 27, 2007 7:13 pm

Post » Sat Jan 15, 2011 3:18 pm

any progress on this, also is there anything you can show us pic or video wise couse some of us dont understand the scripting language and have no idea what your talking about lol
User avatar
Cheryl Rice
 
Posts: 3412
Joined: Sat Aug 11, 2007 7:44 am

Post » Sat Jan 15, 2011 10:28 am

any progress on this, also is there anything you can show us pic or video wise couse some of us dont understand the scripting language and have no idea what your talking about lol

As much as I'd love to show it off I can tell that right now it's too rough to show any body. The grass only bends one way, it stretches abnormally etc, lots to work on before it becomes even close to usable or show-offable in a video. I can try to make one of those developer kind of things where you only show off the good parts ignoring all the faults.
User avatar
Hayley Bristow
 
Posts: 3467
Joined: Tue Oct 31, 2006 12:24 am

Post » Sat Jan 15, 2011 6:22 am

anything would be good like a video showing what your trying to achieve so we can see what to expect for the final product
User avatar
Bird
 
Posts: 3492
Joined: Fri Nov 30, 2007 12:45 am

Post » Sat Jan 15, 2011 6:41 am

anything would be good like a video showing what your trying to achieve so we can see what to expect for the final product

It is http://www.youtube.com/watch?v=x3KA_WWdVlE&hd=1
User avatar
Kate Schofield
 
Posts: 3556
Joined: Mon Sep 18, 2006 11:58 am

Post » Sat Jan 15, 2011 6:40 am

Wow, that's a great start.
User avatar
Ashley Campos
 
Posts: 3415
Joined: Fri Sep 22, 2006 9:03 pm

Post » Sat Jan 15, 2011 10:02 am

Wow, that's a great start.

It was flickering badly early today. But I went ahead and fixed it to show something decent. I wonder if I can make it a fading path so it will give real trails, but without player position, testing would be impossible for now.

And since being there I will try to change the wind animations to http://www.youtube.com/watch?v=Ed4gmlj0Cds.

I think trees are using the same animation codes with this, trees should have their own animations at the end because we don't want to bend the trees. :P

Here is the code:
GrassVertOut GrassVS( GrassVertIn IN ) {
GrassVertOut OUT;

OUT.texcoords = IN.texcoords;

//Animate grass
float4 worldpos = mul(IN.pos, world);

//distance to grass for range
float gdist = length(worldpos.xyz - EyePos.xyz);


float height = clamp(IN.pos.z, 0, 100) / 100;

float2 wind = WindVec * 2.5 + 0.25;

float2 pos_ticks1 = worldpos.xy / 1000 + ticks;
float2 pos_ticks2 = worldpos.xy / 750 + ticks * 2;
float2 pos_ticks3 = worldpos.xy / 500 + ticks * 3;
float2 pos_ticks4 = worldpos.xy / 200 + ticks * 4;

//grass offset for bending
float2 bend_ticks1 = (worldpos.xy - EyePos.xy)/1000 * 1/gdist;


worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;

//interactive grass
if ( gdist < 100 ) {
//remove wind
worldpos.xy -= ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;
//bend
worldpos.xy += (cos(bend_ticks1)) * height * (1/gdist) * 3500;


}

Bolds are my additions... There are four instances of this code in latest ingame.fx file. You should edit all four of them.

I am sure it looks ridiculous for someone who knows this stuff(at least I can sense some unnecessary parts). It needs lot's of tweaking, and I haven't figured out the math of this yet.
User avatar
~Sylvia~
 
Posts: 3474
Joined: Thu Dec 28, 2006 5:19 am

Post » Sat Jan 15, 2011 12:04 pm

Your P.M. box is full so I'll just post this here.

----------------
C_Mireneye for some reason I thought you were already a member at Fliggerty's and just rarely posted there.

It's a fun place to hang at and yes there are tons of script writers there. Plus they are the people working on MSE and so on. :foodndrink:

Here's the link http://www.fliggerty.com/phpBB3/
User avatar
James Hate
 
Posts: 3531
Joined: Sun Jun 24, 2007 5:55 am

Post » Sat Jan 15, 2011 4:24 pm

Your P.M. box is full so I'll just post this here.

----------------
C_Mireneye for some reason I thought you were already a member at Fliggerty's and just rarely posted there.

It's a fun place to hang at and yes there are tons of script writers there. Plus they are the people working on MSE and so on. :foodndrink:

Here's the link http://www.fliggerty.com/phpBB3/

Oh wow, first time it's full in years!

But I am a member of GHF! It is however true that I rarely post there.

@Vtastek That looks good, it does flicker into place some times but it looks surprisingly good already.
Oh but we do want to bend trees and break them but for very different reasons then this. hahaha!

Lol, does any game out there do this with grass? I know Crysis do it with general flora but I don't recall them doing it with their grass.
User avatar
mimi_lys
 
Posts: 3514
Joined: Mon Apr 09, 2007 11:17 am

Post » Sat Jan 15, 2011 1:41 am

I am sure it looks ridiculous for someone who knows this stuff(at least I can sense some unnecessary parts). It needs lot's of tweaking, and I haven't figured out the math of this yet.

It's extremely funny from over here. Like blind men with machetes.
User avatar
Avril Louise
 
Posts: 3408
Joined: Thu Jun 15, 2006 10:37 pm

PreviousNext

Return to III - Morrowind