Dark spots/edges near sky when using sky lighting in Quake2

Discuss the construction of maps and the tools to create maps for 3D games.
jitspoe
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Dark spots/edges near sky when using sky lighting in Quake2

Post by jitspoe »

If you have a wall directly up against a sky ceiling, you'll get some weird shadowy edges on it. I'm pretty sure ArghRad fixed this, and maybe some other compilers. Anybody know how this fix was done?
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by qbism »

The same thing goes for light emitting faces. At intersections it looks like a series of point lights that don't overlap enough. Maybe argh increases the radius, decreases the spacing, or uses a different fall-off function. This is just a guess for now. But here's the place where the reflectivity of radiosity is seen to double as light emitter. Excerpt from MakePatchForFace in patches.c

Code: Select all

	// non-bmodel patches can emit light
	if (fn < dmodels[0].numfaces)
	{
		BaseLightForFace (f, patch->baselight);

		ColorNormalize (patch->reflectivity, color);

		for (i=0 ; i<3 ; i++)
			patch->baselight[i] *= color[i];

		VectorCopy (patch->baselight, patch->totallight);
	}
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by qbism »

Getting some improvement with inverse-square falloff rather than straight inverse. Changes the character of lighting throughout the map, however. Much more even.
In GatherSampleLight

Code: Select all

inv = 0.15 / sqrt(dist); //qb: was 1.0f / dist;
The 0.15 number is something to play with to try to match the overall intensity of the original function.
Not as good as arghrad this way. Maybe an average of inverse and inverse-square, or something more complex.
jitspoe
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by jitspoe »

Hmm, changing that would effectively change the falloff of light in general to be less accurate, wouldn't it?
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by qbism »

Definitely inaccurate. Real-world light is inverse square, DeWan qrad3* is inverse, and other choices include inverse square.

One possibility is to use different functions for different things- inverse for point lights and something else for emitters.

My first guess for arghrad was that is uses a hybrid: inv = 1.0/ (dist * A + sqrt(dist) * B) where A and B are static values. But I haven't been able to duplicate that look. Perhaps A and B are based on distance. Or maybe it's a single factor in a power function? The assumption is that we want to 'smear' the lighting near the emitting source patch to hide darkspots but transition to typical inverse lighting further out.

*edit1: not sure about vanilla, it's written differently than DeWan's GatherSampleLight.

edit2: try this (2 changes):

Code: Select all

