Skip to content

Commit

Permalink
Gloom: Patching up shadow map seams
Browse files Browse the repository at this point in the history
The idea is to give surfaces a bit of thickness when rendering
shadow geometry.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 195bad7 commit e7bd244
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion doomsday/tests/test_gloom/gloom/render/lightrender.cpp
Expand Up @@ -423,7 +423,7 @@ void LightRender::advanceTime(TimeSpan elapsed)

// Testing.
{
Vec3d rotPos = Mat4f::rotate(2 * float(elapsed), Vec3f(0, 1, 0)) * d->skyLight->origin();
Vec3d rotPos = Mat4f::rotate(4 * float(elapsed), Vec3f(0, 1, 0)) * d->skyLight->origin();
d->skyLight->setOrigin(rotPos);
d->skyLight->setDirection(-rotPos);
}
Expand Down
8 changes: 6 additions & 2 deletions doomsday/tests/test_gloom/gloom/render/mapbuild.cpp
Expand Up @@ -95,7 +95,7 @@ DENG2_PIMPL_NOREF(MapBuild)
}
}

for (const ID sectorId : map.sectors().keys())
foreach (const ID sectorId, map.sectors().keys())
{
const Sector &sector = map.sector(sectorId);

Expand All @@ -110,6 +110,8 @@ DENG2_PIMPL_NOREF(MapBuild)
const auto &floor = planeVerts.front();
const auto &ceiling = planeVerts.back();
auto currentPlaneVerts = planeVerts.begin();
const auto floorId = map.floorPlaneId(sectorId);
const auto ceilingId = map.ceilingPlaneId(sectorId);

for (int v = 0; v < sector.volumes.size(); ++v)
{
Expand Down Expand Up @@ -142,6 +144,8 @@ DENG2_PIMPL_NOREF(MapBuild)
f.tangent = plane.tangent();
f.flags = MapVertex::WorldSpaceXZToTexCoords | MapVertex::TextureOffset;
f.geoPlane = planeMapper[volume.planes[i]];
f.texPlane[0] = planeMapper[floorId];
f.texPlane[1] = planeMapper[ceilingId];
f.texOffset[0] = texOffsetMapper[volume.planes[i]];

if (isFacingUp)
Expand All @@ -153,7 +157,7 @@ DENG2_PIMPL_NOREF(MapBuild)
f.tangent = -f.tangent;
}

for (const ID pointID : currentVerts.keys())
foreach (const ID pointID, currentVerts.keys())
{
f.pos = currentVerts[pointID];
f.texCoord = Vec4f(0, 0, 0, 0); // fixed offset
Expand Down
6 changes: 3 additions & 3 deletions doomsday/tests/test_gloom/gloom/render/mapbuild.h
Expand Up @@ -41,9 +41,9 @@ struct MapVertex
Vec4f texCoord;
Vec2f expander;
uint32_t material[2];
uint32_t geoPlane;
uint32_t texPlane[2]; // Index0: vec3
uint32_t texOffset[2]; // Index1: vec2
uint32_t geoPlane; // Index0 (x)
uint32_t texPlane[2]; // Index0 (yz)
uint32_t texOffset[2]; // Index1 (xy)
uint32_t flags;

LIBGUI_DECLARE_VERTEX_FORMAT(10)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tests/test_gloom/gloom/render/skybox.cpp
Expand Up @@ -52,7 +52,7 @@ void SkyBox::glInit(Context &context)

// Load the cube map.
{
const Image img = context.images->image("sky.day");
const Image img = context.images->image("sky.morning");
const Image::Size size{img.width() / 6, img.height()};

d->envTex.setFilter(gl::Linear, gl::Linear, gl::MipLinear);
Expand Down
Expand Up @@ -13,48 +13,54 @@ void main(void) {
Surface surface = Gloom_LoadVertexSurface();
float dp = dot(surface.normal, uLightDir);

float thickness = 1.0 * 0.2;

// Fixing shadow gaps.
if (dp > 0.0) { // Wall?
// if (dp > 0.0) { // Backfacing?
if (surface.normal.y == 0.0) {
//float adj = (1.0 - dp * 0.75);
//surface.vertex.xz -= 0.3 * surface.normal.xz * adj;


// if (testFlag(surface.flags, Surface_LeftEdge)) {
// surface.vertex.xyz -= 0.5 * surface.tangent;
// }
// else if (testFlag(surface.flags, Surface_RightEdge)) {
// surface.vertex.xyz += 0.5 * surface.tangent;
// }

// surface.vertex.xz += surface.expander;
// if (surface.vertex.y == surface.topPlaneY) {
// surface.vertex.y += 0.5;
// }
// else if (surface.vertex.y == surface.botPlaneY) {
// surface.vertex.y -= 0.5;
// }
if (surface.vertex.y == surface.topPlaneY) {
surface.vertex.y += thickness;
}
else if (surface.vertex.y == surface.botPlaneY) {
surface.vertex.y -= thickness;
}
}
else {
// surface.vertex.y -= surface.normal.y;
}
// surface.vertex.xyz -= uLightDir * 0.5;
}

if (dp > 0.0) {
// gl_Position.xz += 0.2 * surface.expander;
// if (dp > 0.0) {

// surface.vertex.xyz -= uLightDir * 0.5;
// }

// surface.vertex.xyz -= uLightDir * 0.5;
}

gl_Position = uLightMatrix * surface.vertex;
// if (dp > 0.0) {
// // Apply a slight bias to backfaces to avoid peter panning.
// // gl_Position.z *= 1.0 + 0.1*(1.0 - dp);
// gl_Position.z -= 0.01;
surface.vertex.xz += thickness * surface.expander;
// }

gl_Position = uLightMatrix * surface.vertex;

if (dp > 0.0) {
// Apply a slight bias to backfaces to avoid peter panning.
// gl_Position.z *= 1.0 + 0.1*(1.0 - dp);
gl_Position.z -= 0.05;
}
// else {
// // gl_Position.z += 0.004;
// }

vUV = Gloom_MapSurfaceTexCoord(surface);
vTSLightDir = Gloom_TangentMatrix(Gloom_SurfaceTangentSpace(surface)) * uLightDir;
vMaterial = surface.material;
Expand Down

0 comments on commit e7bd244

Please sign in to comment.