Shader Grass on the Terrain.

Compozitor

20-05-2006 20:09:20

Sorry don't know in what topic post. Looked in search for this but can't find answer. I want to do Polygonal grass with vertex shaders on the landscape.

How can i do this? How to attach shader to the terrain. Can i do this in the material file or it must be implemented in the client.
Here is the shader.


struct app2vert {
float4 Position : POSITION;
float4 Normal : NORMAL;
float4 TexCoord0 : TEXCOORD0;
float4 Color0 : COLOR0;
};
struct vertout {
float4 Hposition : POSITION;
float4 Color0 : COLOR0;
float4 TexCoord0 : TEXCOORD0;
};
vertout main(app2vert IN,
uniform float4x4 ModelViewProj,
uniform float4x4 ModelView,
uniform float4x4 ModelViewIT,
uniform float4 Constants)
{
vertout OUT;
// we need to figure OUT what the position is
float4 position = IN.Position;
position.z = 0;
position.y = 0;
// add IN the actual base location of
// the straw (stored IN Color0.xz)
position.x = position.x + IN.Color0.x;
position.z = position.z + IN.Color0.z;
// figure OUT where the wind is coming from
float4 origin = float4(20,0,20,0);
float4 dir = position - origin;
// find the intensity of the wind
float inten = sin(Constants.x + .2*length(dir)) *
IN.Position.y;
dir = normalize(dir);
// we need to do some Bezier curve stuff here.
float4 ctrl1 = float4(0,0,0,0);
float4 ctrl2 = float4(0,IN.Color0.y/2,0,0);
float4 ctrl3 = float4(dir.x*inten, IN.Color0.y,
dir.z*inten, 0);
// do the Bezier linear interpolation steps
float t = IN.Color0.w;
float4 temp = lerp(ctrl1, ctrl2, t);
float4 temp2 = lerp(ctrl2, ctrl3, t);
float4 result = lerp(temp, temp2, t);
// add IN the height and wind displacement components
position = position + result;
position.w = 1;
// transform for sending to the reg. combiners
OUT.Hposition = mul(ModelViewProj, position);
// calculate the texture coordinate
// from the position passed IN
OUT.TexCoord0 = float4((IN.Position.x + .05)*10,t,1,1);
// find the normal
// we need one more point to do a partial
temp = lerp(ctrl1, ctrl2, t+0.05);
temp2 = lerp(ctrl2, ctrl3, t+0.05);
float4 newResult = lerp(temp, temp2, t+0.05);
// do a crossproduct with a vector that
// is horizontal across the screen
float normal = cross((result - newResult).xyz,
float3(1,0,0));
normal = normalize(normal);
// calculate diffuse lighting off the normal
// that was just calculated
float3 lightPos = float3(0,5,15);
float3 lightVec = normalize(lightPos - position);
float diffuseInten = dot(lightVec, normal);
// Set up the final color
// The first term is a semi random term based
// on the total height of this straw
// The second term is the diffuse lighting component
OUT.Color0 = normalize(ctrl3) * diffuseInten *
IN.Position.z;
return OUT;
}


Maybe some Examples??

Seraph

21-05-2006 03:00:23

you should rewrite your shader in ogre material script. and attach the material to your grass entity. see this wiki article for more detailed description.
http://www.ogre3d.org/wiki/index.php/Getting_Started_With_Ogre_CG_Materials

Compozitor

21-05-2006 09:13:21

Thx!

Compozitor

21-05-2006 10:46:49

Hm... still can't get it to work.....

I created box.mesh it has material Box

i created this .material file.


vertex_program PolyGrass_VS cg
{
source PolyGrass.vert
entry_point main
profiles vs_2_0

default_params
{
param_named_auto ModelViewProj worldviewproj_matrix
param_named_auto ModelView worldviewproj_matrix
param_named_auto ModelViewIT inversetranspose_worldview_matrix
param_named Constants float4 1 1 1 1
}
}

material Box
{
technique
{
pass
{
vertex_program_ref PolyGrass_VS
{
}
}


And i have PolyGrass.vert in the same directory.
But when i login in to the game, i see only 1 grass stem. and it have black color.

Can someone help me with thise? I will be very appriciate to you!

Falagard

21-05-2006 17:35:54

Post on the main forums, this has nothing to do with the Paging Landscape addon.