## "Everyone" likes cartoon-like worlds?

Gish and Alien Hominid

Visit http://www.theDailyGrind.net for your recommended daily intake of embittered satire.

reubert Wrote:That link is a great hack for it's time... as soon as we have GLSL there will be far more options for cartoony graphics available to us.Meh, low level is the way to go! Here's a quick shader I threw together that utilizes vertex and pixel shaders to do cel shading (without textures, either!).

Vertex portion:

Code:

`!!ARBvp1.0`

OPTION ARB_position_invariant;

TEMP color;

TEMP normal;

TEMP NdotL, NdotH, lightDirection, halfVector, length, tempPosition;

ATTRIB vertexNormal = vertex.normal;

PARAM ambient = state.lightmodel.ambient;

PARAM modelview[4] = {state.matrix.modelview};

PARAM projection[4] = {state.matrix.projection};

PARAM mvInvtrans[4] = {state.matrix.modelview.invtrans};

TEMP position;

MOV color, {0.75, 0.75, 0.5, 1.0};

#transform the position to

DP4 position.x, vertex.position, modelview[0];

DP4 position.y, vertex.position, modelview[1];

DP4 position.z, vertex.position, modelview[2];

DP4 position.w, vertex.position, modelview[3];

MOV tempPosition, position;

DP3 length, tempPosition, tempPosition;

RSQ length, length.x;

MUL tempPosition, tempPosition, length;

#transform the normal

DP3 normal.x, mvInvtrans[0], vertexNormal;

DP3 normal.y, mvInvtrans[1], vertexNormal;

DP3 normal.z, mvInvtrans[2], vertexNormal;

DP3 length, normal, normal;

RSQ length, length.x;

MUL normal, normal, length;

MOV lightDirection, state.light[0].position;

#normalize

DP3 length, lightDirection, lightDirection;

RSQ length, length.x;

MUL lightDirection, lightDirection, length;

MOV halfVector, state.light[0].half;

DP3 length, halfVector, halfVector;

RSQ length, length.x;

MUL halfVector, halfVector, length;

DP3 NdotL, normal, lightDirection;

DP3 NdotH, normal, halfVector;

MOV result.color, color;

MAX result.texcoord[7].x, NdotL, {0};

MAX result.texcoord[7].y, NdotH, {0};

END

Fragment portion:

Code:

`!!ARBfp1.0`

TEMP NdotL, NdotH, color, tempColor;

TEMP intensity, multiplier;

MOV NdotL, fragment.texcoord[7].x;

MOV NdotH, fragment.texcoord[7].y;

MOV color, fragment.color;

MOV NdotL.w, 1.0;

MUL color, state.light[0].diffuse, fragment.color;

MUL color, color, NdotL;

DP3 intensity, color, color;

POW intensity, intensity.x, 0.5;

MOV intensity.w, 1.0;

RCP multiplier, intensity.x;

MUL multiplier, multiplier.x, 0.4;

ADD multiplier, multiplier, 3;

MUL intensity, intensity, multiplier;

FLR intensity, intensity;

MUL intensity, intensity, 0.33;

MUL color, color, intensity;

MUL tempColor, state.lightmodel.ambient, fragment.color;

ADD color, color, tempColor;

MOV result.color, color;

END