/* 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 uv : TEXCOORD0, // outputs out float4 oPosition : POSITION, out float2 oUv : TEXCOORD0, out float diffuse : TEXCOORD1, out float specular : TEXCOORD2, out float edge : TEXCOORD3, // parameters uniform float3 lightPosition, // object space uniform float3 eyePosition, // object space uniform float4 shininess, uniform float4x4 worldViewProj) { // calculate output position oPosition = mul(worldViewProj, position); oUv = uv; // calculate light vector float3 N = normalize(normal); float3 L = normalize(lightPosition - position.xyz); // Calculate diffuse component diffuse = max(dot(N, L) , 0); // Calculate specular component float3 E = normalize(eyePosition - position.xyz); float3 H = normalize(L + E); specular = pow(max(dot(N, H), 0), 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( float4 position : POSITION, float2 uvIn : TEXCOORD0, float diffuseIn : TEXCOORD1, float specularIn : TEXCOORD2, float edge : TEXCOORD3, out float4 colour : COLOR, uniform float4 diffuse, uniform float4 specular, uniform sampler2D diffuseMap, uniform sampler2D diffuseRamp, uniform sampler2D specularRamp, uniform sampler2D edgeRamp) { // Step functions from textures float4 diffTex = tex2D(diffuseMap, uvIn); diffuseIn = tex2D(diffuseRamp, float2(diffuseIn, 0.0)).x; specularIn = tex2D(specularRamp, float2(specularIn, 0.0)).x; edge = tex2D(edgeRamp, float2(edge, 0.0)).x; colour = diffTex * edge * ((diffuse * diffuseIn) + (specular * specularIn)); //colour = float4(1,0,0,1); }