POV-Ray : Newsgroups : povray.off-topic : Question about OpenGL and lightmaps Server Time
29 Jul 2024 18:27:16 EDT (-0400)
  Question about OpenGL and lightmaps (Message 1 to 9 of 9)  
From: Warp
Subject: Question about OpenGL and lightmaps
Date: 19 May 2011 19:43:59
Message: <4dd5ab3e@news.povray.org>
This might not be the best possible place to ask this, but at least it is
related to computer graphics (and there are lots of programmers here), and
I don't feel like subscribing to yet another random online forum.

  This is something I really should know, but I don't. And, more
surprisingly, I just can't find this info even though it should be
something that's trivial to find. It just doesn't seem to be. I was
wondering if someone with more experience on this subject could illuminate
me a bit.

  Light mapping is a common efficient method for lighting static scenes,
especially in older 3D games. I had always assumed that light maps could
both make the underlying texture darker *and* brighter (from complete black
to completely overexposed white where the lighting is the strongest, and
then of course an unmodified texture in between the two extremes).

  However, after searching info online about how to use light maps with
OpenGL, this possibility is actually not clear at all. There are tons and
tons of tutorials online (most of them dealing with how to *create* light
maps, which is not what I'm looking for rather than how to *use* them in
OpenGL). Whether the same light map can both make the underlying texture
darker and brighter (than the original texture) is inconclusive after my
extensive search. Some example images seem to indicate that it is possible,
but the details of *how* it's done are sketchy at best.

  When I tried to search information on how exactly do this with OpenGL,
I just can't find it. You can make the light map modulate (ie. multiply)
the underlying texture, which can only make the texture darker, or you
can make the light map add to the underlying texture, which can only make
the texture brighter, but I can't find the info of how to make it do both,
or whether it's actually possible at all.

  I am almost certain that in many games light maps do both. However,
trying to search for examples has also proven difficult. For example
screenshots of Quake 2 (which is a perfect example of a game using
light mapping) are inconclusive. It's difficult to say whether the
light maps are brightening the textures besides darkening them, or
whether they are only darkening them. I was pretty sure that they do
both, but I can't find conclusive screenshots demonstrating this.

  (One possibility could perhaps be layering *two* light maps on top
of the textures, one for darkening and another for brightening. However,
it seems that at least vanilla OpenGL does not easily support layering
more than two textures at a time.)

  Could someone more knowledgeable about the subject shed some light on it?
(Pun very much intended.)

-- 
                                                          - Warp


Post a reply to this message

From: Alain
Subject: Re: Question about OpenGL and lightmaps
Date: 19 May 2011 21:02:26
Message: <4dd5bda2$1@news.povray.org>

>    This might not be the best possible place to ask this, but at least it is
> related to computer graphics (and there are lots of programmers here), and
> I don't feel like subscribing to yet another random online forum.
>
>    This is something I really should know, but I don't. And, more
> surprisingly, I just can't find this info even though it should be
> something that's trivial to find. It just doesn't seem to be. I was
> wondering if someone with more experience on this subject could illuminate
> me a bit.
>
>    Light mapping is a common efficient method for lighting static scenes,
> especially in older 3D games. I had always assumed that light maps could
> both make the underlying texture darker *and* brighter (from complete black
> to completely overexposed white where the lighting is the strongest, and
> then of course an unmodified texture in between the two extremes).
>
>    However, after searching info online about how to use light maps with
> OpenGL, this possibility is actually not clear at all. There are tons and
> tons of tutorials online (most of them dealing with how to *create* light
> maps, which is not what I'm looking for rather than how to *use* them in
> OpenGL). Whether the same light map can both make the underlying texture
> darker and brighter (than the original texture) is inconclusive after my
> extensive search. Some example images seem to indicate that it is possible,
> but the details of *how* it's done are sketchy at best.
>
>    When I tried to search information on how exactly do this with OpenGL,
> I just can't find it. You can make the light map modulate (ie. multiply)
> the underlying texture, which can only make the texture darker, or you
> can make the light map add to the underlying texture, which can only make
> the texture brighter, but I can't find the info of how to make it do both,
> or whether it's actually possible at all.
>
>    I am almost certain that in many games light maps do both. However,
> trying to search for examples has also proven difficult. For example
> screenshots of Quake 2 (which is a perfect example of a game using
> light mapping) are inconclusive. It's difficult to say whether the
> light maps are brightening the textures besides darkening them, or
> whether they are only darkening them. I was pretty sure that they do
> both, but I can't find conclusive screenshots demonstrating this.
>
>    (One possibility could perhaps be layering *two* light maps on top
> of the textures, one for darkening and another for brightening. However,
> it seems that at least vanilla OpenGL does not easily support layering
> more than two textures at a time.)
>
>    Could someone more knowledgeable about the subject shed some light on it?
> (Pun very much intended.)
>

If you multiply with a map whose values go from 0 to 10, values under 1 
will darken, while values larger than 1 will brighten. It's just a 
question of applying some offset or stretching the range of your light map.

Same with addition, here, you need negative values to darken things.


Post a reply to this message

From: Slime
Subject: Re: Question about OpenGL and lightmaps
Date: 19 May 2011 23:02:24
Message: <4dd5d9c0@news.povray.org>
>    Light mapping is a common efficient method for lighting static 
scenes, especially in older 3D games. I had always assumed that light 
maps could both make the underlying texture darker *and* brighter (from 
complete black to completely overexposed white where the lighting is the 
strongest, and then of course an unmodified texture in between the two 
extremes).


