texture splatting problem

Started by
0 comments, last by Programmer101 17 years, 1 month ago
hi ,ı am using brute force generated heightmap terrain,ı want to ask something is there another way keep up performance instead of 4 time call DrawIndexedPrimitive..normally 98 fps at my old pc 800mhz 196ram and 64mb vdcard, but if use splatting 38-39fps also ı cant see 4 texture blended,first texture and 4.texture seem blended at terrain ,i took referance from charles bloom example... m_device->SetTexture(0, m_Alpha); m_device->SetTexture(1, m_Texture); m_device->DrawIndexedPrimitiveD3DPT_TRIANGLELIST,0,0, TerrainVertices,0,TerrainPrimitives) . . . . here are the links,even 128mb videocard still cant get 4 texture splatted,what is the be reason? http://www.imagehosting.com/show.php/350280_demo.JPG.html http://www.imagehosting.com/show.php/350290_newdemo.JPG.html thx for any reply
Advertisement
You shouldn't be redrawing the terrain. That unnecessarily slows down your engine! A good way to do it is with a pixel shader. That way you only draw the terrain once and the shader splats. Take this for example:

// Pixel shader input structurestruct PS_INPUT{    float4 Position    : POSITION;    float3 Normal      : NORMAL;    float2 Texture     : TEXCOORD0;    float4 vColor      : COLOR0;};// Pixel shader output structurestruct PS_OUTPUT{    float4 Color   : COLOR0;};// Global variablestexture texture0;texture texture1;texture texture2;texture texture3;sampler2D Tex0 =sampler_state{       texture = texture0;    MipFilter = LINEAR;    MinFilter = LINEAR;    MagFilter = LINEAR;};sampler2D Tex1 =sampler_state{       texture = texture1;    MipFilter = LINEAR;    MinFilter = LINEAR;    MagFilter = LINEAR;};sampler2D Tex2 =sampler_state{       texture = texture2;    MipFilter = LINEAR;    MinFilter = LINEAR;    MagFilter = LINEAR;};sampler2D Tex3 =sampler_state{       texture = texture3;    MipFilter = LINEAR;    MinFilter = LINEAR;    MagFilter = LINEAR;};float4x4 matWorld;float4 LightDir;float4 LightColor;// Name: Simple Pixel Shader// Type: Pixel shader// Desc: Fetch texture and blend with constant colorPS_OUTPUT ps_main( in PS_INPUT In ){    PS_OUTPUT Out;    //Texture splatting vars    float4 splat = tex2D(Tex1, In.Texture/32.0/2.0-0.5);    float4 s2;    float4 s3;    float3 LightD = {0.0,-1.0,0.0};    float3 Normal = {0.0,1.0,0.0};    //Texture splatting    Out.Color = tex2D(Tex0, In.Texture)*(1.0-splat[0]-splat[1]);    s2 = tex2D(Tex2, In.Texture) * splat[0];    Out.Color += s2;    s3 = tex2D(Tex3, In.Texture) * splat[1];    Out.Color += s3;    Out.Color *= In.vColor;    return Out;}


This shader has the base texture(dirt) in stage 0. It has the other two textures in stage 2 and 3 (grass and snow). In stage 1 is the splat texture. The red channel defines the splat for grass, the blue channel for snow. You could potentially have the green and alpha channels hold other splats for different textures.

If you don't understand what I'm trying to say I can give you the full shader and source code.

This topic is closed to new replies.

Advertisement