Gamestudio Links
Zorro Links
Newest Posts
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
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 1 of 4 1 2 3 4
waving grass #17719
10/01/03 05:13
10/01/03 05:13
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
i adapted the waving grass shader which can be found at the ati website for a6!

Code:
texture texSkin1;


matrix matWorldViewProj;
matrix matWorldView;

vector vecFog;
vector vecTime;

technique grass
{
pass p0
{
Texture[0]=<texSkin1>;
ZWriteEnable=true;
AlphaTestEnable=true;
CullMode=none;

VertexShaderConstant[0]=<matWorldViewProj>;
VertexShaderConstant[8]=<matWorldView>;
VertexShaderConstant[16]=<vecFog>;
VertexShaderConstant[32]=<vecTime>;
VertexShaderConstant[33]=(0.0f,0.5f,1.0f,2.0f); // common constants
VertexShaderConstant[34]=(-0.16161616f,0.0083333f,-0.00019841f,0.000002755731f); // (-1/3!,1/5!,-1/7!,1/9!)
VertexShaderConstant[35]=(4.0f,1.57079632f,3.14159265f,6.28318530f); // (4.0,pi/2,pi,pi*2)
VertexShaderConstant[36]=(1.07f,0.0f,0.0f,0.0f); // fixup factor

VertexShaderConstant[40]=(2.5f,1.0f,0.5f,0.1f); // wave distort x
VertexShaderConstant[41]=(5.0f,0.5f,0.25f,0.1f); // wave distort y
VertexShaderConstant[42]=(-1.0f,-0.01f,-0.04f,-0.01f); // wave distort z
VertexShaderConstant[43]=(-0.1f,-0.2f,0.1f,0.05f); // wave dir x
VertexShaderConstant[44]=(-0.005f,-0.01f,-0.005f,-0.0025f); // wave dir y
VertexShaderConstant[45]=(0.02f,0.04f,0.05f,0.1f); // wave speed
VertexShaderConstant[46]=(0.35f,0.1f,0.1f,0.025f); // lighting wave scale
VertexShaderConstant[47]=(0.6f,0.8f,0.2f,0.0f); // lighting scale bias

VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[2]; //uv
}
asm
{
vs.1.1

mov r1.w,c16.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position (v0 is the position without sinusodial warping!)
add r0,r0,-c16.x // distance-fog_start
mad r0.x,-r0.x,c16.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog.x,r0.x,c33.x // clamp with custom max value

mul r0,c43,v0.x // use vertex pos x as inputs to sinusoidal warp
mad r0,c44,v0.y,r0 // use vertex pos y as inputs to sinusoidal warp

mov r1,c32.w // get current time
mad r0,r1,c45,r0 // add scaled time
frc r0.xy,r0 // take fraction of all 4 components
frc r1.xy,r0.zwzw
mov r0.zw,r1.xyxy

mul r0,r0,c36.x // multiply by fixup factor (due to inaccuracy of taylor series)
sub r0,r0,c33.y // subtract 0.5
mul r1,r0,c35.w // range -pi to pi

mul r2,r1,r1 // wave_vec^2
mul r3,r2,r1 // wave_vec^3
mul r5,r3,r2 // wave_vec^5
mul r7,r5,r2 // wave_vec^7
mul r9,r7,r2 // wave_vec^9

mad r0,r3,c34.x,r1 // wave_vec-(wave_vec^3)/3!
mad r0,r5,c34.y,r0 // +(wave_vec^5)/5!
mad r0,r7,c34.z,r0 // -(wave_vec^7)/7!
mad r0,r9,c34.w,r0 // +(wave_vec^9)/9!

dp4 r3.x,r0,c40
dp4 r3.y,r0,c41
dp4 r3.zw,r0,c42

sub r4,c33.z,v7.y // attenuate sinusoidal warping by (1-uv.y)^2
mul r4,r4,r4
mul r3,r3,r4

mov r2.w,v0
add r2.xyz,r3,v0 // add sinusoidal warping to grass position
m4x4 oPos,r2,c0 // transform position to clip space

dp4 r1.x,r0,c46 // scale and add sin waves together
mad oD0,c47.xzxz,-r1.x,c47.y // scale and bias color values (green is scaled more than red and blue)
mov oT0.xy,v7.xy // output uvs
};

PixelShader=
asm
{
ps.1.3
def c0,1,1,1,1
def c1,0,0,0,0
tex t0 // sample t0
mov r0,t0
cnd r0.a,r0.a,c0,c1 // if(r0.a>0.5){r0.a=1;}else{r0.a=0;}
mul_x2 r0.rgb,r0,v0 // modulate with lighting
};
}
}



use some intersecting quads as grass model. the grass texture should be a tga bitmap with alphachannel. the polygons will be rendered two-sided.

there are a lot of parameters to tweak (c40-c47) and i am sure it's possible to achieve nicer motion than with my settings!



Re: waving grass [Re: ventilator] #17720
10/01/03 07:58
10/01/03 07:58
Joined: Oct 2001
Posts: 678
Alabama
Cameron_Aycock Offline
Developer
Cameron_Aycock  Offline
Developer