If you write your own shader, you can simply take the light map texture, 
multiply it by the texture, and multiply the result by 2 or whatever 
constant you want, thus essentially scaling the brightness to any range. 
(You'll start to run into precision issues with high values if you're 
not using HDR textures, of course.)

You seem to know of a way to render two textures at once, multiplying 
them together. I wasn't aware of that feature, so I'm not sure if I'm 
just misunderstanding. If you do have a way to do that, you can simply 
use vertex colors of rgb(2,2,2), and make sure you have vertex color 
clamping turned off (with glClampColorARB I think). Even if you can't 
render the light map and the texture at the same time, this trick might 
still be useful for a different solution.

  - Slime


Post a reply to this message

From: stbenge
Subject: Re: Question about OpenGL and lightmaps
Date: 20 May 2011 13:24:32
Message: <4dd6a3d0$1@news.povray.org>
On 5/19/2011 4:43 PM, Warp wrote:
>    Could someone more knowledgeable about the subject shed some light on it?
> (Pun very much intended.)

I'm far from knowledgeable concerning OpenGL, but as Slime mentioned, a 
shader might be the way to go. I think with older pixel shaders (<2) you 
could blend textures in a few different ways (multiply, add, etc.). With 
current GLSL implementations you can write entire functions from scratch 
and do tons of other cool things.

Give GLSL a shot if you aren't worried about your program not working on 
older hardware~

Sam


Post a reply to this message

From: Warp
Subject: Re: Question about OpenGL and lightmaps
Date: 20 May 2011 17:37:32
Message: <4dd6df1c@news.povray.org>
Alain <aze### [at] qwertyorg> wrote:
> If you multiply with a map whose values go from 0 to 10, values under 1 
> will darken, while values larger than 1 will brighten. It's just a 
> question of applying some offset or stretching the range of your light map.

> Same with addition, here, you need negative values to darken things.

  This assumes that the lightmap texel components are floating point values.
It is completely unclear to me whether OpenGL and rendering hardware supports
floating point components in textures. There are some indications that at
least some don't. (You can give OpenGL a texture in floating point format,
but it will be internally converted to an 8-bits-per-component bitmap,
clamping all values to the range [0.0-1.0] and multiplying by 255.)

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: Question about OpenGL and lightmaps
Date: 20 May 2011 17:42:48
Message: <4dd6e058@news.povray.org>
stbenge <"egnebts <-inverted"@hotmail.com> wrote:
> I'm far from knowledgeable concerning OpenGL, but as Slime mentioned, a 
> shader might be the way to go.

  I was more interested in the traditional (pre-pixel-shaders) way of
doing light mapping.

-- 
                                                          - Warp


Post a reply to this message

From: stbenge
Subject: Re: Question about OpenGL and lightmaps
Date: 21 May 2011 01:12:44
Message: <4dd749cc@news.povray.org>
On 5/20/2011 2:37 PM, Warp wrote:
> Alain<aze### [at] qwertyorg>  wrote:
>> If you multiply with a map whose values go from 0 to 10, values under 1
>> will darken, while values larger than 1 will brighten. It's just a
>> question of applying some offset or stretching the range of your light map.
>
>> Same with addition, here, you need negative values to darken things.
>
>    This assumes that the lightmap texel components are floating point values.
> It is completely unclear to me whether OpenGL and rendering hardware supports
> floating point components in textures. There are some indications that at
> least some don't. (You can give OpenGL a texture in floating point format,
> but it will be internally converted to an 8-bits-per-component bitmap,
> clamping all values to the range [0.0-1.0] and multiplying by 255.)

If the GLGraphics library for Processing is any indication, then yes, 
OpenGL supports floats. But are they supported by hardware? It depends 
on your card.

I've got a 7600GS, and was rendering hi-ish res floating point precision 
continuous cellular automata at exceptionally high frame rates, almost 
nearly as fast as 8-bit surfaces. I'm 100% sure it wasn't running in 
8-bit mode because of the behavior (with CCA, it is often readily 
apparent). But when I switched to double precision surfaces, I 
experienced a dramatic decrease in performance, which probably means 
that at that point it could only operate in software mode, since my card 
can't handle higher bit depths (I haven't actually looked it up, but 
it's what I'm assuming).

Sam


Post a reply to this message

From: Roman Reiner
Subject: Re: Question about OpenGL and lightmaps
Date: 22 May 2011 06:20:00
Message: <web.4dd8e31b7aec4d4b748abb700@news.povray.org>
I'm not quite sure whether i understand your question but afaik lightmaps are
traditionally used as

finalColor = (ambientColor+lightMapColor)*textureColor

Using a Shaderprogram you can of course use it in any way you want.

Regards Roman


Post a reply to this message

From: Slime
Subject: Re: Question about OpenGL and lightmaps
Date: 22 May 2011 15:00:52
Message: <4dd95d64$1@news.povray.org>
>    I was more interested in the traditional (pre-pixel-shaders) way of
> doing light mapping.
>

I remember hearing about something called 2X multiply, or Modulate2x 
that multiplies the texture by 2. After a little searching for that, it 
looks like this might be the way to do it in opengl:

glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 2.0)

I also saw GL_RGB_SCALE_ARB, so it might be part of an extension. Of 
course, this has to be combined with multitexturing.

  - Slime


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.