Toon shader question
i have trouble by this question few days
i use a 32*1 texture,it contains four luminance
///////////////////////////////////////////////////
LPDIRECT3DTEXTURE9 g_pTexture = NULL;
if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, "Toon.bmp", &g_pTexture) ) )
{
if( FAILED(D3DXCreateTextureFromFile( g_pd3dDevice, "..\\Toon.bmp", &g_pTexture) ) )
{
MessageBox(NULL, "Could not find Toon.bmp", "tiger.bmp", MB_OK);
return E_FAIL;
}
}
///////////////////////////////////////////////////
then i set the effect
g_pEffect->SetTexture("Toon",g_pTexture);
in the fx files (the while below)
////////////////////////////////////////////////////
texture Toon;
//////////////
// Globals //
////////////
float4x4 gProjMat; // The projection matrix (Project geometery from 3D to 2D window)
float4x4 gViewMat; // The view matrix (Our current camera view of the world)
float4x4 gWorldMat; // The world matrix (Current world orientation of our object)
float4 view_position;
float4 lightDir;
struct VS_OUTPUT
{
float4 Pos : POSITION0;
float2 TexCoord : TEXCOORD0;
};
sampler ToonShaderTexture= sampler_state
{
Texture = (Toon);
};
/////////////////////////////
// Vertex Shaders //
/////////////////////////////
VS_OUTPUT vs_main(float3 inPos : POSITION0,float3 inNorm : NORMAL0)
{
VS_OUTPUT Out;
float4x4 worldViewProjMat = mul(mul(gWorldMat, gViewMat), gProjMat);
float4x4 WorldViewMat=mul(gWorldMat, gViewMat);
Out.Pos = mul(float4(inPos, 1), worldViewProjMat);
float3 normalW = mul((float3x3)WorldViewMat, inNorm);
// float3 normalW = mul((float3x3)gViewMat, inNorm);
// float3 normalW = mul((float3x3)gWorldMat, inNorm);
// float3 normalW = mul((float3x3)worldViewProjMat, inNorm);
float diffuse =max(0,dot(-lightDir,normalW));
Out.TexCoord.x = diffuse;
Out.TexCoord.y = 0.0f;
return Out;
}
////////////////////////////////////////////////////
struct PS_OUTPUT
{
float4 Color : COLOR0;
};
////////////////////////
// Pixel Shader //
////////////////////////
PS_OUTPUT ps_main( float2 TexCoord : TEXCOORD0)
{
PS_OUTPUT Out;
Out.Color = tex2D(ToonShaderTexture,TexCoord);
return Out;
}
///////////////////////
// Techniques //
///////////////////////
technique DiffuseColor
{
pass First
{
Lighting =FALSE; // We don't want to use vertex lighting
ZEnable = TRUE; // We want z-buffering enabled
VertexShader = compile vs_1_1 vs_main();
PixelShader = compile ps_1_1 ps_main();
}
}
///////////////////////////////////////////////////
when i only use vertexShader it works right
but i turn on the pixelshader it always render the mesh as black color
then i modify the HLSL to
Out.TexCoord.x = 0.5f;
Out.TexCoord.y = 0.5f;
discover whatever coordinate i specify,it doesn't
works but i copy this HLSL code to ATI rendermokey
it works right,
i am so puzzle about this mechanism,
please give me a satisfiable answer
thank every one very much~~

