/* Cel shading vertex program for single-pass rendering In this program, we want to calculate the diffuse and specular ramp components, and the edge factor (for doing simple outlining) For the outlining to look good, we need a pretty well curved model. */ void main_vp(float4 position : POSITION, float3 normal : NORMAL, float2 tex : TEXCOORD0, out float4 oPosition : POSITION, out float2 otex : TEXCOORD0, out float diffuse : TEXCOORD1, out float specular : TEXCOORD2, out float edge : TEXCOORD3, uniform float3 lightPosition, // object space uniform float3 eyePosition, // object space uniform float4 shininess, uniform float4x4 worldViewProjection) { // calculate output position oPosition = mul(worldViewProjection, position); otex = tex; // calculate light vector float3 N = normalize(normal); float3 L0 = normalize(lightPosition); // Calculate specular component float3 E = normalize(eyePosition - position.xyz); // Calculate diffuse component diffuse = saturate(dot(L0, N)); specular = pow(saturate(dot(N, normalize(L0 + E))), shininess); // Mask off specular if diffuse is 0 if (diffuse == 0) specular = 0; // Edge detection, dot eye and normal vectors edge = max(dot(N, E), 0); } void main_fp(float2 texIn : TEXCOORD0, float diffuseIn : TEXCOORD1, float specularIn : TEXCOORD2, float edgeIn : TEXCOORD3, out float4 colour : COLOR, uniform float4 diffuseColor, uniform float4 specularColor, uniform float4 lightDiffuseColor, uniform float4 lightSpecularColor, uniform sampler2D ColorMapSampler : register(s0), uniform sampler1D diffuseRamp : register(s1), uniform sampler1D specularRamp : register(s2), uniform sampler1D edgeRamp : register(s3)) { // Step functions from textures float diffuse = tex1D(diffuseRamp, diffuseIn).x; float specular = tex1D(specularRamp, specularIn).x; float edge = tex1D(edgeRamp, edgeIn).x; float4 texCol = tex2D(ColorMapSampler, texIn); colour = edge * ((((diffuse * lightDiffuseColor) * diffuseColor) * texCol) + (((specular * lightSpecularColor) * specularColor)) * texCol); }