Forum

Dynamic lights on moving brush models

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

Re: Dynamic lights on moving brush models

Postby qbism » Sun Apr 22, 2012 6:28 pm

leileilol wrote:It's now in svn but i believe I hit a wall lighting bug. I tried to apply this onto the faster lordhavoc marklights function, a video

A guess... move "currententity = &cl_entities[0]" to a different place. Just before calling R_PushDlights on the worldmodel.
User avatar
qbism
 
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am

Re: Dynamic lights on moving brush models

Postby leileilol » Mon Apr 23, 2012 3:01 am

I don't know. The funny thing is that the shadows show up fine where dynamic lights can't (such as the DM2 megahealth/grenade train). The shadow system is a simplified duplicate of the dlight system.
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: Dynamic lights on moving brush models

Postby mankrip » Mon Apr 23, 2012 7:03 am

As mh said, this kind of fix doesn't take BSP rotation into account. I may implement support for dynamic lighting on rotating brushes someday, but since none of the original maps uses it this is good enough for now.

Does Engoo support rotating brushes? dm2 has a 90 degree angle rotation set in its worldspawn entity. I don't think that may be the cause, but it's worth a look.
Either that, the blob shadows code or something else may be causing it. There's no problem with the dynamic lighting of those dm2 places in Makaqu.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Re: Dynamic lights on moving brush models

Postby mh » Mon Apr 23, 2012 7:21 am

For rotation what you'd ideally do is (1) load an identity matrix onto the brush model, transform it as normal, then (2) multiply the resulting matrix from 1 by the current MVP for drawing the entity, and (3) inverse the resulting matrix from 1 for lighting. (4) multiply the light position by the inverse matrix to get it's transformed position then proceed as before.

That works perfectly with a hardware accelerated engine, but for software you'll obviously need to do a little more work.

e3m3 also has rotation set in it's worldspawn. :evil:
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: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Postby mankrip » Mon Apr 23, 2012 10:05 am

mh wrote:e3m3 also has rotation set in it's worldspawn. :evil:

You're right, I was probably thinking of e3m3.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Re: Dynamic lights on moving brush models

Postby mh » Mon Apr 23, 2012 5:05 pm

mankrip wrote:
mh wrote:e3m3 also has rotation set in it's worldspawn. :evil:

You're right, I was probably thinking of e3m3.

Could easily be both. dm2 also seems to have the wrong worldtype set - it's base but surely it should be metal? - so if one bug can happen then so can another.

This caught me out in e3m3 once when I was rotating a set of surfaces based on the entities angles and not checking if the entity was the world.
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: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Postby mankrip » Mon Apr 23, 2012 8:12 pm

Well, here's it's worldspawn, unmodified from pak1.pak:
Code: Select all
{
"message" "Claustrophobopolis"
"classname" "worldspawn"
"wad" "gfx/metal.wad"
}

Both the worldtype and the CD audio track aren't set. I've fixed the audio track by setting it to 8 in my UQMP toolkit, but I've not added a worldtype parameter to set it to metal. worldtype 0 is the medieval one, which isn't too wrong but isn't right either.

Now I remember, I found out about this when I noticed this map would just keep playing the same audio track from the previously played map, which was quite weird after playing one of the base-themed maps.

Engoo's lighting problem must be somewhere else in the engine then.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Re: Dynamic lights on moving brush models

Postby leileilol » Mon Apr 23, 2012 11:02 pm

mankrip wrote:Engoo's lighting problem must be somewhere else in the engine then.

I suspected it being a surface marking thing rather than the theory of being shifted by rotations. I noted about the shadows because they work where dlights can't and the shadows are dlights copied, but i've compared the functions of shadows and lights and can't even spot a visible clue between the two why one works and the other doesn't.
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: Dynamic lights on moving brush models

Postby Baker » Thu Jul 19, 2012 12:01 am

I forgot there was a tutorial on this. :D

Problems - 1
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 ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Dynamic lights on moving brush models

Postby mh » Thu Jul 19, 2012 12:29 am

Have fun when you come to do the matrix inversion. You really need it for rotating bmodels and GL's stack just doesn't cut it. Best you can do is glPushMatrix/glLoadIdentity/run transforms in reverse order/glGetfloat/glPopMatrix, then do it all again normally. When I implemented this in Quake II I just used D3D's matrix library - it worked fine in GL.
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: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Postby Baker » Thu Jul 19, 2012 4:43 am

I've hated this problem for so long ... I've rather satisfied with the results of this.

This was a great one. I have never liked that world submodels don't behave as part of the proper world.

http://www.youtube.com/watch?v=bWFFe9bCB5s
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 ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Dynamic lights on moving brush models

Postby mh » Thu Jul 19, 2012 5:42 pm

It's one of those things that can be quite subtle a hell of a lot of the time, but once you start noticing it there's no going back. :D
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: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Postby mh » Fri Feb 27, 2015 3:12 pm

Unless I've got things badly wrong, this will perform the inversion for you without any shenanigans:
Code: Select all
void R_InverseTransform (float *out, float *in, float *origin, float *angles)
{
   VectorSubtract (in, origin, out);

   if (angles[0] || angles[1] || angles[2])
   {
      vec3_t   temp;
      vec3_t   forward, right, up;

      VectorCopy (out, temp);
      AngleVectors (angles, forward, right, up);

      out[0] = DotProduct (temp, forward);
      out[1] = -DotProduct (temp, right);
      out[2] = DotProduct (temp, up);
   }
}
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: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Postby Baker » Fri Feb 27, 2015 3:27 pm

I take it that is the replacement for ...
float matrix[16];

// get the inverse transform for moving the light back to the same space as the model
glPushMatrix ();
glLoadIdentity ();
glRotatef (-e->angles[2], 1, 0, 0);
glRotatef (-e->angles[0], 0, 1, 0);
glRotatef (-e->angles[1], 0, 0, 1);
glTranslatef (-e->origin[0], -e->origin[1], -e->origin[2]);
glGetFloatv (GL_MODELVIEW_MATRIX, matrix);
glPopMatrix ();
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 ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Dynamic lights on moving brush models

Postby mankrip » Sun Mar 01, 2015 12:08 am

mh wrote:Unless I've got things badly wrong, this will perform the inversion for you without any shenanigans:
Code: Select all
void R_InverseTransform (float *out, float *in, float *origin, float *angles)
{
   VectorSubtract (in, origin, out);

   if (angles[0] || angles[1] || angles[2])
   {
      vec3_t   temp;
      vec3_t   forward, right, up;

      VectorCopy (out, temp);
      AngleVectors (angles, forward, right, up);

      out[0] = DotProduct (temp, forward);
      out[1] = -DotProduct (temp, right);
      out[2] = DotProduct (temp, up);
   }
}

:D Thanks. This should be useful when I get around to implement a rotated version of that fix in the software renderer.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

PreviousNext

Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests