Forum

[quake2] overbright models

Discuss programming topics that involve the OpenGL API.

Moderator: InsideQC Admins

[quake2] overbright models

Postby marcelo_20xx » Tue Nov 15, 2011 2:11 am

I already implemented overbright in wals so now the game is a lot brighter without washed up textures, but it seems that the routine to include overbrights in models (like npcs and items or your weapons is different). Can somenone give some advice at this, I am working in the 3.21 source provided by ID.
marcelo_20xx
 
Posts: 10
Joined: Sat Nov 12, 2011 2:05 am

Re: [quake2] overbright models

Postby Spike » Tue Nov 15, 2011 6:02 am

overbrights:
Which of the following 2 has the greater dynamic range?

clamp(texture*clamp(lighting*0.5) * 2)
clamp(texture*clamp(lighting))

yup, the top one. that's the maths you need to set up to do your overbrights, instead of the second one.
or in other words, halve the light values passed per-vertex in your engine, and configure the GL_RGB_SCALE_ARB to double the resulting texture samples (or quater/quadruple, your choice).

with lightmaps its the lightmap samples which are halved (before being clamped to 255=1.0), which allows you to double the maximum range in there. with models its the glVertex values which is halved (before being clamped to 255=1.0)
that's the only difference.

if you calc the light levels in the vertex program using non-clamped colour values etc then you can bypass the inner clamp making any overbrighting limit value much much larger. sadly for world lighting, the inner clamp is limited by the precision provided by a 24bit colour image. you can achieve higher ranges by using a floating-point texture format. In the case of q3bsp, the lightmaps are already scaled down to 0.25, while quake/quake2 scales down in the lightmap generation code.
Spike
 
Posts: 2878
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: [quake2] overbright models

Postby Barnes » Tue Nov 15, 2011 7:41 am

very old code for pics or models overbright
Code: Select all
void GL_Overbrights(qboolean enable)
{
   
   if (enable) {            // turn on
      GL_TexEnv(GL_COMBINE_ARB);

      qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
      qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
      qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
      qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (int) r_overBrightBits->value);

      qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
      qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
      qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB);
      qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);
   } else {               // turn off
      GL_TexEnv(GL_MODULATE);

      qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1);
      qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);
   }
}
User avatar
Barnes
 
Posts: 222
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow

Re: [quake2] overbright models

Postby marcelo_20xx » Tue Nov 15, 2011 7:48 am

I forgot to mention that I took the code from this page "http://www.quakewiki.net/quakesrc/28.html" where Vic coded overbrights for the engine, but sadly there isnt working for models. I already took a look at KMQuake2 source and they changed a lot of stuff to get overbrights on models but I wasnt very sure how they implemented this, since the vanilla source and theirs are too much different.
marcelo_20xx
 
Posts: 10
Joined: Sat Nov 12, 2011 2:05 am

Re: [quake2] overbright models

Postby Barnes » Tue Nov 15, 2011 7:52 am

Vic's method really only works for the BSP.
for models and pictures overbright use above code. If I remember correctly it code uses in kmquake2
User avatar
Barnes
 
Posts: 222
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow

Re: [quake2] overbright models

Postby marcelo_20xx » Tue Nov 15, 2011 7:58 am

Yep, Vic's code only works for BSPs, thanks for the quick responses to both of you I will go to sleep and see if tomorrow I can get something work.
marcelo_20xx
 
Posts: 10
Joined: Sat Nov 12, 2011 2:05 am

Re: [quake2] overbright models

Postby mh » Tue Nov 15, 2011 10:18 am

Code: Select all
qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (int) r_overBrightBits->value);


Beware. You can't really do this. GL_ARB_texture_env_combine:
Accepted by the <params> parameter of TexEnvf, TexEnvi, TexEnvfv,
and TexEnviv when the <pname> parameter value is RGB_SCALE_ARB or
ALPHA_SCALE

