Jump to content

Clustered Forward Rendering - Multiple Light Types


Josh

2,931 views

 Share

I added spotlights to the forward clustered renderer. It's nothing too special, but it does demonstrate multiple light types working within a single pass.

Image1.thumb.jpg.cd9eb9a76926fa4526d9c00be973fc9b.jpg

I've got all the cluster data and the light index list packed into one texture buffer now. GPU data needs to be aligned to 16 bytes because everything is built around vec4 data. Consequently, some of the code that handles this stuff is really complicated. Here's a sample of some of the code that packs all this data into an array.

for (auto it = occupiedcells.begin(); it != occupiedcells.end(); it++)
{
	pos = it->first;
	visibilityset->lightgrid[pos.z + pos.y * visibilityset->lightgridsize.x + pos.x * visibilityset->lightgridsize.y * visibilityset->lightgridsize.x] = visibilityset->lightgrid.size() / 4 + 1;
			
	Assert((visibilityset->lightgrid.size() % 4) == 0);

	for (int n = 0; n < 4; ++n)
	{
		visibilityset->lightgrid.push_back(it->second.lights[n].size());
	}
	for (int n = 0; n < 4; ++n)
	{
		if (!it->second.lights[n].empty())
		{
			visibilityset->lightgrid.insert(visibilityset->lightgrid.end(), it->second.lights[n].begin(), it->second.lights[n].end());

			//Add padding to make data aligned to 16 bytes
			int remainder = 4 - (it->second.lights[n].size() % 4);
			for (int i = 0; i < remainder; ++i)
			{
				visibilityset->lightgrid.push_back(0);
			}
			Assert((visibilityset->lightgrid.size() % 4) == 0);
		}
	}
}

And the shader is just as tricky:

//------------------------------------------------------------------------------------------
// Point Lights
//------------------------------------------------------------------------------------------

countlights = lightcount[0];
int lightgroups = countlights / 4;
if (lightgroups * 4 < countlights) lightgroups++;
int renderedlights = 0;

for (n = 0; n < lightgroups; ++n)
{
	lightindices = texelFetch(texture11, lightlistpos + n);
	for (i = 0; i < 4; ++i)
	{
		if (renderedlights == countlights) break;
		renderedlights++;
		lightindex = lightindices[n];
		...

I plan to add boxlights next. These use orthographic projection (unlike spotlights, which us perspective) and they have a boundary defined by a bounding box, with no edge softening. They have one purpose, and one purpose only. You can place them over windows for indoor scenes, so you can have light coming in a straight line, without using an expensive directional light. (The developer who made the screenshot below used spotlights, which is why the sunlight is spreading out slightly.)

251810_screenshots_20160718191102_1.thumb.jpg.ae82b75de84c3640fb5058aa089bf056.jpg

I am considering doing away with cascaded shadow maps entirely and using an array of box lights that automatically rearrange around the camera, or a combination of static and per-object shadows. I hope to find another breakthrough with the directional lights and do something really special. For some reason I keep thinking about the outdoor scenery in the game RAGE and while I don't think id's M-M-MEGATEXTURES!!! are the answer, CSM seem like an incredibly inefficient way to distribute texels and I hope to come up with something better.

download.thumb.jpg.2e6f6537b0b36de4a0bd6278db394c51.jpg

Other stuff I am considering

  • Colored shadows (that are easy to use).
  • Volumetric lights either using a light mesh, similar to the way lights work in the deferred renderer, or maybe a full-screen post-processing effect that traces a ray out per pixel and calculates lighting at each step.
  • Area lights (easy to add, but there are a lot of possibilities to decide on). These might be totally unnecessary if the GI system is able to do this, so I'm not sure.
  • IES lighting profiles.

I really want to find a way to render realistic light refraction, but I can't think of any way to do it other than ray-tracing:

MakeARainbow2.jpg.8fb8a5303bf86366bc44ae209914ec3a.jpg

It is possible the voxel GI system might be able to handle something of this nature, but I think the resolution will be pretty low. We'll see.

So I think what I will do is add the boxlights, shader includes, diffuse and normal maps, bug test everything, make sure map loading works, and then upload a new build so that subscribers can try out their own maps in the beta and see what the speed difference is.

  • Like 1
 Share

3 Comments


Recommended Comments

Quote

I plan to add boxlights next. These use orthographic projection (unlike spotlights, which us perspective) and they have a boundary defined by a bounding box, with no edge softening. They have one purpose, and one purpose only. 

Aren't boxlights like area lights? Would you be able to use it for representing light coming from florescent tube lighting?

Quote

Other stuff I am considering

  • Colored shadows (that are easy to use).
  • Volumetric lights either using a light mesh, similar to the way lights work in the deferred renderer, or maybe a full-screen post-processing effect that traces a ray out per pixel and calculates lighting at each step.
  • Area lights (easy to add, but there are a lot of possibilities to decide on). These might be totally unnecessary if the GI system is able to do this, so I'm not sure.

Colored shadows will be nice to have again if the color can be controlled by what is casting the shadow or at least user defined per entity. This would definitely help when you have translucent objects in a scene. It just looks weird to have a completely black shadow cast by something like a glass object like we have now in LE4.

Quote

I really want to find a way to render realistic light refraction, but I can't think of any way to do it other than ray-tracing:

If you get this working cheaply that would be pretty amazing. 

Link to comment

A box light is orthogonal so there is no spread to the rays. What you are describing is basically a spotlight with a rectangular shape.

of course with a few settings you could consider all of these to be one light type really.

  • Like 1
Link to comment

Super stoked! I'm getting ideas and plans ready for another project and this will certainly help visually and performance wise. I adore the box light idea. 

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...