How can I add overbright lighting to Quake engine?

Discuss programming topics for the various GPL'd game engine sources.
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

How can I add overbright lighting to Quake engine?

Post by hondobondo »

Enhanced GlQuake is the only engine that can run SDQuake, besides Darkplaces, and I want to add overbrights to it? Any tuts?
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Post by revelator »

i think mh had some code for that ?.

aye older release before mhquake went d3d controllable to as its used to replace the software gamma code.
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

Simple enough for the world model. Just shift the lightmap by 8 (jnstead of by 7) in R_BuildLightmap, then use glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR); in R_BlendLightmaps or a 2 x RGB combine instead of GL_MODULATE in R_DrawSequentialPoly. If those last items sound like too much you can double your palette values for mipmapped textures instead.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

BengtOverbrights.zip

Present for you Hondo. :D

Use gl_overbright 1 (default) to enable. Overbrights are only available if GL_ARB_texture_env_combine is also available. In general that means that they're available on everything aside from old first and second gen 3dfx cards (or other hardware of comparable age).

They could be easily added to the gl_texsort 1 path for brush models on this ancient hardware, as that doesn't depend on combine. Adding them to alias models needs a little more work though.

I've made the whole project Visual C++ 2008 friendly, and removed the need to use gas2masm (just added the generated .asm files to it; ml.exe comes with 2008). The WinQuake builds won't compile successfully though, and I didn't bother with fixing them.

Just search for the word "overbright" in the source and you'll find most of what you need.

Incidentally, there is a third engine that can run SDQuake. :D

Image
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

you are sooper awesome

Post by hondobondo »

mh wrote:BengtOverbrights.zip

Present for you Hondo. :D

Use gl_overbright 1 (default) to enable. Overbrights are only available if GL_ARB_texture_env_combine is also available. In general that means that they're available on everything aside from old first and second gen 3dfx cards (or other hardware of comparable age).

They could be easily added to the gl_texsort 1 path for brush models on this ancient hardware, as that doesn't depend on combine. Adding them to alias models needs a little more work though.

I've made the whole project Visual C++ 2008 friendly, and removed the need to use gas2masm (just added the generated .asm files to it; ml.exe comes with 2008). The WinQuake builds won't compile successfully though, and I didn't bother with fixing them.

Just search for the word "overbright" in the source and you'll find most of what you need.

Incidentally, there is a third engine that can run SDQuake. :D

Image
thanks MH :D :D :D
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

ummm

Post by hondobondo »

mh wrote:BengtOverbrights.zip

Present for you Hondo. :D

Use gl_overbright 1 (default) to enable. Overbrights are only available if GL_ARB_texture_env_combine is also available. In general that means that they're available on everything aside from old first and second gen 3dfx cards (or other hardware of comparable age).

They could be easily added to the gl_texsort 1 path for brush models on this ancient hardware, as that doesn't depend on combine. Adding them to alias models needs a little more work though.

I've made the whole project Visual C++ 2008 friendly, and removed the need to use gas2masm (just added the generated .asm files to it; ml.exe comes with 2008). The WinQuake builds won't compile successfully though, and I didn't bother with fixing them.

Just search for the word "overbright" in the source and you'll find most of what you need.

Incidentally, there is a third engine that can run SDQuake. :D

Image
i tried out the code but had some problems:
first i tried merging your changes with mine, but since i use GL_RGBA every level came out with colored splotches everywhere (WTF?)
then i tried adding colored lights to yours but the same thing happened. anyway, i have no idea what you said above with the openGL gibberish(?!)
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Post by revelator »

gl_overbright is just a cvar for enabling/disabling the overbrights nothing to do with opengl as such ;)

shift means the part in R_DrawSequentialPoly where you see << 7 make that << 8 (<< means shift in C).


then use the appropriate blendmodes in R_BlendLightmaps or
R_DrawSequentialPoly.

have a look at the zip mh sent ya :)

this part in particular

Code: Select all


// mh - set/unset combine modes
void GL_BeginLightBlend (void)
{
	if (gl_usingoverbright)
	{
		// mh - combine mode
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
		glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0f);
	}
	else
	{
		// mh - uninverted range
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	}
}

[/code]
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

thanks reckless

Post by hondobondo »

i'll see what i can make sense of
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

Oh, is this how QMB made the strobe effect for ammo models? :twisted:
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Post by revelator »

not sure :)

btw. this part glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0f); the 2.0f at the end can actually be replaced by a cvar for scaling the overbrights, just dont go overboard with silly values keep it clamped to some valid ranges.

