mirror of
https://github.com/ZDoom/ZDRay.git
synced 2024-11-10 06:41:37 +00:00
Fix issue with rays passing through 3d floor sides
This commit is contained in:
parent
ff91b34939
commit
11e2931548
5 changed files with 52 additions and 72 deletions
|
@ -178,6 +178,12 @@ enum SecPlaneType
|
|||
PLANE_CEILING,
|
||||
};
|
||||
|
||||
struct X3DFloor
|
||||
{
|
||||
IntSector* Sector = nullptr;
|
||||
IntLineDef* Line = nullptr;
|
||||
};
|
||||
|
||||
struct IntSector
|
||||
{
|
||||
// none of the sector properties are used by the node builder
|
||||
|
@ -200,7 +206,7 @@ struct IntSector
|
|||
int ceilinglightdef;
|
||||
|
||||
bool controlsector;
|
||||
TArray<IntSector*> x3dfloors;
|
||||
TArray<X3DFloor> x3dfloors;
|
||||
|
||||
bool HasLightmaps = false;
|
||||
|
||||
|
|
|
@ -656,7 +656,7 @@ void FLevel::PostLoadInitialization()
|
|||
{
|
||||
if (Sectors[j].tags[t] == sectorTag)
|
||||
{
|
||||
Sectors[j].x3dfloors.Push(controlsector);
|
||||
Sectors[j].x3dfloors.Push({ controlsector, line });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,8 +206,8 @@ void DoomLevelMesh::CreateSurfaces(FLevel& doomMap)
|
|||
|
||||
for (unsigned int j = 0; j < sector->x3dfloors.Size(); j++)
|
||||
{
|
||||
CreateFloorSurface(doomMap, sub, sector, sector->x3dfloors[j], i);
|
||||
CreateCeilingSurface(doomMap, sub, sector, sector->x3dfloors[j], i);
|
||||
CreateFloorSurface(doomMap, sub, sector, §or->x3dfloors[j], i);
|
||||
CreateCeilingSurface(doomMap, sub, sector, §or->x3dfloors[j], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -454,13 +454,13 @@ void DoomLevelMesh::Create3DFloorWallSurfaces(FLevel& doomMap, IntSideDef* side)
|
|||
|
||||
for (unsigned int j = 0; j < back->x3dfloors.Size(); j++)
|
||||
{
|
||||
IntSector* xfloor = back->x3dfloors[j];
|
||||
X3DFloor* xfloor = &back->x3dfloors[j];
|
||||
|
||||
// Don't create a line when both sectors have the same 3d floor
|
||||
bool bothSides = false;
|
||||
for (unsigned int k = 0; k < front->x3dfloors.Size(); k++)
|
||||
{
|
||||
if (front->x3dfloors[k] == xfloor)
|
||||
if (front->x3dfloors[k].Sector == xfloor->Sector)
|
||||
{
|
||||
bothSides = true;
|
||||
break;
|
||||
|
@ -473,13 +473,13 @@ void DoomLevelMesh::Create3DFloorWallSurfaces(FLevel& doomMap, IntSideDef* side)
|
|||
surf.Type = ST_MIDDLESIDE;
|
||||
surf.TypeIndex = side->Index(doomMap);
|
||||
surf.Side = side;
|
||||
surf.ControlSector = xfloor;
|
||||
surf.ControlSector = xfloor->Sector;
|
||||
surf.IsSky = false;
|
||||
|
||||
float v1Top = (float)xfloor->ceilingplane.ZatPoint(v1);
|
||||
float v1Bottom = (float)xfloor->floorplane.ZatPoint(v1);
|
||||
float v2Top = (float)xfloor->ceilingplane.ZatPoint(v2);
|
||||
float v2Bottom = (float)xfloor->floorplane.ZatPoint(v2);
|
||||
float v1Top = (float)xfloor->Sector->ceilingplane.ZatPoint(v1);
|
||||
float v1Bottom = (float)xfloor->Sector->floorplane.ZatPoint(v1);
|
||||
float v2Top = (float)xfloor->Sector->ceilingplane.ZatPoint(v2);
|
||||
float v2Bottom = (float)xfloor->Sector->floorplane.ZatPoint(v2);
|
||||
|
||||
FFlatVertex verts[4];
|
||||
verts[0].x = verts[2].x = v1.X;
|
||||
|
@ -492,7 +492,7 @@ void DoomLevelMesh::Create3DFloorWallSurfaces(FLevel& doomMap, IntSideDef* side)
|
|||
verts[3].z = v2Top;
|
||||
|
||||
surf.SectorGroup = sectorGroup[back->Index(doomMap)];
|
||||
surf.Texture = side->GetTexture(WallPart::MIDDLE);
|
||||
surf.Texture = xfloor->Line->sidedef[0]->GetTexture(WallPart::MIDDLE);
|
||||
|
||||
AddWallVertices(surf, verts);
|
||||
SetSideTextureUVs(surf, side, WallPart::TOP, v1Top, v1Bottom, v2Top, v2Bottom);
|
||||
|
@ -627,7 +627,7 @@ void DoomLevelMesh::SetSideTextureUVs(DoomLevelMeshSurface& surface, IntSideDef*
|
|||
}
|
||||
}
|
||||
|
||||
void DoomLevelMesh::CreateFloorSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, IntSector* controlSector, int typeIndex)
|
||||
void DoomLevelMesh::CreateFloorSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, X3DFloor* controlSector, int typeIndex)
|
||||
{
|
||||
DoomLevelMeshSurface surf;
|
||||
surf.Subsector = sub;
|
||||
|
@ -640,14 +640,14 @@ void DoomLevelMesh::CreateFloorSurface(FLevel& doomMap, MapSubsectorEx* sub, Int
|
|||
}
|
||||
else
|
||||
{
|
||||
plane = controlSector->ceilingplane;
|
||||
plane = controlSector->Sector->ceilingplane;
|
||||
plane.FlipVert();
|
||||
surf.IsSky = false;
|
||||
}
|
||||
|
||||
surf.MeshLocation.NumVerts = sub->numlines;
|
||||
surf.MeshLocation.StartVertIndex = Mesh.Vertices.Size();
|
||||
surf.Texture = (controlSector ? controlSector : sector)->GetTexture(PLANE_FLOOR);
|
||||
surf.Texture = (controlSector ? controlSector->Sector : sector)->GetTexture(PLANE_FLOOR);
|
||||
|
||||
FGameTexture* txt = TexMan.GetGameTexture(surf.Texture);
|
||||
float w = txt->GetDisplayWidth();
|
||||
|
@ -676,40 +676,28 @@ void DoomLevelMesh::CreateFloorSurface(FLevel& doomMap, MapSubsectorEx* sub, Int
|
|||
unsigned int startVertIndex = surf.MeshLocation.StartVertIndex;
|
||||
unsigned int numElements = 0;
|
||||
surf.MeshLocation.StartElementIndex = Mesh.Indexes.Size();
|
||||
if (!IsFacingUp(verts, surf.MeshLocation.NumVerts))
|
||||
for (int j = 2; j < surf.MeshLocation.NumVerts; j++)
|
||||
{
|
||||
for (int j = 2; j < surf.MeshLocation.NumVerts; j++)
|
||||
{
|
||||
Mesh.Indexes.Push(startVertIndex);
|
||||
Mesh.Indexes.Push(startVertIndex + j - 1);
|
||||
Mesh.Indexes.Push(startVertIndex + j);
|
||||
numElements += 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 2; j < surf.MeshLocation.NumVerts; j++)
|
||||
{
|
||||
Mesh.Indexes.Push(startVertIndex + j);
|
||||
Mesh.Indexes.Push(startVertIndex + j - 1);
|
||||
Mesh.Indexes.Push(startVertIndex);
|
||||
numElements += 3;
|
||||
}
|
||||
Mesh.Indexes.Push(startVertIndex);
|
||||
Mesh.Indexes.Push(startVertIndex + j - 1);
|
||||
Mesh.Indexes.Push(startVertIndex + j);
|
||||
numElements += 3;
|
||||
}
|
||||
|
||||
surf.MeshLocation.NumElements = numElements;
|
||||
surf.Bounds = GetBoundsFromSurface(surf);
|
||||
|
||||
surf.Type = ST_FLOOR;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.ControlSector = controlSector;
|
||||
surf.ControlSector = controlSector ? controlSector->Sector : nullptr;
|
||||
surf.Plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.d);
|
||||
surf.SectorGroup = sectorGroup[sector->Index(doomMap)];
|
||||
AddSurfaceToTile(surf, doomMap, (controlSector ? controlSector : sector)->sampleDistanceFloor);
|
||||
AddSurfaceToTile(surf, doomMap, (controlSector ? controlSector->Sector : sector)->sampleDistanceFloor);
|
||||
|
||||
Surfaces.Push(surf);
|
||||
}
|
||||
|
||||
void DoomLevelMesh::CreateCeilingSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, IntSector* controlSector, int typeIndex)
|
||||
void DoomLevelMesh::CreateCeilingSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, X3DFloor* controlSector, int typeIndex)
|
||||
{
|
||||
DoomLevelMeshSurface surf;
|
||||
surf.Subsector = sub;
|
||||
|
@ -722,14 +710,14 @@ void DoomLevelMesh::CreateCeilingSurface(FLevel& doomMap, MapSubsectorEx* sub, I
|
|||
}
|
||||
else
|
||||
{
|
||||
plane = controlSector->floorplane;
|
||||
plane = controlSector->Sector->floorplane;
|
||||
plane.FlipVert();
|
||||
surf.IsSky = false;
|
||||
}
|
||||
|
||||
surf.MeshLocation.NumVerts = sub->numlines;
|
||||
surf.MeshLocation.StartVertIndex = Mesh.Vertices.Size();
|
||||
surf.Texture = (controlSector ? controlSector : sector)->GetTexture(PLANE_CEILING);
|
||||
surf.Texture = (controlSector ? controlSector->Sector : sector)->GetTexture(PLANE_CEILING);
|
||||
|
||||
FGameTexture* txt = TexMan.GetGameTexture(surf.Texture);
|
||||
float w = txt->GetDisplayWidth();
|
||||
|
@ -758,35 +746,22 @@ void DoomLevelMesh::CreateCeilingSurface(FLevel& doomMap, MapSubsectorEx* sub, I
|
|||
unsigned int startVertIndex = surf.MeshLocation.StartVertIndex;
|
||||
unsigned int numElements = 0;
|
||||
surf.MeshLocation.StartElementIndex = Mesh.Indexes.Size();
|
||||
if (!IsFacingUp(verts, surf.MeshLocation.NumVerts))
|
||||
for (int j = 2; j < surf.MeshLocation.NumVerts; j++)
|
||||
{
|
||||
for (int j = 2; j < surf.MeshLocation.NumVerts; j++)
|
||||
{
|
||||
Mesh.Indexes.Push(startVertIndex + j);
|
||||
Mesh.Indexes.Push(startVertIndex + j - 1);
|
||||
Mesh.Indexes.Push(startVertIndex);
|
||||
numElements += 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 2; j < surf.MeshLocation.NumVerts; j++)
|
||||
{
|
||||
Mesh.Indexes.Push(startVertIndex);
|
||||
Mesh.Indexes.Push(startVertIndex + j - 1);
|
||||
Mesh.Indexes.Push(startVertIndex + j);
|
||||
numElements += 3;
|
||||
}
|
||||
Mesh.Indexes.Push(startVertIndex + j);
|
||||
Mesh.Indexes.Push(startVertIndex + j - 1);
|
||||
Mesh.Indexes.Push(startVertIndex);
|
||||
numElements += 3;
|
||||
}
|
||||
surf.MeshLocation.NumElements = numElements;
|
||||
surf.Bounds = GetBoundsFromSurface(surf);
|
||||
|
||||
surf.Type = ST_CEILING;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.ControlSector = controlSector;
|
||||
surf.ControlSector = controlSector ? controlSector->Sector : nullptr;
|
||||
surf.Plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.d);
|
||||
surf.SectorGroup = sectorGroup[sector->Index(doomMap)];
|
||||
AddSurfaceToTile(surf, doomMap, (controlSector ? controlSector : sector)->sampleDistanceCeiling);
|
||||
AddSurfaceToTile(surf, doomMap, (controlSector ? controlSector->Sector : sector)->sampleDistanceCeiling);
|
||||
|
||||
Surfaces.Push(surf);
|
||||
}
|
||||
|
|
|
@ -85,8 +85,8 @@ private:
|
|||
void AddWallVertices(DoomLevelMeshSurface& surf, FFlatVertex* verts);
|
||||
void SetSideTextureUVs(DoomLevelMeshSurface& surface, IntSideDef* side, WallPart texpart, float v1TopZ, float v1BottomZ, float v2TopZ, float v2BottomZ);
|
||||
|
||||
void CreateFloorSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, IntSector* controlSector, int typeIndex);
|
||||
void CreateCeilingSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, IntSector* controlSector, int typeIndex);
|
||||
void CreateFloorSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, X3DFloor* controlSector, int typeIndex);
|
||||
void CreateCeilingSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, X3DFloor* controlSector, int typeIndex);
|
||||
|
||||
void AddSurfaceToTile(DoomLevelMeshSurface& surf, FLevel& doomMap, uint16_t sampleDimension);
|
||||
int GetSampleDimension(const DoomLevelMeshSurface& surf, uint16_t sampleDimension);
|
||||
|
@ -109,18 +109,6 @@ private:
|
|||
void PropagateLight(FLevel& doomMap, ThingLight* light, int recursiveDepth);
|
||||
int GetLightIndex(ThingLight* light, int portalgroup);
|
||||
|
||||
static bool IsFacingUp(FFlatVertex* vertices, int count)
|
||||
{
|
||||
for (int i = 2; i < count; i++)
|
||||
{
|
||||
if (!IsDegenerate(vertices[i - 2].fPos(), vertices[i - 1].fPos(), vertices[i].fPos()))
|
||||
{
|
||||
return ToPlane(vertices[i - 2].fPos(), vertices[i - 1].fPos(), vertices[i].fPos()).Z >= 0.0f;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static FVector4 ToPlane(const FFlatVertex& pt1, const FFlatVertex& pt2, const FFlatVertex& pt3)
|
||||
{
|
||||
return ToPlane(FVector3(pt1.x, pt1.y, pt1.z), FVector3(pt2.x, pt2.y, pt2.z), FVector3(pt3.x, pt3.y, pt3.z));
|
||||
|
|
|
@ -39,6 +39,17 @@ void main()
|
|||
{
|
||||
incoming = SunColor;
|
||||
}
|
||||
|
||||
if (surface.TextureIndex != 0)
|
||||
{
|
||||
vec2 uv = GetSurfaceUV(result.primitiveIndex, result.primitiveWeights);
|
||||
vec4 color = texture(textures[surface.TextureIndex], uv);
|
||||
incoming *= color.rgb;
|
||||
}
|
||||
else
|
||||
{
|
||||
incoming = vec3(0.0, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue