HomeNewsFeaturesLicensingDownloadsScreenshotsFAQRoadmap Contact Us
Search:
9 Online

Community

Discussion Topics Recent Postings User Contributions General Articles Example Documentation Credits

Licensed Developer

Programmer's Manual Artists Manual Tutorials and Articles

Programming: Game Code

Game Code Overview Server Side Game Code Client Side Game Code

Programming: System

Alphabetical Function List Renderer File System Collision & Ray Casting Low Level Audio Game Audio The Console Console Variable List Multiplayer Localisation Maths Library Memory Manager Model File Formats Texture Formats

Art: Overviews

Specifications Shaders Particle Systems Lens Flares Cipher console Cipher file types Tutorials Reference

Art: Tools

Shader Designer Particle Designer 3dsmax tools Model Conversion Font Generator

Cipher Engine
Game Development Search Engine
GameDev.net
You are not signed in - [sign in] [register]

Lightmaps

Submitted by: rikh
Date Submitted: 2003-11-19 10:55:27

Shader Script

textures/normal_lightmap
{
    {
        tex map textures/plaster
        rgbsrc vertex
    }
    {
        tex map textures/bloom
        blendfunc lightmap
    }
}


textures/overbright_lightmap
{
    {
        tex map textures/plaster
        rgbsrc vertex
    }
    {
        tex map textures/bloom
        blendfunc gl_dst_color gl_src_color
    }
}


Screenshot

Lightmaps

Description

Here are a couple of examples of using lightmaps with Cipher's shader system.
The first is a regular lightmap shader. It specifies the wall texture to use. The rgbsrc command is also important, as it gets Cipher to use the vertex colours in the geometry instead of using normal lighting. Since the lighting will be coming from the Lightmap, we don't want any other lighting getting mixed in, or everything will end up very dark. If you aren't using the vertex colours for anything special in your models, then you could just as well replace this command with a "rgbsrc white".
The second pass blends in the lightmap texture with the wall texture. The lightmap in the example has a bit of colour in it as well to show that this method will work well for coloured lights. The blendfunc command tells Cipher how to mix this texture with the previous pass. The lightmap mode uses a standard modulate effect.

The second shader demonstrates a slightly more interesting lightmap method. The main problem with normal lightmaps is that they can only make things darker and never brighter. A white texel in the lightmap leaves the base texture unchanged, while a black texel in the lightmap results in a black pixel on the screen. In other words, the lighting can go from black to the base textures colour.
If we want to allow the lightmap to take the result from black to white, with the base texture colour somewhere in the middle, then we have to use a different blending mode.
If you look at the second shader, you will see that it is the same as the first one, apart from the lightmap blend function. This function performs the following operation...

SrcColour * DstColour + DstColour * SrcColour

This is really just 2* the normal lightmap function, which results in things getting saturated to white. In a regular lightmap white texels leave the base texture unmodified. In this example mid grey (128,128,128) leaves the base texture unmodified. Anything darker than mid grey will darken the base texture and anything brighter than mid grey will brighten the base texture.

[Recent Contributions] [Recent Shaders]

User Contributed Comments

tobyallen 15th December, 2003 12:39
If you want to go a little further and add some movement to your lightmap, simply create a text frame pass and use the lightmap textures as the frames, this can achieve various effects such as blinking lights and such.

Toby.




Register and Sign In to discuss this article