//Vertex input data
struct vertexInput {
float4 position : POSITION;
float3 normal : NORMAL;
float4 texCoordDiffuse : TEXCOORD0;
};
//Vertex output data
struct vertexOutput {
float4 hPosition : POSITION;
float4 objPos : TEXCOORD0; //Object-space position
float4 texCoordDiffuse : TEXCOORD1;
float3 normal : TEXCOORD2;
};
//Vertex Program
vertexOutput main_vp(vertexInput IN, uniform float4x4 worldViewProj)
{
vertexOutput OUT;
OUT.hPosition = mul(worldViewProj, IN.position);
OUT.objPos= IN.position; //Keep the object-space data
OUT.texCoordDiffuse = IN.texCoordDiffuse;
OUT.normal = IN.normal; //To be interpolated
return OUT;
}
//Fragment program
float4 main_fp( vertexOutput IN,
//parameters
uniform float timeBlend,
uniform float4 uvFactor, //To adjust the haltone texture
uniform float4 lightAmbient, //Ambient light for the halftone only!
uniform float3 lightPosition,
uniform sampler2D diffuseTex,
uniform sampler2D halftone): COLOR
{
//Lighting
float3 P = IN.objPos.xyz;
float3 N = normalize(IN.normal);
float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);
float4 diffuse = diffuseLight * tex2D(diffuseTex, IN.texCoordDiffuse.xy);
//End of lighting
float3 intensityConverter = {0.299, 0.587, 0.114};
float Y = dot(intensityConverter, diffuse.xyz + lightAmbient.xyz); //Intensity from YIQ color format
float H = tex2D(halftone, fmod(IN.texCoordDiffuse.xy*uvFactor.xy, 1.0)).x; //Get the halftone intensity
float4 halfToneCol= (H > 1-Y ) ? float4(1, 1, 1, 1) : float4(0, 0, 0, 1); //Threshold function
return float4(lerp(halfToneCol.rgb, diffuse.rgb, timeBlend), 1.0); //Interpolation between halftoned and phong shading.
}

本文引用地址:
http://www.cgchina.com/article/2007/0724/article_10965.html