Lucka, but not Lucky..
The "final" version is now:
////////////////////////////////
// PS 2.0 Texture Blend Shader//
// //
// By Carlos(Darkcoder)Wilkes //
// Darkcoder.co.uk //
////////////////////////////////
//////////////////////////////
// Engine Matrices //
//////////////////////////////
matrix WorldViewProjection : WorldViewProjection;
matrix World : World;
//////////////////////////////
// Shader Constants //
//////////////////////////////
float3 Normal;
float3 LightDir;
float3 LightPos;
//////////////////////////////
// Shader Textures //
//////////////////////////////
float Luminanza = 20.0f;
texture LayerMap1TX <string ResourceName = "" ;>;
sampler2D LayerMap1Sampler = sampler_state
{
texture = <LayerMap1TX>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
texture LayerMap2TX <string ResourceName = "" ;>;
sampler2D LayerMap2Sampler = sampler_state
{
texture = <LayerMap2TX>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
texture BaseTX <string ResourceName = "" ;>;
sampler2D BaseSampler = sampler_state
{
texture = <BaseTX>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
texture Layer1TX <string ResourceName = "" ;>;
sampler2D Layer1Sampler = sampler_state
{
texture = <Layer1TX>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
texture Layer2TX <string ResourceName = "" ;>;
sampler2D Layer2Sampler = sampler_state
{
texture = <Layer2TX>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
texture Layer3TX <string ResourceName = "" ;>;
sampler2D Layer3Sampler = sampler_state
{
texture = <Layer3TX>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
texture Layer4TX <string ResourceName = "" ;>;
sampler2D Layer4Sampler = sampler_state
{
texture = <Layer4TX>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
texture Layer5TX <string ResourceName = "" ;>;
sampler2D Layer5Sampler = sampler_state
{
texture = <Layer5TX>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
//////////////////////////////
// Structs //
//////////////////////////////
struct TextureBlend_Input
{
float4 Position : POSITION;
float2 UV0 : TEXCOORD0;
float2 UV1 : TEXCOORD1;
float Diffuse : COLOR;
};
struct TextureBlend_Output
{
float4 Position : POSITION;
float2 UV0 : TEXCOORD0;
float2 UV1 : TEXCOORD1;
float Diffuse : COLOR;
};
//////////////////////////////
// Vertex Shaders //
//////////////////////////////
TextureBlend_Output VS_TextureBlend(TextureBlend_Input IN)
{
TextureBlend_Output OUT;
OUT.Position = mul( IN.Position, WorldViewProjection );
OUT.UV0 = IN.UV0;
OUT.UV1 = IN.UV1;
float3 Normal = mul( IN.Normal, World ); // Transform normal to world space
float3 LightDir= normalize( LightPos - mul( IN.Position, World ) ); // Find the light direction vector
OUT.Diffuse = dot( Normal, LightDir ); // Calc lighting
return OUT;
}
//////////////////////////////
// Pixel Shaders //
//////////////////////////////
float4 PS_TextureBlend(TextureBlend_Output IN) : COLOR
{
float3 LayerMap1Map = tex2D( LayerMap1Sampler ,IN.UV0 ); // *NOTE* The first 2 textures are used to sample the opacity, for each of the 5
float3 LayerMap2Map = tex2D( LayerMap2Sampler ,IN.UV0 ); // additional texture stages, much like the vertex blend uses vertex UV data.
float4 BaseMap = tex2D( BaseSampler ,IN.UV1 );
float3 Layer1Map = tex2D( Layer1Sampler ,IN.UV1 );
float3 Layer2Map = tex2D( Layer2Sampler ,IN.UV1 );
float3 Layer3Map = tex2D( Layer3Sampler ,IN.UV1 );
float3 Layer4Map = tex2D( Layer4Sampler ,IN.UV1 );
float3 Layer5Map = tex2D( Layer5Sampler ,IN.UV1 );
BaseMap.rgb = lerp( BaseMap.rgb, Layer1Map, LayerMap1Map.r ); // *NOTE* As with the vertex blend shader you don't need to use Lerp, you can
BaseMap.rgb = lerp( BaseMap.rgb, Layer2Map, LayerMap1Map.g ); // use a texture lookup blend quite easily, especially since the
BaseMap.rgb = lerp( BaseMap.rgb, Layer3Map, LayerMap1Map.b ); // Layer2Map has both the G and A channels free.
BaseMap.rgb = lerp( BaseMap.rgb, Layer4Map, LayerMap2Map.r );
BaseMap.rgb = lerp( BaseMap.rgb, Layer5Map, LayerMap2Map.g );
BaseMap.rgb *= IN.Diffuse / 100 * Luminanza; // Multiply colour by diffuse to get shading!
return BaseMap;
}
//////////////////////////////
// Techniques //
//////////////////////////////
technique TextureBlend
{
pass p0
{
vertexShader = compile vs_1_1 VS_TextureBlend();
pixelShader = compile ps_2_0 PS_TextureBlend();
}
}
There must be all the necessary.. but still not running properly, the object disappears.
Did you try it out?
Gardening? not a bad idea!
Lucka - gawteam coder - www.gawgames.com
