DaemonEngine / Daemon

The Dæmon game engine. With some bits of ioq3 and XreaL.
https://unvanquished.net
BSD 3-Clause "New" or "Revised" License
298 stars 61 forks source link

Shadowmaps #1209

Open VReaperV opened 3 months ago

VReaperV commented 3 months ago

This issue is to keep track of necessary steps and progress for implementing shadowmaps in the tiled renderer.

Required:

Optional:

slipher commented 3 months ago

I suppose shadows are expected to be cast by dynamic lights only? Since the information isn't really there for lights baked into the map. It's possible to instruct q3map2 not to remove point light entities, but then everyone says you should be using light emitting shaders anyway. I don't remember anything about the old shadow implementation, so I'm just asking as if it's starting from scratch.

illwieckz commented 3 months ago

I suppose shadows are expected to be cast by dynamic lights only?

IT would be a good start, yes.

Since the information isn't really there for lights baked into the map. It's possible to instruct q3map2 not to remove point light entities, but then everyone says you should be using light emitting shaders anyway.

Indeed light entities could be used when not removed, and surfaces using light emitting shaders too (would require to also parse those keywords), when the shader is properly shipped with the map (it was possible to not ship some shaders if the image had the same name as the shader and some special effects like image scrolling were not used).

I wonder if we can also average some lightgrid direction.

VReaperV commented 3 months ago

Yeah, some information would be required for any shadows. I'm assuming light emitting shaders essentially work as spotlights where everything between where the light source would be and the surface itself is ignored? (and light falloff not applying until getting to the surface of course)

illwieckz commented 3 months ago

I'm assuming light emitting shaders essentially work as spotlights

Basically, yes. In fact the map compiler spawns a kind of spotlight every given subdivision, and this subdivision can be configured, but considering it as a spotlight at first would be good enough (and we may not want to render so many shadows anyway).

spotlights where everything between where the light source would be and the surface itself is ignored?

I don't get this part of the sentence.

VReaperV commented 3 months ago

I don't get this part of the sentence.

I'm imagining something like this: image

DolceTriade commented 3 months ago

Averaging the lightgrid is possible and that's what we did in the past. It's just not super accurate, but if the shadows look nice, it still looks nice :)

I don't think we have any information about light emitting shaders except the light grid, which is super lossy.

illwieckz commented 3 months ago

The light emitting shader works like this:

                           light cone
      \       /   \       /
       \     /     \     /
        \   /       \   /
         \ /         \ /
          *           * light
         / \         / \ back splash
     ________________________ light emitting shader
/////|//////////|///////////|/////// wall
     |          |           | subdivision

A light is spawn a bit in front of the surface having a light emitting shader, with a back splash.

The distance of the light to the surface, and the intensity of the backsplash is configurable independently to the main light intensity.

More details here: http://q3map2.robotrenegade.com/docs/shader_manual/q3map-global-directives.html

VReaperV commented 3 months ago

Hmm, interesting. How is the light cone size calculated though? I'm not seeing any mention of that. At least some light source for such surfaces can probably be combined to avoid building more shadowmaps.

illwieckz commented 3 months ago

DolceTriade dixit: I don't think we have any information about light emitting shaders except the light grid, which is super lossy.

I guess we can iterate every surface of the geometry, compute the position in space, pick the material name, lookup for the shader, parse it and see if there is some light emitting keywords in its body.

VReaperV dixit: How is the light cone size calculated though?

I even don't know if it's a cone, but I guess it's somewhat biased into some direction if it needs a backlight.

illwieckz commented 3 months ago

I even don't know if it's a cone, but I guess it's somewhat biased into some direction if it needs a backlight.

It may also be an half-sphere.