Joined: Oct 2001
Posts: 678
Alabama
WOW - You never cease to amaze me Ven!

Can you give a better description of what you did? Can you release any files to play with? What do you recommend to learn shader development?

I re-wrote the terrain sewing code if you think you could use that. It is in another thread...no tracing.


Popular media is the opiate of the masses. Think for yourself.
Re: waving grass [Re: Cameron_Aycock] #17721
10/01/03 09:20
10/01/03 09:20
Joined: Feb 2003
Posts: 2,826
Margaritaville (Redneck Rivier...
myrlyn68 Offline
Senior Expert
myrlyn68  Offline
Senior Expert

Joined: Feb 2003
Posts: 2,826
Margaritaville (Redneck Rivier...
While I do not have access to the A6 shaders yet, this type of stuff is pretty straight forward. If you do a search for shader development groups - you will find a few different methods to accomplish it, including this one.

Also, if I recall they used grass as an example in ShaderX (the book) - though it is at work, so I can't look right now.


Virtual Worlds - Rebuilding the Universe one Pixel at a Time. Take a look - daily news and weekly content updates.
Re: waving grass [Re: myrlyn68] #17722
10/01/03 09:47
10/01/03 09:47
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
as far as i know this shader from ati is exactly the same as in the shaderx book. i just did some changes to it so that it works with a6 and i created some grass models for it.

for learning the basics about shaders i read the vertex- and pixelshader introductions by wolfgang engel -> www.direct3d.net. they are great! the assembler language is easy but for more complex shaders my maths skills are somewhat lacking! for example vertex shaders have to use taylor series to calculate sine values and i don't really understand how taylor series work!

Re: waving grass [Re: ventilator] #17723
10/01/03 09:50
10/01/03 09:50
Joined: Feb 2003
Posts: 2,826
Margaritaville (Redneck Rivier...
myrlyn68 Offline
Senior Expert
myrlyn68  Offline
Senior Expert

Joined: Feb 2003
Posts: 2,826
Margaritaville (Redneck Rivier...
Also - for those who are playing with the shaders, Gamasutra ran a short article on an interesting water effect (light refracting and causing the ground under water to show light and dark spots with the waters ripples). It contained the full code and what not (I forget if it used any DX9 commands or if it was all DX8...). Pretty interesting stuff (though completely off topic).


Virtual Worlds - Rebuilding the Universe one Pixel at a Time. Take a look - daily news and weekly content updates.
Re: waving grass [Re: myrlyn68] #17724
10/02/03 00:05
10/02/03 00:05
Joined: Oct 2001
Posts: 395
Arlington Heights, IL USA
cbw Offline
Senior Member
cbw  Offline
Senior Member

Joined: Oct 2001
Posts: 395
Arlington Heights, IL USA
I don't think it's off topic, it's a shader effect, and this is the shader forum. I think I know what you're talking about, but what about the top of the water? http://mirror.ati.com/developer/samples/oceanwater.html If anyone (I'm looking at you Ven) wants to try coverting this, I think it'll make realistic water that much easier in 3DGS.

Last edited by gscbw; 10/02/03 00:11.

Greg Szemiot, Lead Designer, Orb Crossbeam Studios Entertainment
Re: waving grass [Re: cbw] #17725
10/02/03 04:01
10/02/03 04:01
Joined: Oct 2001
Posts: 678
Alabama
Cameron_Aycock Offline
Developer
Cameron_Aycock  Offline
Developer

Joined: Oct 2001
Posts: 678
Alabama
I second that!


Popular media is the opiate of the masses. Think for yourself.
Re: waving grass [Re: Cameron_Aycock] #17726
10/02/03 04:19
10/02/03 04:19
Joined: Feb 2003
Posts: 2,826
Margaritaville (Redneck Rivier...
myrlyn68 Offline
Senior Expert
myrlyn68  Offline
Senior Expert

Joined: Feb 2003
Posts: 2,826
Margaritaville (Redneck Rivier...


Virtual Worlds - Rebuilding the Universe one Pixel at a Time. Take a look - daily news and weekly content updates.
Re: waving grass [Re: ventilator] #17727
10/03/03 04:44
10/03/03 04:44
Joined: Aug 2000
Posts: 7,490
O
Orange Brat Offline

Senior Expert
Orange Brat  Offline

Senior Expert
O

Joined: Aug 2000
Posts: 7,490
Check this out:

http://www.idvinc.com/


My User Contributions master list - my initial post links are down but scroll down page to find list to active links
Re: waving grass [Re: ventilator] #17728
10/05/03 20:36
10/05/03 20:36
Joined: Mar 2003
Posts: 1,095
Germany
nightshade Offline
Serious User
nightshade  Offline
Serious User

Joined: Mar 2003
Posts: 1,095
Germany
Gute leistung ventilator!

Page 1 of 4 1 2 3 4

Moderated by  Blink, Hummel, Superku 

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