Rim Lighting

This time, we have a smaller sample. This sample shows the implementation of a “rim lighting” shader, customizable by a series of parameters.

I observed this kind of effect in Super Mario Galaxy screenshots, and it looked like a nice effect, that could easily amplify the cuteness and eye-candy of a game. So here’s my implementation.

The looks of the effect may be customize by 4 parameter, Rim_Start, Rim_End, Rim_Multiply and Rim_Color. The source includes a small table with some experiments I did that yielded interesting results.

In the downloadable archive you will find a custom content processor for a Model, which changes the model’s effect to RimLight.fx, and copied the texture over to the new effect.

While running the sample, use [Space] or Gamepad [A] to switch between the dino model and a group of three colorful objects. Look at the source code, in the Draw function for some customization options.

You can download the source code here: rimlighttest.zip

RimLight6 RimLigh2

RimLight1 RimLight3


  • Pingback: Catalin Zima - XNA and HLSL blog » July Sample: Rim Lighting

  • Matt

    Looks great. Have a good vacation.

  • Sir Lantis

    Funny, looks like my shader. Wrote one 6 months ago (also SMG inspired) but archived it since I had problems creating a cool planet-model for tests.
    Will take a look at your shader now 😉

  • http://www.skull.co.nz/ nih

    The proper name for this is Fresnel Shading, and it’s very nice indeed. Tuned right it can make skin look real, cartoons look hand-drawn and metal look fantastic.

  • http://machinesdontcare.wordpress.com a|x

    It also does nice electron micrograph-like effects, if you set it so that you get just the rim-lighting.

    Very nice.

  • Pingback: More Velvetty GLSL « machines don’t care

  • Pingback: In arrivo l'espansione Gothic 3 "Forsaken Gods" - News, Commenti e Pareri! - Page 19 - Videogiochi Forum su Multiplayer.it

  • Mo

    hi im mo and i like this RimShader and when i tried to use it on my Game Environment it give me this Error “Object reference not set to an instance of an object.” and im using XNA 2.0 thnx for help.

  • http://www.catalinzima.com Catalin Zima

    I can’t help you without more information. When does this error get thrown, and on what line if code?

  • Mo

    Matrix[] bones;
    bones = new Matrix[level.Bones.Count];

    foreach (ModelMesh mesh in level.Meshes)
    foreach (Effect effects in mesh.Effects)
    { effects.Parameters[“World”].SetValue(bones[mesh.ParentBone.Index]);

    //customize the effect

    //Other Variants
    // Rim_Start || Rim_End || Rim_Multiplier || Rim_Color ||
    // 0.5f || 0.1f || 0.5f || PeachPuff ||
    // 0.4f || 1.0f || 1.6f || Red ||
    // 0.4f || 0.5f || -1.4f || White ||
    // 0.0f || 1.0f || 0.5f || Chocolate ||
    // 0.1f || 0.3f || 0.8f || SlateBlue ||

  • Mo

    “effects.Parameters[”ViewI”].SetValue(Matrix.Invert(view));” this is line of error

  • http://www.catalinzima.com Catalin Zima

    Your model probably doesn’t have the effect set on it. So when trying to access the ViewI parameters, which is a parameter of the RimLighting.fx effect, it cannot be found, so it returns a null.

    In my sample, I used a ContentProcessor to apply the effect on the models I want to use rim lighting on.

  • Mo

    you right i Found that But when i use the Model Without Texture just use colors, It gives me Gray Color so any Info. and thnx for help

  • http://www.catalinzima.com Catalin Zima

    The shader in the example doesn’t support untextured models.
    You would have to modify the shader, and possibly the ContentProcessor

  • Mo

    thnx 4 help but all what i need is to know how to make a simple light with shader support untextured models and also textured so if u know learning resource that will be great …

  • http://www.catalinzima.com Catalin Zima