Dynamic lights on moving brush models

Post tutorials on how to do certain tasks within game or engine code here.
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Dynamic lights on moving brush models

Post by qbism »

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.
leileilol
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: Dynamic lights on moving brush models

Post by leileilol »

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
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Dynamic lights on moving brush models

Post by mankrip »

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
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Post by mh »

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
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Dynamic lights on moving brush models

Post by mankrip »

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
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Post by mh »

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
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Dynamic lights on moving brush models

Post by mankrip »

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
leileilol
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: Dynamic lights on moving brush models

Post by leileilol »

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

Re: Dynamic lights on moving brush models

Post by Baker »

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 ..
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Post by mh »

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

Re: Dynamic lights on moving brush models

Post by Baker »

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 ..
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Post by mh »

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
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Dynamic lights on moving brush models

Post by mh »

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

Re: Dynamic lights on moving brush models

Post by Baker »

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 ..
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Dynamic lights on moving brush models

Post by mankrip »

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
Post Reply