...
			else
			{
				inv = 4.5f / (dist * sqrt(dist)); //qb: was 1.0f / dist;
				delta[0] *= inv;
				delta[1] *= inv;
				delta[2] *= inv;
			}

			dot = DotProduct(delta, normal);
			if (dot <= 0.001)
				continue;	// behind sample surface

			if (l->adjangle == 1.0f)
				adj = dot;
			else if (l->adjangle = 0.0f)
				adj = 1.0f;
			else
			{
				adj = pow(dot, l->adjangle);
			}

			switch (l->type)
			{
			case emit_point:
				// linear falloff
				scale = (l->intensity - (l->wait * dist)) * adj;
				break;

			case emit_surface:
				dot2 = -DotProduct(delta, l->normal);
				if (dot2 <= 0.001)
					goto skipadd;	// behind light surface
				//scale = (l->intensity / (dist * dist)) * dot * dot2;
				scale = (l->intensity * inv * 0.15) * dot * dot2;  //qb: was (l->intensity * inv * inv) * dot * dot2;

				break;
...
jitspoe
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by jitspoe »

I'll try to play around with this soon.

I would have thought the problem would come from the DotProduct check, as the black edge would be where the dot product is at/near zero. I wonder if adding a small fraction to the DotProduct result would help with this (but might cause light to bleed into areas it shouldn't).
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by qbism »

You might be looking at a different artifact if it's a completely black area vs a gradient. What I'm seeing with DeWan tools is like a series of point lights around sky openings and large light-emitting surfaces, and the points get further apart with larger -chop sizes. When I tried the code above it 'works' near these conditions but produces splotchy dark patches elsewhere. So next I will try 1/sqrt(dist) for patches and the original 1/dist for spots and point lights.

I haven't been able to find any other Q2 code that deals with altering radiosity. Alien Arena and q2world tools have modified features but both source code bases remove emitting surfaces.
jitspoe
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by jitspoe »

This is what I'm referring to:

If I put a sky (or I guess any light emitting surface) flat along the top of a map, I get this (note the dark edges):
Image

It's possible to work around this by building the sky up vertically (building walls of sky) and having a higher sky ceiling:
Image
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by qbism »

I haven't run into that type of artifact. I built a little test map and tried 'flat sky' vs 'raised sky' but no edge problems on the test map. On the other hand, I was able to find an example of seemingly random splotchy or linear lightmap artifacts that I've been getting. Screenshots below- the first is vanilla GPL map tools and the second is modified DeWan qrad3, currently: inv =3.0f / (dist * sqrt(dist)) and emit_surface scale = (l->intensity * inv * 0.3) * dot * dot2

Since I compiled both from scratch, I wonder if it is related to the floating point Quake lightmap glitch posted around here a few months ago.

Image

Image
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by qbism »

OK, so I added a long skinny brush on the wall to eventually make it a light. But simply adding the brush made the artifact disappear. This doesn't solve the underlying issue but it shows the nature of the problem.
Image
jitspoe
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by jitspoe »

I noticed a similar issue (horizontal line on a wall) in my test map. Not sure what causes it. Maybe it's at the max edge when the lighting util is forced to chop the geometry? Maybe adding another brush caused qbsp to break the geometry up differently?

There are certainly some weird little nuances that are difficult to debug.
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by mankrip »

jitspoe wrote:This is what I'm referring to:

If I put a sky (or I guess any light emitting surface) flat along the top of a map, I get this (note the dark edges):
Image
It looks like a raytracing problem. At the very edges, the wall is perfectly orthogonal to the sky surface, so it's impossible to trace a beam from any point in the sky surface to the top edge of the wall.

To fix that, the lighting tool would have to manually set the lightmap values at the shared edges of surfaces that shares edges with the sky surface, as long as the planes of those surfaces are < 180 degrees and >= 90 degrees in relation to the plane of the sky surface. Or something like that.

Another solution would be for the lighting tool to interpret sky surfaces as if they were boxes, and trace from behind the sky surfaces instead of tracing from the actual location of their planes.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by Spike »

aye, a co-planar ray tracing issue will do it.
your traceline will have start==0 and end==0 as it traces horizontally along the plane. if your code considers dist=0 to be an impact then it'll consider the wall to be behind the sky instead of infront, and thus won't light those light samples.
you can change your code to consider both start and end equal to 0 to not be a trace, but doing so potentially allows leaking light due to tracing between brushes.
probably the easiest/safest way to fix it is to nudge the world coord of those surface points towards the center of the wall polygon somehow, avoiding the worst of any coplaner issues, but can still have precision issues, and might give neighbouring surfaces different light levels for the same point (resulting in harsh lines at the boundary between light/shade).
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by mankrip »

Spike wrote:aye, a co-planar ray tracing issue will do it.
your traceline will have start==0 and end==0 as it traces horizontally along the plane. if your code considers dist=0 to be an impact then it'll consider the wall to be behind the sky instead of infront, and thus won't light those light samples.
you can change your code to consider both start and end equal to 0 to not be a trace, but doing so potentially allows leaking light due to tracing between brushes.
probably the easiest/safest way to fix it is to nudge the world coord of those surface points towards the center of the wall polygon somehow, avoiding the worst of any coplaner issues, but can still have precision issues, and might give neighbouring surfaces different light levels for the same point (resulting in harsh lines at the boundary between light/shade).
But there's no need to do any tracing. We already know that the lighting in the top edges of those walls should have the maximum value emitted by the sky surface, so it's just a matter of setting that value into their corresponding positions in the lightmap.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Dark spots/edges near sky when using sky lighting in Qua

Post by qbism »

Aren't light-emitting surfaces simulated by a grid of point lights? The top edge of the wall should see a point light as well as any other point on the wall. Can the sky plane itself obscure a light-emitting point on the plane?
Post Reply