/* 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, // outputs out float4 oPosition : POSITION, out float2 otex : TEXCOORD0, out float diffuse0 : TEXCOORD1, out float specular0 : TEXCOORD2, out float edge : TEXCOORD7, // parameters uniform float3 lightPosition_0, // 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_0); // Calculate specular component float3 E = normalize(eyePosition - position.xyz); // Calculate diffuse component diffuse0 = saturate(dot(L0, N)); float3 Half0 = normalize(L0 + E); specular0 = pow(saturate(dot(N, Half0)), shininess); // Mask off specular if diffuse is 0 if (diffuse0 == 0) specular0 = 0; // Edge detection, dot eye and normal vectors edge = max(dot(N, E), 0); } void main_fp( float2 texIn : TEXCOORD0, float diffuse0In : TEXCOORD1, float specular0In : TEXCOORD2, float edge : TEXCOORD7, out float4 colour : COLOR, uniform float4 diffuseColor, uniform float4 specularColor, //uniform float4 ambientColor, //uniform float ambientIntensity, uniform float4 LightDiffuseColor0, uniform float4 LightSpecularColor0, uniform sampler2D ColorMapSampler : register(s0), uniform sampler1D diffuseRamp : register(s1), uniform sampler1D specularRamp : register(s2), uniform sampler1D edgeRamp : register(s3)) { //ambientColor *= ambientIntensity; float diff0; float spec0; float4 total = (float4)(0, 0, 0, 0); float4 texCol = tex2D(ColorMapSampler,texIn); // * ambientColor; // Step functions from textures diff0 = tex1D(diffuseRamp, diffuse0In).x; spec0 = tex1D(specularRamp, specular0In).x; edge = tex1D(edgeRamp, edge).x; colour = edge * ((((diff0 * LightDiffuseColor0) * diffuseColor) * texCol) + (((spec0 * LightSpecularColor0) * specularColor)) * texCol); }