Terrain Texture Splatting only diffuse? hlsl

Started by
2 comments, last by Tophurious 16 years, 4 months ago
Hi, I'm just implementing terrain texture splatting and I've hit a problem. I can see that the alpha blending has worked but there seems to be no detail on the texture. Just a solid green or gray, depending on the given texture. Some code... Setting effect file

// transformations provided by the app as input
float4x4 matWorldViewProj: WORLDVIEWPROJECTION;
float4x4 matWorld :WORLD;
float3 vecLightDir;  
texture BaseTexture;
texture OneTexture; 
texture TwoTexture; 
texture ThreeTexture; 
texture AlphaTexture; 

sampler2D Base : register(s0) = sampler_state 
{
    texture = <BaseTexture>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
 
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

sampler2D One : register(s1) = sampler_state 
{
    texture = <OneTexture>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
 
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};
sampler2D Two : register(s2) = sampler_state 
{
    texture = <TwoTexture>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
 
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

sampler2D Three : register(s3) = sampler_state 
{
    texture = <ThreeTexture>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
 
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

sampler2D Alpha : register(s4) = sampler_state 
{
    texture = <AlphaTexture>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
 
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};




Vertex Shader

struct VS_INPUT                           
{                                          
    float4 Pos   : POSITION;                 
    float2 AlphaTexture	: TEXCOORD0;  
    float2 BaseTexture	: TEXCOORD1;
    float2 OneTexture	: TEXCOORD2; 
    float2 TwoTexture	: TEXCOORD3; 
    float2 ThreeTexture	: TEXCOORD4; 
    float3 Normal: NORMAL;
};                                         

struct VS_OUTPUT
{
    float4 Pos  : POSITION;
    float2 AlphaTexture	: TEXCOORD0; 
    float2 BaseTexture	: TEXCOORD1;
    float2 OneTexture	: TEXCOORD2; 
    float2 TwoTexture	: TEXCOORD3; 
    float2 ThreeTexture	: TEXCOORD4;
    float3 Light: TEXCOORD5; 
    float3 Norm : TEXCOORD6; 
};

VS_OUTPUT VS(VS_INPUT IN)                   
{
    VS_OUTPUT Out = (VS_OUTPUT)0; 

    //Transform vertex positions       

    //Transform Position
    Out.Pos = mul( matWorldViewProj,IN.Pos ); 
   
    //Texture co-ordinate 
    Out.BaseTexture = IN.BaseTexture;  
    Out.OneTexture = IN.OneTexture;   
    Out.TwoTexture = IN.TwoTexture;   
    Out.ThreeTexture = IN.ThreeTexture;   
    Out.AlphaTexture = IN.AlphaTexture;                         

    //Light direction	
    Out.Light = normalize(vecLightDir);
	
    //Normal	
    Out.Norm = normalize(mul(IN.Normal,matWorld)); 
	 
    return Out;
}




Pixel Shader

struct PS_INPUT
{
    float2 AlphaTexture	: TEXCOORD0; 
    float2 BaseTexture	: TEXCOORD1;
    float2 OneTexture	: TEXCOORD2; 
    float2 TwoTexture	: TEXCOORD3; 
    float2 ThreeTexture	: TEXCOORD4; 
    float3 Light	: TEXCOORD5;
    float3 Norm		: TEXCOORD6; 
};                               

struct PS_OUTPUT
{
    float4 tex : COLOR0;
};

PS_OUTPUT PS(PS_INPUT IN)   
{
    PS_OUTPUT output = (PS_OUTPUT)0;
	
    //Get textures
    float4  b = tex2D(Base, IN.BaseTexture);
    float4  a = tex2D(Alpha, IN.AlphaTexture);
    float4  i = tex2D(One, IN.OneTexture);
    float4  j = tex2D(Two, IN.TwoTexture);
    float4  k = tex2D(Three, IN.ThreeTexture);
    
    // combine texel colors
    b = (a.r * i)   + ((1 - a.r) * b);
    b = (a.g * j) + ((1 - a.g) * b);
    b = (a.b * k)  + ((1 - a.b) * b);
    b = b *(saturate(max(0.0f,dot(IN.Norm,IN.Light)) + 0.3f));
       
    output.tex = b;   
    
    return output; 
}




Technique

// Effect technique to be used
technique Terrain
{
    pass P0
    {
        // shaders
        VertexShader = compile vs_1_1 VS();
        PixelShader = compile ps_2_0 PS();
		//fillmode = wireframe;
        sampler[0] = (Base);             
    } 
}




PICTURE I dont have an stuff like SetTexture as its all done in the effect file. If anyone can see my mistake i would be in debt to them. Thanks C. [Edited by - colinolivant on December 1, 2007 11:38:28 AM]
Advertisement
I can`t see any problem. blending is done right. try to view only alpha texture if thats correct. btw why you have so many tex coords? one should be enough
also take a look at smoothstep intrinsic function, it will make your code more readable. I don`t understand why you set registers manually. is it better in any way?
Make sure your texture coords that your passing in to the shader are right too

This topic is closed to new replies.

Advertisement