mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-28 15:57:59 +03:00
Decopypaste more mirror-related code
This commit is contained in:
parent
60a59caa53
commit
569644f1d4
3 changed files with 82 additions and 107 deletions
|
@ -420,7 +420,7 @@ namespace TEN::Renderer
|
||||||
void ApplySMAA(RenderTarget2D* renderTarget, RenderView& view);
|
void ApplySMAA(RenderTarget2D* renderTarget, RenderView& view);
|
||||||
void ApplyFXAA(RenderTarget2D* renderTarget, RenderView& view);
|
void ApplyFXAA(RenderTarget2D* renderTarget, RenderView& view);
|
||||||
void BindTexture(TextureRegister registerType, TextureBase* texture, SamplerStateRegister samplerType);
|
void BindTexture(TextureRegister registerType, TextureBase* texture, SamplerStateRegister samplerType);
|
||||||
int BindLight(RendererLight& light, ShaderLight* lights, int index);
|
int BindLight(RendererLight& light, ShaderLight* lights, int index);
|
||||||
void BindRoomLights(std::vector<RendererLight*>& lights);
|
void BindRoomLights(std::vector<RendererLight*>& lights);
|
||||||
void BindStaticLights(std::vector<RendererLight*>& lights);
|
void BindStaticLights(std::vector<RendererLight*>& lights);
|
||||||
void BindInstancedStaticLights(std::vector<RendererLight*>& lights, int instanceID);
|
void BindInstancedStaticLights(std::vector<RendererLight*>& lights, int instanceID);
|
||||||
|
@ -433,6 +433,7 @@ namespace TEN::Renderer
|
||||||
void UpdateAnimation(RendererItem* item, RendererObject& obj, const AnimFrameInterpData& frameData, int mask, bool useObjectWorldRotation = false);
|
void UpdateAnimation(RendererItem* item, RendererObject& obj, const AnimFrameInterpData& frameData, int mask, bool useObjectWorldRotation = false);
|
||||||
bool CheckPortal(short parentRoomNumber, RendererDoor* door, Vector4 viewPort, Vector4* clipPort, RenderView& renderView);
|
bool CheckPortal(short parentRoomNumber, RendererDoor* door, Vector4 viewPort, Vector4* clipPort, RenderView& renderView);
|
||||||
void GetVisibleRooms(short from, short to, Vector4 viewPort, bool water, int count, bool onlyRooms, RenderView& renderView);
|
void GetVisibleRooms(short from, short to, Vector4 viewPort, bool water, int count, bool onlyRooms, RenderView& renderView);
|
||||||
|
void CollectMirrors(RenderView& renderView);
|
||||||
void CollectRooms(RenderView& renderView, bool onlyRooms);
|
void CollectRooms(RenderView& renderView, bool onlyRooms);
|
||||||
void CollectItems(short roomNumber, RenderView& renderView);
|
void CollectItems(short roomNumber, RenderView& renderView);
|
||||||
void CollectStatics(short roomNumber, RenderView& renderView);
|
void CollectStatics(short roomNumber, RenderView& renderView);
|
||||||
|
@ -452,6 +453,7 @@ namespace TEN::Renderer
|
||||||
void InitializeMenuBars(int y);
|
void InitializeMenuBars(int y);
|
||||||
void InitializeSky();
|
void InitializeSky();
|
||||||
void DrawAllStrings();
|
void DrawAllStrings();
|
||||||
|
void PrepareDynamicLight(RendererLight& light);
|
||||||
void PrepareLaserBarriers(RenderView& view);
|
void PrepareLaserBarriers(RenderView& view);
|
||||||
void PrepareSingleLaserBeam(RenderView& view);
|
void PrepareSingleLaserBeam(RenderView& view);
|
||||||
void DrawHorizonAndSky(RenderView& renderView, ID3D11DepthStencilView* depthTarget);
|
void DrawHorizonAndSky(RenderView& renderView, ID3D11DepthStencilView* depthTarget);
|
||||||
|
@ -575,6 +577,17 @@ namespace TEN::Renderer
|
||||||
void CreateSSAONoiseTexture();
|
void CreateSSAONoiseTexture();
|
||||||
void InitializeSMAA();
|
void InitializeSMAA();
|
||||||
|
|
||||||
|
inline bool RoomHasMirrors(RenderView& renderView, int roomNumber)
|
||||||
|
{
|
||||||
|
for (auto& mirror : renderView.Mirrors)
|
||||||
|
{
|
||||||
|
if (Camera.pos.RoomNumber == mirror.RealRoom && roomNumber == mirror.RealRoom)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool IgnoreMirrorPassForRoom(int room)
|
inline bool IgnoreMirrorPassForRoom(int room)
|
||||||
{
|
{
|
||||||
return (_currentMirror != nullptr && room != _currentMirror->RealRoom);
|
return (_currentMirror != nullptr && room != _currentMirror->RealRoom);
|
||||||
|
@ -663,7 +676,6 @@ namespace TEN::Renderer
|
||||||
void FreeRendererData();
|
void FreeRendererData();
|
||||||
void AddDynamicPointLight(const Vector3& pos, float radius, const Color& color, bool castShadows, int hash = 0);
|
void AddDynamicPointLight(const Vector3& pos, float radius, const Color& color, bool castShadows, int hash = 0);
|
||||||
void AddDynamicSpotLight(const Vector3& pos, const Vector3& dir, float radius, float falloff, float distance, const Color& color, bool castShadows, int hash = 0);
|
void AddDynamicSpotLight(const Vector3& pos, const Vector3& dir, float radius, float falloff, float distance, const Color& color, bool castShadows, int hash = 0);
|
||||||
void StoreInterpolatedDynamicLightData(RendererLight& light);
|
|
||||||
void RenderLoadingScreen(float percentage);
|
void RenderLoadingScreen(float percentage);
|
||||||
void RenderFreezeMode(float interpFactor, bool staticBackground);
|
void RenderFreezeMode(float interpFactor, bool staticBackground);
|
||||||
void UpdateProgress(float value);
|
void UpdateProgress(float value);
|
||||||
|
|
|
@ -1594,20 +1594,7 @@ namespace TEN::Renderer
|
||||||
dynamicLight.Luma = Luma(dynamicLight.Color);
|
dynamicLight.Luma = Luma(dynamicLight.Color);
|
||||||
dynamicLight.Hash = hash;
|
dynamicLight.Hash = hash;
|
||||||
|
|
||||||
StoreInterpolatedDynamicLightData(dynamicLight);
|
PrepareDynamicLight(dynamicLight);
|
||||||
_dynamicLights[_dynamicLightList].push_back(dynamicLight);
|
|
||||||
|
|
||||||
for (auto& mirror : g_Level.Mirrors)
|
|
||||||
{
|
|
||||||
if (Camera.pos.RoomNumber == mirror.RealRoom && IsPointInRoom(pos, mirror.RealRoom))
|
|
||||||
{
|
|
||||||
dynamicLight.Position = Vector3::Transform(pos, mirror.ReflectionMatrix);
|
|
||||||
dynamicLight.Direction = Vector3::Transform(dynamicLight.Direction, mirror.ReflectionMatrix);
|
|
||||||
dynamicLight.Hash = 0;
|
|
||||||
|
|
||||||
_dynamicLights[_dynamicLightList].push_back(dynamicLight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddDynamicPointLight(const Vector3& pos, float radius, const Color& color, bool castShadows, int hash)
|
void Renderer::AddDynamicPointLight(const Vector3& pos, float radius, const Color& color, bool castShadows, int hash)
|
||||||
|
@ -1632,44 +1619,48 @@ namespace TEN::Renderer
|
||||||
dynamicLight.Luma = Luma(dynamicLight.Color);
|
dynamicLight.Luma = Luma(dynamicLight.Color);
|
||||||
dynamicLight.Hash = hash;
|
dynamicLight.Hash = hash;
|
||||||
|
|
||||||
StoreInterpolatedDynamicLightData(dynamicLight);
|
PrepareDynamicLight(dynamicLight);
|
||||||
_dynamicLights[_dynamicLightList].push_back(dynamicLight);
|
|
||||||
|
|
||||||
for (auto& mirror : g_Level.Mirrors)
|
|
||||||
{
|
|
||||||
if (Camera.pos.RoomNumber == mirror.RealRoom && IsPointInRoom(pos, mirror.RealRoom))
|
|
||||||
{
|
|
||||||
dynamicLight.Position = Vector3::Transform(pos, mirror.ReflectionMatrix);
|
|
||||||
dynamicLight.Hash = 0;
|
|
||||||
|
|
||||||
_dynamicLights[_dynamicLightList].push_back(dynamicLight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::StoreInterpolatedDynamicLightData(RendererLight& light)
|
void Renderer::PrepareDynamicLight(RendererLight& light)
|
||||||
{
|
{
|
||||||
// Hash is not provided, do not search for same light in old buffer.
|
// If hash is provided, search for same light in old buffer.
|
||||||
if (light.Hash == 0)
|
if (light.Hash != 0)
|
||||||
return;
|
{
|
||||||
|
// Determine the previous buffer index.
|
||||||
|
const auto& previousList = _dynamicLights[1 - _dynamicLightList];
|
||||||
|
|
||||||
// Determine the previous buffer index.
|
// Find a light in the previous buffer with the same Hash.
|
||||||
const auto& previousList = _dynamicLights[1 - _dynamicLightList];
|
auto it = std::find_if(previousList.begin(), previousList.end(),
|
||||||
|
[&light](const auto& prevLight)
|
||||||
|
{
|
||||||
|
return prevLight.Hash == light.Hash;
|
||||||
|
});
|
||||||
|
|
||||||
// Find a light in the previous buffer with the same Hash.
|
if (it == previousList.end())
|
||||||
auto it = std::find_if(previousList.begin(), previousList.end(),
|
return;
|
||||||
[&light](const auto& prevLight)
|
|
||||||
|
// If a matching light is found, copy its data.
|
||||||
|
const auto& prevLight = *it;
|
||||||
|
light.PrevPosition = prevLight.Position;
|
||||||
|
light.PrevDirection = prevLight.Direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue dynamic light.
|
||||||
|
_dynamicLights[_dynamicLightList].push_back(light);
|
||||||
|
|
||||||
|
// Check if light is spawned in a mirrored room, and create reflection.
|
||||||
|
for (auto& mirror : g_Level.Mirrors)
|
||||||
|
{
|
||||||
|
if (Camera.pos.RoomNumber == mirror.RealRoom && IsPointInRoom(light.Position, mirror.RealRoom))
|
||||||
{
|
{
|
||||||
return prevLight.Hash == light.Hash;
|
light.Position = Vector3::Transform(light.Position, mirror.ReflectionMatrix);
|
||||||
});
|
light.Direction = Vector3::Transform(light.Direction, mirror.ReflectionMatrix);
|
||||||
|
light.Hash = 0;
|
||||||
|
|
||||||
if (it == previousList.end())
|
_dynamicLights[_dynamicLightList].push_back(light);
|
||||||
return;
|
}
|
||||||
|
}
|
||||||
// If a matching light is found, copy its data.
|
|
||||||
const auto& prevLight = *it;
|
|
||||||
light.PrevPosition = prevLight.Position;
|
|
||||||
light.PrevDirection = prevLight.Direction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::PrepareScene()
|
void Renderer::PrepareScene()
|
||||||
|
@ -1728,6 +1719,7 @@ namespace TEN::Renderer
|
||||||
|
|
||||||
// Prepare scene to draw.
|
// Prepare scene to draw.
|
||||||
auto time1 = std::chrono::high_resolution_clock::now();
|
auto time1 = std::chrono::high_resolution_clock::now();
|
||||||
|
CollectMirrors(view);
|
||||||
CollectRooms(view, false);
|
CollectRooms(view, false);
|
||||||
auto time = std::chrono::high_resolution_clock::now();
|
auto time = std::chrono::high_resolution_clock::now();
|
||||||
_timeRoomsCollector = (std::chrono::duration_cast<ns>(time - time1)).count() / 1000000;
|
_timeRoomsCollector = (std::chrono::duration_cast<ns>(time - time1)).count() / 1000000;
|
||||||
|
|
|
@ -27,25 +27,6 @@ namespace TEN::Renderer
|
||||||
|
|
||||||
void Renderer::CollectRooms(RenderView& renderView, bool onlyRooms)
|
void Renderer::CollectRooms(RenderView& renderView, bool onlyRooms)
|
||||||
{
|
{
|
||||||
// Collect mirrors first, because they are needed while collecting items
|
|
||||||
for (auto& mirror : g_Level.Mirrors)
|
|
||||||
{
|
|
||||||
if (mirror.RealRoom != Camera.pos.RoomNumber)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!mirror.Enabled)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto& rendererMirror = renderView.Mirrors.emplace_back();
|
|
||||||
|
|
||||||
rendererMirror.RealRoom = mirror.RealRoom;
|
|
||||||
rendererMirror.ReflectionMatrix = mirror.ReflectionMatrix;
|
|
||||||
rendererMirror.ReflectLara = mirror.ReflectLara;
|
|
||||||
rendererMirror.ReflectMoveables = mirror.ReflectMoveables;
|
|
||||||
rendererMirror.ReflectStatics = mirror.ReflectStatics;
|
|
||||||
rendererMirror.ReflectLights = mirror.ReflectLights;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr auto VIEW_PORT = Vector4(-1.0f, -1.0f, 1.0f, 1.0f);
|
constexpr auto VIEW_PORT = Vector4(-1.0f, -1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
_visitedRoomsStack.clear();
|
_visitedRoomsStack.clear();
|
||||||
|
@ -376,6 +357,28 @@ namespace TEN::Renderer
|
||||||
_visitedRoomsStack.pop_back();
|
_visitedRoomsStack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::CollectMirrors(RenderView& renderView)
|
||||||
|
{
|
||||||
|
// Collect mirrors first, because they are needed while collecting items
|
||||||
|
for (auto& mirror : g_Level.Mirrors)
|
||||||
|
{
|
||||||
|
if (mirror.RealRoom != Camera.pos.RoomNumber)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!mirror.Enabled)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto& rendererMirror = renderView.Mirrors.emplace_back();
|
||||||
|
|
||||||
|
rendererMirror.RealRoom = mirror.RealRoom;
|
||||||
|
rendererMirror.ReflectionMatrix = mirror.ReflectionMatrix;
|
||||||
|
rendererMirror.ReflectLara = mirror.ReflectLara;
|
||||||
|
rendererMirror.ReflectMoveables = mirror.ReflectMoveables;
|
||||||
|
rendererMirror.ReflectStatics = mirror.ReflectStatics;
|
||||||
|
rendererMirror.ReflectLights = mirror.ReflectLights;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::CollectItems(short roomNumber, RenderView& renderView)
|
void Renderer::CollectItems(short roomNumber, RenderView& renderView)
|
||||||
{
|
{
|
||||||
if (_rooms.size() < roomNumber)
|
if (_rooms.size() < roomNumber)
|
||||||
|
@ -384,6 +387,8 @@ namespace TEN::Renderer
|
||||||
auto& room = _rooms[roomNumber];
|
auto& room = _rooms[roomNumber];
|
||||||
auto* r = &g_Level.Rooms[room.RoomNumber];
|
auto* r = &g_Level.Rooms[room.RoomNumber];
|
||||||
|
|
||||||
|
bool roomHasMirrors = RoomHasMirrors(renderView, roomNumber);
|
||||||
|
|
||||||
short itemNum = NO_VALUE;
|
short itemNum = NO_VALUE;
|
||||||
for (itemNum = r->itemNumber; itemNum != NO_VALUE; itemNum = g_Level.Items[itemNum].NextItem)
|
for (itemNum = r->itemNumber; itemNum != NO_VALUE; itemNum = g_Level.Items[itemNum].NextItem)
|
||||||
{
|
{
|
||||||
|
@ -409,20 +414,9 @@ namespace TEN::Renderer
|
||||||
if (obj.DoNotDraw)
|
if (obj.DoNotDraw)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Clip object by frustum only if it doesn't cast shadows. Otherwise we may see
|
// Clip object by frustum only if it doesn't cast shadows and is not in the mirror room.
|
||||||
// disappearing shadows if object gets out of frustum.
|
// Otherwise we may see disappearing shadows or reflections if object gets out of frustum.
|
||||||
|
if (!roomHasMirrors && obj.ShadowType == ShadowMode::None)
|
||||||
bool isMirrorRoom = false;
|
|
||||||
for (auto& mirror : g_Level.Mirrors)
|
|
||||||
{
|
|
||||||
if (Camera.pos.RoomNumber == mirror.RealRoom)
|
|
||||||
{
|
|
||||||
isMirrorRoom = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.ShadowType == ShadowMode::None && !isMirrorRoom)
|
|
||||||
{
|
{
|
||||||
// Get all spheres and check if frustum intersects any of them.
|
// Get all spheres and check if frustum intersects any of them.
|
||||||
auto spheres = GetSpheres(itemNum);
|
auto spheres = GetSpheres(itemNum);
|
||||||
|
@ -496,6 +490,8 @@ namespace TEN::Renderer
|
||||||
if (r->mesh.empty())
|
if (r->mesh.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool roomHasMirrors = RoomHasMirrors(renderView, roomNumber);
|
||||||
|
|
||||||
for (int i = 0; i < room.Statics.size(); i++)
|
for (int i = 0; i < room.Statics.size(); i++)
|
||||||
{
|
{
|
||||||
auto* mesh = &room.Statics[i];
|
auto* mesh = &room.Statics[i];
|
||||||
|
@ -524,21 +520,8 @@ namespace TEN::Renderer
|
||||||
if (obj.ObjectMeshes.empty())
|
if (obj.ObjectMeshes.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool isMirrorRoom = false;
|
if (!roomHasMirrors && !renderView.Camera.Frustum.SphereInFrustum(mesh->Sphere.Center, mesh->Sphere.Radius))
|
||||||
for (auto& mirror : g_Level.Mirrors)
|
continue;
|
||||||
{
|
|
||||||
if (Camera.pos.RoomNumber == mirror.RealRoom)
|
|
||||||
{
|
|
||||||
isMirrorRoom = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isMirrorRoom)
|
|
||||||
{
|
|
||||||
if (!renderView.Camera.Frustum.SphereInFrustum(mesh->Sphere.Center, mesh->Sphere.Radius))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect the lights
|
// Collect the lights
|
||||||
std::vector<RendererLight*> lights;
|
std::vector<RendererLight*> lights;
|
||||||
|
@ -761,22 +744,10 @@ namespace TEN::Renderer
|
||||||
void Renderer::CollectLightsForRoom(short roomNumber, RenderView &renderView)
|
void Renderer::CollectLightsForRoom(short roomNumber, RenderView &renderView)
|
||||||
{
|
{
|
||||||
if (_rooms.size() < roomNumber)
|
if (_rooms.size() < roomNumber)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
RendererRoom& room = _rooms[roomNumber];
|
RendererRoom& room = _rooms[roomNumber];
|
||||||
ROOM_INFO* r = &g_Level.Rooms[roomNumber];
|
ROOM_INFO* r = &g_Level.Rooms[roomNumber];
|
||||||
|
|
||||||
bool isMirrorRoom = false;
|
|
||||||
for (auto& mirror : renderView.Mirrors)
|
|
||||||
{
|
|
||||||
if (mirror.RealRoom == roomNumber)
|
|
||||||
{
|
|
||||||
isMirrorRoom = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect dynamic lights for rooms
|
// Collect dynamic lights for rooms
|
||||||
for (int i = 0; i < _dynamicLights[_dynamicLightList].size(); i++)
|
for (int i = 0; i < _dynamicLights[_dynamicLightList].size(); i++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue