Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What is ramp shading or lighting and how does it work? Is it different than toon shading or is it the same concept? How is specularity calculated differently for ramp shading versus blinn-phong or lambert?

share|improve this question

1 Answer 1

up vote 13 down vote accepted

In traditional Blinn/Phong shading, you calculate the diffuse term for a pixel by measuring the cosine of the angle between the normal at the surface and the direction of the light. So, in this case, a simple shader would look something like this:

float DiffuseCoeff(in float3 pos, in float3 normal, in float3 lightPos) {
    float3 lightDir = lightPos - pos;
    lightDir.normalize();

    return max(0.0, Dot(lightDir, normal));
}

In ramp shading, the idea is to modulate the diffuse coefficient by a 1D lookup texture. Depending on what you put in this texture you can generate different effects. Hence, our shader function to compute the diffuse coefficient becomes:

texture1D rampTex;
float DiffuseCoeff(in float3 pos, in float3 normal, in float3 lightPos) {
    float3 lightDir = lightPos - pos;
    lightDir.normalize();

    // Map value from [-1, 1] to [0, 1]
    float rampCoord = Dot(lightDir, normal) * 0.5 + 0.5;
    return tex1D(rampTex, rampCoord);
}

For example, if we wanted to implement a cell shader, what we could do is generate a ramp texture that emulates a step function:

enter image description here

You can use the same idea to generate different effects for the specular lighting as well. "Ramp" shading really only refers to the idea of modulating a shading value by a texture.

EDIT: Team Fortress 2 uses a ramp shader in their rendering. You can check out the details in this paper:

http://www.valvesoftware.com/publications/2007/NPAR07_IllustrativeRenderingInTeamFortress2.pdf

Look under Section 5, at the subsection entitled "Diffuse Warping Function"

share|improve this answer
1  
Great answer! The explanation of the difference for lighting between diffuse and ramp lighting is exactlywhat I was looking for. I also appreciate the comment about what the concept of ramp shading is in general. As an extra aside, could you possibly post an example image from a game that uses this concept? –  Stampyturtle Mar 15 '13 at 11:45
    
@Stampyturtle I've updated my answer with an example. –  Mokosha Mar 15 '13 at 15:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.