This is an archive of my old blog (2008–2013), kept online because people still use it. XNA has been discontinued; MonoGame is its open-source successor, and the techniques still apply. Comments are closed.

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

RimLight4

13 comments on “Rim Lighting”

  1. 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 ;)

  2. 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.

  3. 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.

  4. Matrix[] bones;
    bones = new Matrix[level.Bones.Count];
    level.CopyBoneTransformsTo(bones);

    foreach (ModelMesh mesh in level.Meshes)
    {
    foreach (Effect effects in mesh.Effects)
    { effects.Parameters["World"].SetValue(bones[mesh.ParentBone.Index]);
    effects.Parameters["View"].SetValue(view);
    effects.Parameters["ViewI"].SetValue(Matrix.Invert(view));
    effects.Parameters["Projection"].SetValue(Projection);

    //customize the effect
    effects.Parameters["Rim_Start"].SetValue(0.4f);
    effects.Parameters["Rim_End"].SetValue(1.0f);
    effects.Parameters["Rim_Multiplier"].SetValue(0.9f);
    effects.Parameters["Rim_Color"].SetValue(Color.White.ToVector4());

    //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 ||
    ///////////////////////////////////////////////////////////////////////////
    }
    mesh.Draw();
    }

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

  6. 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.

  7. 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
    Regards

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

  9. 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 ...