woensdag 20 februari 2013

Lightmapped tinting

Dear readers,

Today I'd like to explain a technique we're using in our new game considering lighting. It involves using the lightmap to shade models like bullet impacts and characters. A lightmap is actually just another texture applied to a model in combination with the second texture coordinates. The lightmap is blended with the primary texture to obtain a model that is shaded without there being any (hardware) light in the scene. The reason this is done is because it is much faster to render than real-time lighting/shadows. The downside is that it is computed beforehand and so is static (i.e. not real-time). Below you see an example of a scene that uses a lightmap for shading and below that an example of what a lightmap texture looks like.

An example of a lightmapped scene, notice the shadows of the trees and hills.

An example of a lightmap texture. You can see the shadows of trees and buildings in this texture.

Now what we'd like is that when a character walks through the scene and walk into a shaded area, the character also becomes darker (because it's walking in the shade). To do this we cast a ray from the character onto the ground and get the second texture coordinate of the point on the ground. We then use this color on the character material and in this way it'll shade appropriately.

A character in light on the left and in shadow on the right.
This also works for other objects such as bullet holes, but care should be taken. As bullet holes share the same material, adjusting the color on that material changes the appearence of all bullet holes which is not what we want (as some are in light, others in shadow). Creating a separate material for each bullet hole is possible, but not desirable: it slows down rendering. Instead we create just two materials: one for in light, the other for in shadow and assign one of the two materials to the bullet hole depending on whether it is in light or shadow.
Bullet holes in light on the left and in shadow on the right.
-- Stijn

4 opmerkingen:

  1. Hello! I know this is kind of off-topic however I needed to ask.
    Does running a well-established blog like yours take a massive amount work?
    I am completely new to writing a blog however I do write in my journal everyday.
    I'd like to start a blog so I can easily share my own experience and views online. Please let me know if you have any ideas or tips for new aspiring bloggers. Appreciate it!

    Also visit my website :: ├╝bersetzung latein deutsch leo

  2. Great items from you, man. I have remember your stuff prior to and you are simply too excellent.
    I really like what you've received here, really like what you're
    saying and the way in which in which you are
    saying it. You're making it entertaining and you still take care of to stay it wise. I can't wait to learn much more
    from you. This is really a wonderful web site.

    Also visit my weblog ... wasserdichter mp3 player zum schwimmen

  3. Hi there great blog! Does running a blog such as this
    require a lot of work? I have virtually no knowledge of computer programming but I
    had been hoping to start my own blog in the near future. Anyway, if you have any suggestions or techniques for new blog
    owners please share. I understand this is off subject nevertheless I
    simply had to ask. Thanks!

    my web blog: portable mp3 players