Welcome to CMM

The CMM forum software was recently upgraded, some things may have changed and some things may be broken or not working. Please let me know by PM or on IRC if you have any problems using this forum.

Also, I've removed the skybox and shader links for now, the shader generator page was being abused and as we're moving towards a ue4 mapping base, they're redundant.

Normal/bump mapping a shadow baked model

Having a problem with a shader or texture
User avatar
Rayne
Site Admin
Posts: 624
Joined: Wed Aug 17, 2011 5:22 pm

Normal/bump mapping a shadow baked model

Postby Rayne » Sat Feb 23, 2013 7:21 am

Right now in UrT HD there are 3 ways of lighting up a model.
- lightmapping
- vertex lighting
- shadow baking

Each has up and downsides. Upside of lightmaping is that you can apply normal/bumo maps, finer shadows and so on.
However lightmapping regularly fails on curves and small details.
That's when we use vertex lighting that prefers curves to flat surfaces.
Downside to vertex lighting is that you can' bump or normal map a model if it's vertex lit.
Well you can but the results are uncontrollable.
But what when vertex lighting fails, and it can fail and break.

Shadowbaking offers a quick and easy solution. Build a model, unwrap it, set up some lights in max/blender and then render the shadows into a single image you can later on edit and apply to your diffuse map.
fairly simple process once you get a hang of it and you get much better looking shadows.

Downside is, you have to write a shader that will completely eliminate lightmaps.
Since you're using your own baked lightmap the one generated by the compiled is just getting in the way.
So what if you really want to apply a normal/bump map to your model, you can't cause there is no lightmap.
And if there is no lightmap then a normal map is useless, it doesn't do anything.

Recently i made a crappy looking model of a bathtub. Probably cause of my poor way of building vertex lighting broke and the shadows looked horrible.
So the only thing i could do is shadow bake it. So i did.
But i really wanted to apply a normal map to it. It doesn't really needs it, i just have this normal map fetish.

So i had to figure out a way to lightmap this model but remove lightmaps entirely in the same time.

The solution is very simple. Just one line in the shader i overlooked for a long time.
q3map_lightmapbrightness

This line can turn up the brightness of a lightmap. cause of the way lightmaps are blended onto a surface if a lightmap is white, it wont show.
But it exists.

Shader is very simple and gets the job done.

Code: Select all

textures/uthd_lilimarleen/bathtub
 {
   q3map_forcemeta
   q3map_lightmapbrightness 2000
   {
   map textures/uthd_lilimarleen/bathtub
   blendfunc gl_one gl_zero
   }
   {
   map $lightmap
   RgbGen identity
   }
}


If you get black polygons this shader wont work on them. Simple math, RGB value for black is 0 0 0. Zero multiplied with any given number returns a zero.
So to fix this all i had to do is add _minlight 5 to the world spawn.
Minlight is something mappers avoid, but a value this low wont affect the map in any way, but it will remove all pitch black lightmaps and up their RGB value enough for this shader to work.
So there it is, shadow baked and lightmapped in the same time.
I used the shadow image from shadow baking and added it to the alpha channel, just to tone down it;s effect a little in the shadows.
Alpha is intentionally brighter than it should be so the effect is easier to spot.
Image

Here's another quick test, everything seems to work fine.
Image

User avatar
johnnyenglish
Space cake
Posts: 895
Joined: Wed Aug 17, 2011 9:23 am
Location: Nottingham, England

Re: Normal/bump mapping a shadow baked model

Postby johnnyenglish » Sat Feb 23, 2013 7:39 am

Erm, wow - been struggling with this for a long time - nice solution.

The shadow on the drinking fountain spouts is perfect m8, will be trying this out later.

User avatar
Rayne
Site Admin
Posts: 624
Joined: Wed Aug 17, 2011 5:22 pm

Re: Normal/bump mapping a shadow baked model

Postby Rayne » Sat Feb 23, 2013 7:43 am

johnnyenglish wrote:Erm, wow - been struggling with this for a long time - nice solution.

The shadow on the drinking fountain spouts is perfect m8, will be trying this out later.

I've been struggling with this for a year. Lack of full control over lightmaps per surface is really annoying, if you could only force the blend mode to add a lightmap would become invisible.
But since you can't, i had to figure out another solution, and as it turns out it's simpler than i imagined.
This just show how important it is to read the shader manual without skipping some parts.


Return to “Shaders / textures”

Who is online

Users browsing this forum: No registered users and 1 guest

cron