[WIP]Interactive Grass

Post » Sat Jan 15, 2011 4:55 am

It's extremely funny from over here. Like blind men with machetes.

Care to give us two pair of eyes? Haha.
User avatar
Hannah Barnard
 
Posts: 3421
Joined: Fri Feb 09, 2007 9:42 am

Post » Sat Jan 15, 2011 4:44 am

It's extremely funny from over here. Like blind men with machetes.

I get that a lot. :)

http://www.youtube.com/watch?v=ZKm0YeKAq9E
User avatar
Hearts
 
Posts: 3306
Joined: Sat Oct 20, 2007 1:26 am

Post » Sat Jan 15, 2011 4:46 am

Couple code edits I'd suggest:
GrassVertOut GrassVS( GrassVertIn IN ) {GrassVertOut OUT;OUT.texcoords = IN.texcoords;//Animate grassfloat4 worldpos = mul(IN.pos, world);//distance to grass for rangefloat 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 bendingfloat2 bend_ticks1 = (worldpos.xy - EyePos.xy)/1000 * 1/gdist;//interactive grassif ( gdist < 100 ) {	//bend	worldpos.xy += (cos(bend_ticks1)) * height * (1/gdist) * 3500;} else {	worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;}


Instead of removing the wind effect, just don't apply it. But, why would wind not be applied? You could cut it down somewhat, but I don't see why you're removing it completely.
User avatar
Sun of Sammy
 
Posts: 3442
Joined: Mon Oct 22, 2007 3:38 pm

Post » Sat Jan 15, 2011 5:01 pm

Couple code edits I'd suggest:
snip
Instead of removing the wind effect, just don't apply it. But, why would wind not be applied? You could cut it down somewhat, but I don't see why you're removing it completely.

I wanted to control it alone, I was thinking "after getting the effect I want I will reapply it back.".
User avatar
Lovingly
 
Posts: 3414
Joined: Fri Sep 15, 2006 6:36 am

Post » Sat Jan 15, 2011 11:46 am

I wanted to control it alone, I was thinking "after getting the effect I want I will reapply it back.".

Any progress on this?

Lol, look who's talking. I guess I should be one of the guys to make progress haha.
User avatar
quinnnn
 
Posts: 3503
Joined: Sat Mar 03, 2007 1:11 pm

Post » Sat Jan 15, 2011 1:03 am

Any progress on this?

Lol, look who's talking. I guess I should be one of the guys to make progress haha.

Mireneye. :shakehead: And I was waiting for you! :P

Well, above code is giving a good effect,

as you make the initial step, grass offsets suddenly,
as you weight on your step, grass crushes under your feet more.

And since you're stepping on it, wind can't shake it.

It can't get more realistic than this. :P
User avatar
Adam
 
Posts: 3446
Joined: Sat Jun 02, 2007 2:56 pm

Post » Sat Jan 15, 2011 5:07 am

Mireneye. :shakehead: And I was waiting for you! :P

Well, above code is giving a good effect,

as you make the initial step, grass offsets suddenly,
as you weight on your step, grass crushes under your feet more.

And since you're stepping on it, wind can't shake it.

It can't get more realistic than this. :P

Does it still only bend in one direction tho?
User avatar
Jessica Stokes
 
Posts: 3315
Joined: Fri Jul 28, 2006 11:01 am

Post » Sat Jan 15, 2011 2:39 am

Does it still only bend in one direction tho?

Nope! :)

But the problem is you can't see it since it is only working in first person.
User avatar
Dalton Greynolds
 
Posts: 3476
Joined: Thu Oct 18, 2007 5:12 pm

Post » Sat Jan 15, 2011 1:57 pm

I used the same trick on phal's wavy waters, I am making waves around me. I feel like Moses. :)

With some programming I assume we can get something better than old water's distortion effects. Addition of player position(s) and some MGE programming for storing previous frame(s) direction and velocity info(accumulation buffers?), it seems very possible to me...
User avatar
joannARRGH
 
Posts: 3431
Joined: Mon Mar 05, 2007 6:09 am

Post » Sat Jan 15, 2011 5:37 pm

I used the same trick on phal's wavy waters, I am making waves around me. I feel like Moses. :)

With some programming I assume we can get something better than old water's distortion effects. Addition of player position(s) and some MGE programming for storing previous frame(s) direction and velocity info(accumulation buffers?), it seems very possible to me...

Interesting =)

I'm happy that I helped spawn some wicked ideas.
User avatar
Brandon Bernardi
 
Posts: 3481
Joined: Tue Sep 25, 2007 9:06 am

Post » Sat Jan 15, 2011 5:24 pm

Any progress with this? The water shader is doing a fine job displacing around the player in 3rd person. What about grass? :3 Seems as though everything is now in MGE to make this happen.
User avatar
Natasha Callaghan
 
Posts: 3523
Joined: Sat Dec 09, 2006 7:44 pm

Post » Sat Jan 15, 2011 8:30 am

Is this Project dead?

Or are people really working on it in the MGE team?
User avatar
Blessed DIVA
 
Posts: 3408
Joined: Thu Jul 13, 2006 12:09 am

Post » Sat Jan 15, 2011 11:18 am

Any progress with this? The water shader is doing a fine job displacing around the player in 3rd person. What about grass? :3 Seems as though everything is now in MGE to make this happen.

I think so too. :tops:

Is this Project dead?

Or are people really working on it in the MGE team?

I don't think it is dead. But it is possible no one is working on it, I'm not. Should I be working on it? I'm not an advanced programmer. The positioning of grass blades makes it harder to bend them correctly. Maybe just scaling can work instead of bending.
User avatar
Maddy Paul
 
Posts: 3430
Joined: Wed Feb 14, 2007 4:20 pm

Post » Sat Jan 15, 2011 4:25 am

Should I be working on it?

Yes you should! I saw your youtube video, looked just like crysis, though you did mention you hadn't gotten 3rd person to work yet.
User avatar
Ebony Lawson
 
Posts: 3504
Joined: Fri Feb 16, 2007 11:00 am

Post » Sat Jan 15, 2011 8:11 am

I don't think it is dead. But it is possible no one is working on it, I'm not. Should I be working on it? I'm not an advanced programmer. The positioning of grass blades makes it harder to bend them correctly. Maybe just scaling can work instead of bending.
If you've got the time and the will, I say go for it. Either way, I'm sure this would be an incredibly popular shader.

Either way, is there a version of this in this thread that works in 1st person? If so, which version is it and what do I have to do to ingame.fx to apply it?
User avatar
Annika Marziniak
 
Posts: 3416
Joined: Wed Apr 18, 2007 6:22 am

Post » Sat Jan 15, 2011 5:56 pm

In Phal's latest beta version of MGE, you can call PlayerPos instead of EyePos, which with a bit of modification and tweaking makes the code posted by Peachykeen on page 2 work both in third person and first person. Here's what I put in my InGame.fx file, it works pretty well for me, even though the grass can get somewhat jerky.

	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.xy - PlayerPos.xy);	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 - PlayerPos.xy)/1000 * 1/gdist;	//interactive grassif ( gdist < 100 ) {	//bend	worldpos.xy += (bend_ticks1)/abs(bend_ticks1)*(cos(bend_ticks1)) * height * 1/(25+gdist) * 3500;} else {	worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;}


edit: here's a video of it http://www.youtube.com/watch?v=HjqFOvYOUVI
User avatar
Ross Thomas
 
Posts: 3371
Joined: Sat Jul 21, 2007 12:06 am

Post » Sat Jan 15, 2011 3:56 am

Very vice tomerk! :)

Any FPS hit?

I don't think i'd use it since i tend to play in first person and it wouldnt really be that noticeable.
User avatar
BRIANNA
 
Posts: 3438
Joined: Thu Jan 11, 2007 7:51 pm

Post » Sat Jan 15, 2011 11:30 am

thats awesome iv been waiting for this, so do i just edit the ingame like shown to get this function or are there scripts to add also???
User avatar
Harry-James Payne
 
Posts: 3464
Joined: Wed May 09, 2007 6:58 am

Post » Sat Jan 15, 2011 10:59 am

Didn't work for me, i just pasted it last in ingame.fx. All i got was a kind of stuttering grass.
User avatar
Logan Greenwood
 
Posts: 3416
Joined: Mon Jul 30, 2007 5:41 pm

Post » Sat Jan 15, 2011 2:20 pm

Didn't work for me, i just pasted it last in ingame.fx. All i got was a kind of stuttering grass.


Find this section of code in the .ini file

GrassVertOut GrassVS (GrassVertIn IN) {	GrassVertOut OUT;	OUT.texcoords = IN.texcoords;
now look at his code, add only his changes into that section of code.

however, I just tried doing this myself and it causes mge to suggest that the ingame.fx file is unreadable, I'm not exactly sure why.........give me a few minutes and I'll see if I can figure it out.
User avatar
brian adkins
 
Posts: 3452
Joined: Mon Oct 01, 2007 8:51 am

Post » Sat Jan 15, 2011 8:32 am

okay everytime i add the new bit of code to the ingame morrowind can no longer load the distantland effects so not water grass or shaders anything, any reason it might do this im using phals mge beta v5
User avatar
Sarah Evason
 
Posts: 3507
Joined: Mon Nov 13, 2006 10:47 pm

Post » Sat Jan 15, 2011 5:36 am

awersume
User avatar
JD FROM HELL
 
Posts: 3473
Joined: Thu Aug 24, 2006 1:54 am

Post » Sat Jan 15, 2011 9:06 am

@tomerk
Very nice video tomerk. It appears to be working better than I expect. :foodndrink:


however, I just tried doing this myself and it causes mge to suggest that the ingame.fx file is unreadable, I'm not exactly sure why.........give me a few minutes and I'll see if I can figure it out.


okay everytime i add the new bit of code to the ingame morrowind can no longer load the distantland effects so not water grass or shaders anything, any reason it might do this im using phals mge beta v5

You have to be careful, only one mistake will cause an error. Try to maintain the order and apply it to correct places.
User avatar
Ruben Bernal
 
Posts: 3364
Joined: Sun Nov 18, 2007 5:58 pm

Post » Sat Jan 15, 2011 2:25 pm

@tomerk
Very nice video tomerk. It appears to be working better than I expect. :foodndrink:




You have to be careful, only one mistake will cause an error. Try to maintain the order and apply it to correct places.

well i copyed and pasted what was put on here, i dont see what i might have done wrong
heres section of my ingame with the grassvertout in the middle ish

//------------------------------------------------------------

struct GrassVertIn {
float4 pos : POSITION;
float3 normal : NORMAL;
float4 color : COLOR0;
float2 texcoords : TEXCOORD0;
};

//------------------------------------------------------------

struct GrassVertOut {
float4 pos : POSITION;
float2 texcoords : TEXCOORD0;
float3 color : COLOR0;
FOGTYPE fog : TEXCOORD1;
float4 screenpos: TEXCOORD4;
float blend : TEXCOORD5;
};

//------------------------------------------------------------

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.xy - PlayerPos.xy);

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 - PlayerPos.xy)/1000 * 1/gdist;

//interactive grass
if ( gdist < 100 ) {
//bend

worldpos.xy += (bend_ticks1)/abs(bend_ticks1)*(cos(bend_ticks1)) * height * 1/(25+gdist) * 3500;

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

//------------------------------------------------------------

GrassVertOut GrassInstVS (StatInstVertIn IN) {
GrassVertOut OUT;

// Pack instance transform
float4x4 worldmat = float4x4 (IN.m1, IN.m2, IN.m3, IN.m4);

OUT.texcoords = IN.texcoords;

// Define % to Fog
float4 worldpos = mul (IN.pos, worldmat);

#ifdef EXPFOG
float3 EyeVec = worldpos.xyz - EyePos.xyz;
float dist = length (EyeVec);
EyeVec /= dist;
#ifdef SCATTER
OUT.fog = getFog (EyeVec,dist);
#else
OUT.fog = float4 (skyfogblend (EyeVec.z), getFog (dist));
#endif
#else
float dist = length (worldpos.xyz - EyePos.xyz);
OUT.fog = getFog (dist);
#endif

OUT.blend = 1 - (saturate ((GrassDist - dist) / (GrassDist / 5)));
OUT.blend += 0.4;
OUT.screenpos = 0;

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

float2 wind = WindVec / 6;

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;

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

// Projection
OUT.pos = mul (worldpos, view);
OUT.pos = mul (OUT.pos, proj);

// Lighting
OUT.color = (SunCol * 0.25) + SunAmb;

return OUT;
}

is this right?
User avatar
Erika Ellsworth
 
Posts: 3333
Joined: Sat Jan 06, 2007 5:52 am

Post » Sat Jan 15, 2011 8:29 am

well i copyed and pasted what was put on here, i dont see what i might have done wrong
heres section of my ingame with the grassvertout in the middle ish

is this right?

There are 4 intances of grass code.

Search for
//Animate grass

there is a line
float4 worldpos = mul (IN.pos, world);

in 2 of those 4 instances.
Move this line above "//animate grass" line.

Then it will look like this, all 4 instances:
//Animate grass		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;		worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;


then change that part with

// Animate grass		//distance to grass for range	float gdist = length(worldpos.xy - PlayerPos.xy);	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 - PlayerPos.xy)/1000 * 1/gdist;	//interactive grassif ( gdist < 100 ) {	//bend	worldpos.xy += (bend_ticks1)/abs(bend_ticks1)*(cos(bend_ticks1)) * height * 1/(25+gdist) * 3500;} else {	worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;}

User avatar
:)Colleenn
 
Posts: 3461
Joined: Thu Aug 31, 2006 9:03 am

PreviousNext

Return to III - Morrowind