1.0
2.0
4.0
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
User avatar
mh
 
Posts: 2286
Joined: Sat Jan 12, 2008 1:38 am

Re: [quake2] overbright models

Postby leileilol » Tue Nov 15, 2011 1:36 pm

I should mention that unlike Quake, Quake2's models aren't intended to be overbrightened (not even in software) so brightening only the BSP still is logical.

Don't forget to nuke that stupid "intensity" feature. It sucks.
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: [quake2] overbright models

Postby Barnes » Tue Nov 15, 2011 2:31 pm

I think there is more correct to speak not about the overbright, but the multiplication of the color intensity of 2 times
like
gl_FragColor = color * u_ColorModulate; :D
User avatar
Barnes
 
Posts: 222
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow

Re: [quake2] overbright models

Postby mh » Tue Nov 15, 2011 4:38 pm

I believe that Q2 actually does overbright MD2s as it sends their textures through it's lightscale/intensity thing, and glColor/glColorPointer will clamp in the 0..1 range. There is a lot of second-system-effect crap in the Q2 renderer (gl_modulate is something else that must also die) that does confuse the issue though.
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
User avatar
mh
 
Posts: 2286
Joined: Sat Jan 12, 2008 1:38 am

Re: [quake2] overbright models

Postby marcelo_20xx » Tue Nov 15, 2011 5:43 pm

The function that controls the textures in bmodels is "void R_DrawInlineBModel (void)"? (found in gl_rsurf.c). Also this forum is about coding Quake engine? or Quake 2 too?. KmQuake2 already implemented overbright in models but since their project and their webpage is dead I cant find how they did it :(.
marcelo_20xx
 
Posts: 10
Joined: Sat Nov 12, 2011 2:05 am

Re: [quake2] overbright models

Postby revelator » Tue Nov 15, 2011 8:02 pm

Mostly Quake but we do help on Q2 to if we can :)
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2518
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: [quake2] overbright models

Postby marcelo_20xx » Tue Nov 15, 2011 8:25 pm

@reckless
Oh I see, I was reading the tutorial section of the forums and almost all the code is related to Quake1

I think I am near the solution of the problem, I found the following function in Kmquake2 source:
Code: Select all
/*
=================
R_SetVertexOverbrights
=================
*/
void R_SetVertexOverbrights (qboolean toggle)
{
   if (!r_overbrightbits->value || !glConfig.mtexcombine)
      return;

   if (toggle) // turn on
   {
#if 1
      qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
      qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
      qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, r_overbrightbits->value);
      qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
      
      GL_TexEnv(GL_COMBINE_ARB);
#else
      qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
      qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
      qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, r_overbrightbits->value);
      qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);

      GL_TexEnv(GL_COMBINE_EXT);
#endif
   }
   else // turn off
   {
      GL_TexEnv(GL_MODULATE);
      qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1);
   }
}


Its almost the same of what Barnes posted, btw Barnes where do I put the calls?
marcelo_20xx
 
Posts: 10
Joined: Sat Nov 12, 2011 2:05 am

Re: [quake2] overbright models

Postby Barnes » Tue Nov 15, 2011 9:47 pm

mh wrote:
Code: Select all
qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (int) r_overBrightBits->value);

Beware. You can't really do this.

I remember about it. Although it code I used for pictures, decals or skyboxes. Almost everything else I'm drawing with glsl
User avatar
Barnes
 
Posts: 222
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow

Re: [quake2] overbright models

Postby mh » Tue Nov 15, 2011 10:48 pm

marcelo_20xx wrote:Oh I see, I was reading the tutorial section of the forums and almost all the code is related to Quake1

A lot of the code is so similar in both engines that it doesn't really matter.
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
User avatar
mh
 
Posts: 2286
Joined: Sat Jan 12, 2008 1:38 am

Next

Return to OpenGL Programming

Who is online

Users browsing this forum: No registered users and 1 guest