a range from 0.0f to 2.0f should be fine.
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

reckless wrote:not sure :)

btw. this part glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0f); the 2.0f at the end can actually be replaced by a cvar for scaling the overbrights, just dont go overboard with silly values keep it clamped to some valid ranges.

a range from 0.0f to 2.0f should be fine.
Actually it can't; the only legal values are 1, 2 or 4: http://www.opengl.org/sdk/docs/man/xhtml/glTexEnv.xml
GL_INVALID_VALUE is generated if the params value for GL_RGB_SCALE or GL_ALPHA_SCALE are not one of 1.0, 2.0, or 4.0.
Also http://msdn.microsoft.com/en-us/library ... 85%29.aspx which tends to more accurately represent what the hardware can actually do (at the expense of having it explode in your face if you try to do something it can't! :lol: )

It would probably work on NVIDIA hardware though, but don't expect it to work on anything else.

(Aside: I have done some experiments with 4 x overbrighting in the past. It does give a slightly better light range, but only very slightly, and the stair-step effect becomes very strong (due to >> 9). It's fine if you can do 64-bit or 128-bit textures, but not really that big a deal overall.)
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Post by revelator »

limited cvar usage then :lol: well could probably round those values somehow but aye would be a bit messy if the user wrote 1.5 should it then be 1 or 2 :)

idea actually came from a quake2 engine that used a cvar that way allthough the menu item for it was clamped at 2 highest 1 normal.
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

you funny

Post by hondobondo »

mh wrote:Simple enough for the world model. Just shift the lightmap by 8 (jnstead of by 7) in R_BuildLightmap, then use glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR); in R_BlendLightmaps or a 2 x RGB combine instead of GL_MODULATE in R_DrawSequentialPoly. If those last items sound like too much you can double your palette values for mipmapped textures instead.
i'm laughing because all of this is gibberish to me. i think i can do the first part in R_BuildLightMap (change all the <<= 7s and >>= 7s to 8s). but i don't know what 2xRGB combine is.

I DO MATH! but poor at OPENGL
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: you funny

Post by mh »

hondobondo wrote:
mh wrote:Simple enough for the world model. Just shift the lightmap by 8 (jnstead of by 7) in R_BuildLightmap, then use glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR); in R_BlendLightmaps or a 2 x RGB combine instead of GL_MODULATE in R_DrawSequentialPoly. If those last items sound like too much you can double your palette values for mipmapped textures instead.
i'm laughing because all of this is gibberish to me. i think i can do the first part in R_BuildLightMap (change all the <<= 7s and >>= 7s to 8s). but i don't know what 2xRGB combine is.

I DO MATH! but poor at OPENGL
Find this:

Code: Select all

		glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
and replace it with this:

Code: Select all

		glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
		glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
		glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
		glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
		glTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, 2.0f);
When shutting down the state at the end of your draw function you'll also need this:

Code: Select all

	glTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f);
	glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
But beware! Your code may use glTexEnvf where I use glTexEnvi. No practical difference though. :D

You'll also need these in your glquake.h:

Code: Select all

#define GL_COMBINE                        0x8570
#define GL_COMBINE_RGB                    0x8571
#define GL_COMBINE_ALPHA                  0x8572
#define GL_SOURCE0_RGB                    0x8580
#define GL_SOURCE1_RGB                    0x8581
#define GL_SOURCE2_RGB                    0x8582
#define GL_SOURCE0_ALPHA                  0x8588
#define GL_SOURCE1_ALPHA                  0x8589
#define GL_SOURCE2_ALPHA                  0x858A
#define GL_OPERAND0_RGB                   0x8590
#define GL_OPERAND1_RGB                   0x8591
#define GL_OPERAND2_RGB                   0x8592
#define GL_OPERAND0_ALPHA                 0x8598
#define GL_OPERAND1_ALPHA                 0x8599
#define GL_OPERAND2_ALPHA                 0x859A
#define GL_RGB_SCALE                      0x8573
#define GL_ADD_SIGNED                     0x8574
#define GL_INTERPOLATE                    0x8575
#define GL_SUBTRACT                       0x84E7
#define GL_CONSTANT                       0x8576
#define GL_PRIMARY_COLOR                  0x8577
#define GL_PREVIOUS                       0x8578
#define GL_DOT3_RGB                       0x86AE
#define GL_DOT3_RGBA                      0x86AF
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

To hell with the death of Quakesrc.org

MH is his own Quakesrc.org galaxy. :P
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Post Reply