Need help, splatting with Arras's Title terrain

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Showen
Posts: 4
Joined: Wed Feb 11, 2009 5:17 pm

Need help, splatting with Arras's Title terrain

Post by Showen »

For the reason that I'm a newb in IRR and shaders,there're many difficulties confused me when I'm using BlindSide's Shader :

Code: Select all


sampler2D coverage; //coverage 
sampler2D lightmap; //lightmap 

sampler2D splat1; 
sampler2D splat2; 

// Pixel shader output structure 
struct PS_OUTPUT 
{ 
    float4 Color : COLOR0;  // Pixel color    
}; 

struct PS_INPUT 
{ 
   float4 Position : POSITION; 
   float4 Diffuse  : COLOR0; 
    
   float2 LightmapTexCoord : TEXCOORD1; //lightmap texture coords 
    
   float2 SplatTexCoord1 : TEXCOORD2; //1st spalt texture coords 
   float2 SplatTexCoord2 : TEXCOORD3; //2nd spalt texture coords 
   float normalDist : TEXCOORD0; 
}; 
    
PS_OUTPUT main( PS_INPUT Input ) 
{ 
   PS_OUTPUT Output; 

       
   float4 TexColor = lerp(tex2D( splat2, Input.SplatTexCoord2), 
               tex2D( splat1, Input.SplatTexCoord1),Input.normalDist); 
    
   float4 LightmapColor = tex2D( lightmap, Input.LightmapTexCoord );  // lightmap 

   Output.Color = Input.Diffuse * TexColor * LightmapColor; 

   return Output; 
}  


1.Here the coverage means what? :shock:

2.how do i add the textures(coverage,lightmap,splatmap) to the material?
I simply add the getMaterial().setTexture() behind the set detail texture as follow, apparently unreasonable and invalid. :oops:

Code: Select all

 // load color map 
   terrain->loadColorMap("colormap.jpg");

   // set detail texture 
   terrain->setMaterialTexture(0, driver->getTexture("detailmap.jpg"));
 
   terrain->getMaterial(0).MaterialType = (video::E_MATERIAL_TYPE)TexSplatting;
   
   terrain->getMaterial(0).setTexture(0, driver->getTexture("coverage.png"));
   terrain->getMaterial(0).setTexture(1, driver->getTexture("lightmap.png")); 
   terrain->getMaterial(0).setTexture(2, driver->getTexture("splatmap1.png"));
   terrain->getMaterial(0).setTexture(3, driver->getTexture("splatmap2.png"));


3.It seems that the lightmap texture coords here equate with CTexture(defined in Arras's app)'s coords which just corresponds to vissible terrain mesh,how do i make it correspond to whole terrain?

Besides, It seems that the link of Hex terrain editor was dead,
If anyone who can offer me another , I would be extremely grateful!
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I don't remember releasing any texture splatting specifically for Arras terrain...but whatever:
1.Here the coverage means what? Shocked
Coverage means nothing, you can delete the line "sampler2D coverage; //coverage". Because this shader used to use the coverage shader to interpolate between the two texture but now it just uses the Normal's Y coord, so it doesn't need it.

2.how do i add the textures(coverage,lightmap,splatmap) to the material?
Change

Code: Select all

sampler2D lightmap; //lightmap

sampler2D splat1;
sampler2D splat2; 
To

Code: Select all

sampler2D lightmap : register(s0); //lightmap

sampler2D splat1 : register(s1);
sampler2D splat2 : register(s2); 
and set the textures as follows:

Code: Select all

   terrain->getMaterial(0).setTexture(0, driver->getTexture("lightmap.png"));
   terrain->getMaterial(0).setTexture(1, driver->getTexture("splatmap1.png"));
   terrain->getMaterial(0).setTexture(2, driver->getTexture("splatmap2.png")); 
So basically get rid of coverage texture and move everything down one index.

I think thats it for now, I'm not sure about the lightmaps texcoords, what does the vertex shader look like?

Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Showen
Posts: 4
Joined: Wed Feb 11, 2009 5:17 pm

Post by Showen »

Thank you for your answer . :)
I fixed it as what you teached me. then, I tryed to make the Texture to fit
the Terrain ,so i fixed Arras's code as follows ,but it seemed no use...

Code: Select all

 CTexture = driver->addTexture(core::dimension2d<s32>(tw, th), "colortexture", video::ECF_A8R8G8B8);

    driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mmflag);

    Material[0].TextureLayer[0].Texture = CTexture;
    Material[0].TextureLayer[0].TextureWrap = video::ETC_CLAMP_TO_EDGE;

    // setup UV coordinates of vertices on 2nd texture layer
    f32 ax = (f32)MeshSize.Width / CTexture->getSize().Width / MeshSize.Width;
    f32 ay = (f32)MeshSize.Height/ CTexture->getSize().Height / MeshSize.Height;
    f32 ry = 1.0f - (f32)MeshSize.Height/ CTexture->getSize().Height;

    s32 n = MeshSize.Height-1;
    for(s32 j=0; j<MeshSize.Height; j++)
    {
        for(s32 i=0; i<MeshSize.Width; i++)
        {
            Tile(i,n).Vertex[0]->TCoords = core::vector2d<f32>(i*ax, ry+(j+1)*ay);
            Tile(i,n).Vertex[1]->TCoords = core::vector2d<f32>(i*ax, ry+j*ay);
            Tile(i,n).Vertex[3]->TCoords = core::vector2d<f32>((i+1)*ax, ry+(j+1)*ay);
            Tile(i,n).Vertex[2]->TCoords = core::vector2d<f32>((i+1)*ax, ry+j*ay);
        }
        n--;
    }
        //NOTE:
	//Here i add sth. to have a test
	f32 sx=2.0f;
	f32 sy=2.0f;
	Material[0].getTextureMatrix(0).setTextureTranslate(sx,sy);
Here is your vertexshad.hlsl

Code: Select all

float4x4 mWorldViewProj;  // World * View * Projection transformation 

// Vertex shader output structure 
struct VS_OUTPUT 
{ 
   float4 Position   : POSITION;   // vertex position 
   float4 Diffuse    : COLOR0;     // vertex diffuse color 
    
   float2 LightmapTexCoord : TEXCOORD1; //lightmap texture coords 
    
   float2 SplatTexCoord1 : TEXCOORD2; //1st spalt texture coords 
   float2 SplatTexCoord2 : TEXCOORD3; //2nd spalt texture coords 
   float normalDist : TEXCOORD0; 
}; 

struct VS_INPUT 
{ 
   float4 Position   : POSITION; 
   float3 Normal      : NORMAL; 
   float4 Diffuse      : COLOR0; 
   float2 TexCoord0   : TEXCOORD0; 
   float2 TexCoord1   : TEXCOORD1; 
}; 


VS_OUTPUT main(VS_INPUT Input) 
{ 
   VS_OUTPUT Output; 

   // transform position to clip space 
   Output.Position = mul(Input.Position, mWorldViewProj); 
    
   Output.Diffuse = Input.Diffuse; 
   Output.LightmapTexCoord = Input.TexCoord0; 
    
   Output.SplatTexCoord1 = Input.TexCoord1; 
   Output.SplatTexCoord2 = Input.TexCoord1; 
    
   Output.normalDist = Input.Normal.y; 
    
   return Output; 
} 
Post Reply