Advertisement

Lightmaps and per pixel lighting

Started by December 13, 2004 01:33 PM
11 comments, last by lc_overlord 19 years, 11 months ago
i've seen something similar in Half Life 2 and Doom 3. Basically, how is possible to light a surface with a lightmap on it? Let me explain it better. Imagine a quad with a texture and a lightmap on it. What i want to do (for example) is to simulate the effect of a flashlight (or any other kind of light) in a way that i can enlight also the dark zones of the quad under the lightmap. How can this be done?
For starters, HL2 and D3 use totally different lighting models. Doom 3 uses totally dynamic direct lighting, HL2 uses Radiosity Normal Mapping ( see ATI dev site for a paper ) - which isn't as dynamic but copes with indirect lighting. For a flashlight, you can either consider it a spot light, or just use a projected texture ( HL1 just used a projected texture for instance - I have no idea what HL2 uses, haven't played it ).
If at first you don't succeed, redefine success.
Advertisement
simple, use a multipass system.

1. Render all the geometry with textures and lightmaps(you could even add some specular lighting).
2. Copy the screen to the accum buffer.
3. Render the geometry(you only need to render the affected geometry) with the flashlight effect(where everything no lit with the flashlight is totaly black).
4. Add the screen to the accum buffer once again.

Lastly display the accum buffer.

I have to add that if you want to do some fragment programing it could all be done in one fragment program.

BTW: HL2 is a 2nd gen FPS game engine and uses pretty mutch the same lighting system as the original HL.
But it definitly is enhanced to perfection.
Doom3 on the other hand, together with unreal engine 3 are third generation game engines, and uses a different, more accurate method/theory for lighting/shadows.
@lc_overlord :
tell me the fragment stuff :D
You don't have to use the accum buffer. You could just project a dynamic lightmap.
If at first you don't succeed, redefine success.
Shure, but that's like ancient quake1 technology.
Using the accum buffer(or your own render to texture thingy) you could reach a mutch higher level of visual perfection.

one option is to do it all in a fragment program.
what you do is that you modulate the texture with the lightmap,
then you modulate the texture with the projected flashlight texture,
if you want specular highlights with bumpmaps it is time to do them now,
Finaly you add them all together and return the resulting color.

@B3rs3rk:
try this link http://www.clockworkcoders.com/oglsl/tutorials.html
Advertisement
thank you ^__^ i'll try to write a shader and i'll post my results :)
Ahhh, I thought you actually meant using the accumulation buffer, which isn't hardware support on consumer level hardware, and is just bloody slow. Personally I'd just consider the flashlight as another general spot light, and treat it as such.

Also, I wouldn't say the Doom 3 engine has a more accurate method of calculating shadows, quite the opposite actually, as it only accounts for direct illumination. The only advantage is that they are totally dynamic, where as HL2's GI solution lightmaps are static.
If at first you don't succeed, redefine success.
The doom3 soulution is better, it deals with light and shadows in a better way.
Allthough it doesn't have radiosity yet(allthough it can have static radiosity if you want it to), it's not far off.
There are allready some realtime radiosity effects in the works (even i am working on one) and it won't be long before there is some hardware that actuarly can render this in realtime.

Shure one could argue that compared to HL2 and farcry doom3 is slow, looks a bit wonky at some aspects and all that, but HL2 and farcry are at the absolute maximum of what second generation rendering methods can acheve.
Doom3 and the third generation FPS engines are only in it's infancy, expect more glory and ownage in the near future.

O, and about the accum buffer.
It works well on my card and it's pretty easy to use, so i am currently using it in my engine.
I do have a backup system in place, but it stalls the GPU to mutch.
So im currently working with p-buffers to solve this problem(+ add HDR rendering).
no way :/ i wrote a Cg shader that modulates the decal texture with the lightmap and applies parallax mapping, but i don't get what i want -__-
this is the shader's source:
float4 main(    const sampler2D  in uniform texture   : TEXTURE0,    const sampler2D  in uniform normalMap : TEXTURE1,    const sampler2D  in uniform HeightMap : TEXTURE2,    const sampler2D  in uniform LightMap : TEXTURE3,    const PIN        in         pin) : COLOR0 {      const float3 light = normalize(pin.light);      const float3 eye   = normalize(pin.eye);      float  bump   = tex2D(HeightMap, pin.texCoord).x;      float2 offsetCoord = pin.texCoord + (bump * 0.03 - 0.015) * float2(-eye.y, eye.x);      const float4 surfColor = tex2D(texture,offsetCoord);      const float4 LightMapColor = tex2D(LightMap, pin.texCoord);      float4 ResultColor = (surfColor * LightMapColor);      float3 normal = tex2D(normalMap,  offsetCoord).xyz * 2.0 - 1.0;      normal = normalize(normal);      const float3 lightColor = pin.diffuse_light;       const float3 ambient = pin.ambient_light ;       float3 diffuse = lightColor * max(dot(normal, light), 0);      return float4((diffuse + ambient ) * ResultColor.xyz ,ResultColor.w);      }


how should i do?

This topic is closed to new replies.

Advertisement