Jump to content

Creating light maps (and other stuff) based on 2nd UV channels

Recommended Posts

Recently @Tut and I were experimenting about lightmapping with a light map and a shader (Very different from vertex lighting) and i want to share our experience with that.
Initially we only wanted to make the 2nd UV channel work with objects but then i remembered about @Ren_712 lightmapped "Dust" map from counter strike and i wanted to re-create that effect.
I thought his instructions were a bit unclear, so i write it down here again. If an Admin reads this, please move this topic to User Guides, i think thats better than this scripting tutorial section.

This is the original resource of Ren: 

In 3ds max, first you need an object that you want to assign the 2nd UV map to. Doesnt matter what object.
-Create the "unwrap uvw" modifier
-Select "2" as Map Channel in the modifier
-In the following Dialog, "Move" or "Abandon" the UV coordinates of Channel 1 to the new Channel 2, you will most likely need to use "Flatten mapping" anyway
-Do whatever you need with the new UVs (Flatten mapping makes everything fit on 1 texture = no more "tiling")
-Create the lightmap with whatever tool (Radiosity?) that can render the light onto a grayscale lightmap image. This image will later produce light with our 2nd flattened UV map.
-Right click on the object and "Convert to -> Editable mesh", this collapses everything nicely and saves your changes.
-Finish your object and then export it with rwio or Kams max scripts.


This is the lightmap shader created by Ren, its nothing special and i simplified the code a little bit and i added some comments:


Now all you need to do is assign the lightmap shader to your object with the following simple code:

local lshader = dxCreateShader("light.fx")
if lshader then
	local lightTexture = dxCreateTexture("your_lightmap.png", "argb")
	if lightTexture then
		dxSetShaderValue(lshader, "lightTexture", lightTexture)
		engineApplyShaderToWorldTexture(lshader, "*", THE_TARGET_OBJECT_THAT_NEEDS_LIGHT)


  • Like 4
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...