Forum

In Fitz R_Marklights ...

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

In Fitz R_Marklights ...

Postby Baker » Thu Jul 19, 2012 6:32 am

In FitzQuake R_Marklights, what is the objective of the following code?

I notice this is removed in the RMQ Engine and nothing like this is present in DirectQ. There is already a distance check before this code.

Code: Select all
      // clamp center of light to corner and check brightness
      l = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
      s = l+0.5;if (s < 0) s = 0;else if (s > surf->extents[0]) s = surf->extents[0];
      s = l - s;
      l = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
      t = l+0.5;if (t < 0) t = 0;else if (t > surf->extents[1]) t = surf->extents[1];
      t = l - t;

      // compare to minimum light
      if ((s*s+t*t+dist*dist) < maxdist)
      {
         if (surf->dlightframe != r_dlightframecount) // not dynamic until now
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: In Fitz R_Marklights ...

Postby Spike » Thu Jul 19, 2012 6:48 am

each surface is defined as a plane. it has a forwards direction, it has an s direction, and it has a t direction. forward=normal, s+t=texture alignment directions.

if you check light proximity purely against the plane, then you're going to light that plane even if the light is nowhere near the actual surface quad or whatever it is.
it clips the position based upon the texture coords. the l= lines are a classic plane equation, just with two distances instead of one.

imagine a huge wall 100000qu across (split into 18 lightmap samples or so along its length). fire your rocket at the middle...
that code means that you only mark/relight the surfaces in the middle, as opposed to all the way along the length of the entire wall/plane.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: In Fitz R_Marklights ...

Postby Baker » Thu Jul 19, 2012 6:51 am

Ok, so it is doing what I think it is doing, but there is a reason for it. I didn't realize the distance check was using a plane, obviously.
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: In Fitz R_Marklights ...

Postby Spike » Thu Jul 19, 2012 7:08 am

aye, just a weird complex way to check 3 planes instead of just 1. kinda.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: In Fitz R_Marklights ...

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

I removed it from RMQ because it was imposing some extra CPU load there and the dlight implementation I had written just benchmarked faster without it. DirectQ recently got it back though. The moral of that story is that there is no 100% correct-and-appropriate-at-all-times "this is faster" approach; you need to take other factors into consideration and review/revisit something that may have benchmarked faster before in the light (pun intended) of new code changes.

If you compare with the code in R_AddDynamicLights you'll see that it's virtually the same - the only thing that looks anyway goofy is the "s * s + t * t + dist * dist" part, but that's just a standard distance calculation with the sqrt optimized out (note that maxdist is pre-calced as radius * radius).
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


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest