Phone Shader

//UI interface
float4 AmbientColor : Ambient
<
  string UIName = "Ambient";
> = (0.25f,0.25f,0.25f,0.1f);

float4 DiffuseColor : Diffuse
<
  string UIName = "Diffuse";
> = (0.25f,0.25f,0.25f,0.1f);

texture diffuseMap : DiffuseMap
<
   string name = "defaut";
   string UIName = "Diffuse Textrue";
   string TextureType = "2D";
>;
texture normalMap : NormalMap
<
    string name = "default_bump_normal.dds";
 string UIName = "Normal Map";
    string TextureType = "2D";
>;


float4 light1Pos : POSITION
<
 string UIName = "Light Position";
 string Object = "PointLight";
 string Space = "World";
 int refID = 0;
> = {100.0f, 100.0f, 100.0f, 0.0f};

float4 light1Color : LIGHTCOLOR
<
 int LightRef = 0;
> = { 1.0f, 1.0f, 1.0f, 0.0f };

/****************************************************/
/********** SAMPLERS ********************************/
/****************************************************/

sampler2D diffuseMapSampler = sampler_state
{
 Texture = <diffuseMap>;
 MinFilter = Linear;
 MagFilter = Linear;
 MipFilter = Anisotropic;
 ADDRESSU = WRAP;
    ADDRESSV = WRAP;
};

sampler2D normalMapSampler = sampler_state
{
 Texture = <normalMap>;
 MinFilter = Linear;
 MagFilter = Linear;
 MipFilter = Anisotropic;
 ADDRESSU = WRAP;
    ADDRESSV = WRAP;
};

float4x4 WorldViewProj : WorldViewProjection< string UIWidget = "None"; >;
float4x4 World      :   WORLD< string UIWidget = "None"; >;


struct VS_out
{
 float4 oposition : POSITION;
 float3 onormal : NORMAL;
 float2 otexcoord : TEXCOORD0;
 float4 diffuse     : COLOR;
};

struct VS_IN
{
 float4 position : POSITION;
 float3 texcoord : TEXCOORD0;
 float3 normal :NORMAL;
 float2 Norm : NORMAL;
};

/**************************************/
/***** VERTEX SHADER ******************/
/**************************************/

VS_out mainVS(VS_IN Input)
{
 VS_out Output =(VS_out)0;
 
 Output.oposition = mul(Input.position, WorldViewProj);// transform vert position to homogeneous clip space
 Output.otexcoord = Input.texcoord;
 
    float3 worldSpacePos = mul(Input.position, World);
 float3 L = normalize(light1Pos - worldSpacePos);
 float3 N = normalize(Input.normal);
 float diffuseLight = max(dot(N,L),0);
 
 Output.diffuse = diffuseLight;
 return Output; 
}

/**************************************/
/***** PIXEL SHADER *******************/
/**************************************/

float4 mainPS(VS_out PS_Input) : COLOR
{
 float4 ColorTexture = tex2D(diffuseMapSampler,PS_Input.otexcoord);
 float4 diffuse = PS_Input.diffuse*ColorTexture*DiffuseColor*light1Color;
 return  AmbientColor+diffuse;
}

technique technique0
{
 pass p0
 {
  ZEnable = true;
     ZWriteEnable = true;
      CullMode = cw;
     AlphaBlendEnable = false;
  VertexShader = compile vs_3_0 mainVS();
  PixelShader = compile ps_3_0 mainPS();
 }
}

posted @ 2011-07-06 11:30  softimagewht  阅读(369)  评论(0编辑  收藏  举报