Revert "Formatting pass"

This reverts commit 88a8ba24de.
This commit is contained in:
Sezz 2024-12-25 18:12:43 +11:00
parent 88a8ba24de
commit becd24da93
14 changed files with 209 additions and 199 deletions

View file

@ -4,25 +4,20 @@
#include "Game/camera.h"
#include "Game/control/los.h"
#include "Game/effects/effects.h"
#include "Game/items.h"
#include "Game/Lara/lara.h"
#include "Game/Lara/lara_flare.h"
#include "Game/Lara/lara_helpers.h"
#include "Game/Lara/lara_one_gun.h"
#include "Game/Lara/lara_struct.h"
#include "Game/Lara/lara_one_gun.h"
#include "Game/Lara/lara_two_guns.h"
#include "Specific/Input/Input.h"
#include "Game/Setup.h"
#include "Scripting/Include/Flow/ScriptInterfaceFlowHandler.h"
#include "Specific/Input/Input.h"
using namespace TEN::Input;
static void HandlePlayerOpticZoom(ItemInfo& item)
{
constexpr auto OPTICS_RANGE_MAX = ANGLE(8.5f);
constexpr auto OPTICS_RANGE_MIN = ANGLE(0.7f);
constexpr auto OPTICS_RANGE_RATE = ANGLE(0.35f);
auto& player = GetLaraInfo(item);
bool isSlow = IsHeld(In::Walk);
@ -69,6 +64,7 @@ static void HandlePlayerOpticAnimations(ItemInfo& item)
return;
int animNumber = Objects[ID_LARA_BINOCULARS_MESH].loaded ? LA_BINOCULARS_IDLE : LA_STAND_IDLE;
if (player.Control.Look.IsUsingLasersight)
{
switch (player.Control.Weapon.GunType)
@ -99,8 +95,7 @@ static void HandlePlayerOpticAnimations(ItemInfo& item)
player.Torch.IsLit = false;
player.Flare.ControlLeft = false;
player.Flare.Life = 0;
player.Control.Weapon.GunType =
player.Control.Weapon.RequestGunType = player.Control.Weapon.LastGunType;
player.Control.Weapon.GunType = player.Control.Weapon.RequestGunType = player.Control.Weapon.LastGunType;
}
else if (player.Control.Weapon.GunType != LaraWeaponType::None &&
player.Control.HandStatus != HandStatus::Free)
@ -129,14 +124,10 @@ static void HandlePlayerOpticAnimations(ItemInfo& item)
player.Control.HandStatus = HandStatus::Free;
}
player.LeftArm.Locked =
player.RightArm.Locked = false;
player.LeftArm.FrameNumber =
player.RightArm.FrameNumber = 0;
player.LeftArm.AnimNumber =
player.RightArm.AnimNumber = animNumber;
player.LeftArm.FrameBase =
player.RightArm.FrameBase = GetAnimData(animNumber).FramePtr;
player.LeftArm.Locked = player.RightArm.Locked = false;
player.LeftArm.FrameNumber = player.RightArm.FrameNumber = 0;
player.LeftArm.AnimNumber = player.RightArm.AnimNumber = animNumber;
player.LeftArm.FrameBase = player.RightArm.FrameBase = GetAnimData(animNumber).FramePtr;
}
static void ResetPlayerOpticAnimations(ItemInfo& item)
@ -145,14 +136,10 @@ static void ResetPlayerOpticAnimations(ItemInfo& item)
ResetPlayerFlex(&item);
player.LeftArm.Locked =
player.RightArm.Locked = false;
player.LeftArm.AnimNumber =
player.RightArm.AnimNumber = 0;
player.LeftArm.FrameNumber =
player.RightArm.FrameNumber = 0;
player.RightArm.FrameBase =
player.LeftArm.FrameBase = GetAnimData(item).FramePtr;
player.LeftArm.Locked = player.RightArm.Locked = false;
player.LeftArm.AnimNumber = player.RightArm.AnimNumber = 0;
player.LeftArm.FrameNumber = player.RightArm.FrameNumber = 0;
player.RightArm.FrameBase = player.LeftArm.FrameBase = GetAnimData(item).FramePtr;
player.Control.HandStatus = player.Control.Look.IsUsingLasersight ? HandStatus::WeaponReady : HandStatus::Free;
if (!player.Control.Look.IsUsingLasersight)
@ -169,31 +156,32 @@ static void ResetPlayerOpticAnimations(ItemInfo& item)
SetScreenFadeIn(OPTICS_FADE_SPEED);
}
static void DoOpticsHighlight(const ItemInfo& item, const Vector3i& origin, const Vector3i& target)
static void DoOpticsHighlight(const ItemInfo& item, Vector3i* origin, Vector3i* target)
{
auto origin2 = GameVector(origin, item.RoomNumber);
auto target2 = GameVector(target);
auto pos1 = GameVector(*origin, item.RoomNumber);
auto pos2 = GameVector(*target);
const auto& binocularsColor = g_GameFlow->GetSettings()->Camera.BinocularLightColor;
const auto& binocularColor = g_GameFlow->GetSettings()->Camera.BinocularLightColor;
const auto& lasersightColor = g_GameFlow->GetSettings()->Camera.LasersightLightColor;
const auto& color = GetLaraInfo(item).Control.Look.IsUsingLasersight ? lasersightColor : binocularsColor;
const auto& color = GetLaraInfo(item).Control.Look.IsUsingLasersight ? lasersightColor : binocularColor;
TriggerDynamicLight(origin2.x, origin2.y, origin2.z, 12, color.GetR(), color.GetG(), color.GetB());
TriggerDynamicLight(pos1.x, pos1.y, pos1.z, 12, color.GetR(), color.GetG(), color.GetB());
if (!LOS(&origin2, &target2))
if (!LOS(&pos1, &pos2))
{
int luma = sqrt(SQUARE(origin2.x - target2.x) + SQUARE(origin2.y - target2.y) + SQUARE(origin2.z - target2.z)) * CLICK(1);
if ((luma + 8) > 31)
luma = 31;
int l = sqrt(pow(pos1.x - pos2.x, 2) + pow(pos1.y - pos2.y, 2) + pow(pos1.z - pos2.z, 2)) * CLICK(1);
auto dir = origin2.ToVector3() - target2.ToVector3();
if (l + 8 > 31)
l = 31;
auto dir = pos1.ToVector3() - pos2.ToVector3();
dir.Normalize();
dir *= BLOCK(1);
byte r = std::max(0, color.GetR() - luma);
byte g = std::max(0, color.GetG() - luma);
byte b = std::max(0, color.GetB() - luma);
TriggerDynamicLight(target2.x + dir.x, target2.y + dir.y, target2.z + dir.z, luma + 12, r, g, b);
byte r = std::max(0, color.GetR() - l);
byte g = std::max(0, color.GetG() - l);
byte b = std::max(0, color.GetB() - l);
TriggerDynamicLight(pos2.x + dir.x, pos2.y + dir.y, pos2.z + dir.z, l + 12, r, g, b);
}
}
@ -269,7 +257,7 @@ bool HandlePlayerOptics(ItemInfo& item)
auto origin = Camera.pos.ToVector3i();
auto target = Camera.target.ToVector3i();
DoOpticsHighlight(item, origin, target);
DoOpticsHighlight(item, &origin, &target);
}
if (!breakOptics)

View file

@ -1,10 +1,12 @@
#pragma once
#include "Specific/clock.h"
struct ItemInfo;
constexpr auto OPTICS_FADE_SPEED = 6.0f / FPS;
constexpr auto OPTICS_RANGE_DEFAULT = ANGLE(0.7f);
constexpr auto OPTICS_RANGE_MIN = ANGLE(0.7f);
constexpr auto OPTICS_RANGE_MAX = ANGLE(8.5f);
constexpr auto OPTICS_RANGE_RATE = ANGLE(0.35f);
bool HandlePlayerOptics(ItemInfo& item);

View file

@ -565,11 +565,11 @@ namespace TEN::Renderer
void CreateSSAONoiseTexture();
void InitializeSMAA();
bool IsRoomReflected(RenderView& renderView, int roomNumber);
bool RoomIsReflected(RenderView& renderView, int roomNumber);
inline bool IgnoreReflectionPassForRoom(int roomNumber)
inline bool IgnoreReflectionPassForRoom(int room)
{
return (_currentMirror != nullptr && roomNumber != _currentMirror->RoomNumber);
return (_currentMirror != nullptr && room != _currentMirror->RoomNumber);
}
inline void ReflectVectorOptionally(Vector3& vector)

View file

@ -561,9 +561,9 @@ namespace TEN::Renderer
if (rat->On)
{
auto* mesh = GetMesh(Objects[ID_RATS_EMITTER].meshIndex + (rand() % 8));
RendererMesh* mesh = GetMesh(Objects[ID_RATS_EMITTER].meshIndex + (rand() % 8));
auto world = rat->Transform;
Matrix world = rat->Transform;
ReflectMatrixOptionally(world);
_stStatic.World = world;
@ -571,7 +571,9 @@ namespace TEN::Renderer
_stStatic.AmbientLight = _rooms[rat->RoomNumber].AmbientLight;
if (rendererPass != RendererPass::GBuffer)
{
BindStaticLights(_rooms[rat->RoomNumber].LightsToDraw);
}
_cbStatic.UpdateData(_stStatic, _context.Get());
@ -777,7 +779,7 @@ namespace TEN::Renderer
auto transformMatrix = Matrix::Lerp(bat.PrevTransform, bat.Transform, GetInterpolationFactor());
auto world = transformMatrix;
Matrix world = transformMatrix;
ReflectMatrixOptionally(world);
_stInstancedStaticMeshBuffer.StaticMeshes[batCount].World = world;
@ -899,7 +901,7 @@ namespace TEN::Renderer
auto transformMatrix = Matrix::Lerp(beetle.PrevTransform, beetle.Transform, GetInterpolationFactor());
auto world = transformMatrix;
Matrix world = transformMatrix;
ReflectMatrixOptionally(world);
_stInstancedStaticMeshBuffer.StaticMeshes[beetleCount].World = world;
@ -1056,7 +1058,7 @@ namespace TEN::Renderer
auto& mesh = *GetMesh(Objects[ID_LOCUSTS].meshIndex + (-locust.counter & 3));
auto world = Matrix::Lerp(locust.PrevTransform, locust.Transform, GetInterpolationFactor());
Matrix world = Matrix::Lerp(locust.PrevTransform, locust.Transform, GetInterpolationFactor());
ReflectMatrixOptionally(world);
_stStatic.World = world;
@ -1596,7 +1598,7 @@ namespace TEN::Renderer
if (_isLocked || g_GameFlow->LastFreezeMode != FreezeMode::None)
return;
auto dynamicLight = RendererLight{};
RendererLight dynamicLight = {};
dynamicLight.Color = Vector3(color.x, color.y, color.z);
if (radius < BLOCK(2))
@ -1618,23 +1620,22 @@ namespace TEN::Renderer
void Renderer::PrepareDynamicLight(RendererLight& light)
{
// If hash is provided, search for same light in previous buffer.
// If hash is provided, search for same light in old buffer.
if (light.Hash != 0)
{
// Determine previous buffer index.
const auto& prevList = _dynamicLights[1 - _dynamicLightList];
// Determine the previous buffer index.
const auto& previousList = _dynamicLights[1 - _dynamicLightList];
// Find light in previous buffer with same hash.
auto it = std::find_if(
prevList.begin(), prevList.end(),
// Find a light in the previous buffer with the same Hash.
auto it = std::find_if(previousList.begin(), previousList.end(),
[&light](const auto& prevLight)
{
return (prevLight.Hash == light.Hash);
return prevLight.Hash == light.Hash;
});
if (it != prevList.end())
if (it != previousList.end())
{
// If matching light is found, copy it.
// If a matching light is found, copy its data.
const auto& prevLight = *it;
light.PrevPosition = prevLight.Position;
light.PrevDirection = prevLight.Direction;
@ -1644,17 +1645,16 @@ namespace TEN::Renderer
// Queue dynamic light.
_dynamicLights[_dynamicLightList].push_back(light);
// Check if light is spawned in mirrored room and create reflection.
for (const auto& mirror : g_Level.Mirrors)
// Check if light is spawned in a mirrored room, and create reflection.
for (auto& mirror : g_Level.Mirrors)
{
if (!mirror.ReflectLights)
continue;
// TODO: Avoid LaraItem global.
if ((Camera.pos.RoomNumber == mirror.RoomNumber || LaraItem->RoomNumber == mirror.RoomNumber) &&
IsPointInRoom(light.Position, mirror.RoomNumber))
{
auto reflectedLight = light;
RendererLight reflectedLight = light;
reflectedLight.Position = Vector3::Transform(light.Position, mirror.ReflectionMatrix);
reflectedLight.Direction = Vector3::Transform(light.Direction, mirror.ReflectionMatrix);
reflectedLight.Hash = 0;
@ -1886,7 +1886,7 @@ namespace TEN::Renderer
SortTransparentFaces(view);
DoRenderPass(RendererPass::Transparent, view, true);
DoRenderPass(RendererPass::GunFlashes, view, true); // HACK: Gunflashes are drawn after everything because they are near camera.
DoRenderPass(RendererPass::GunFlashes, view, true); // HACK: Gunflashes are drawn after everything because they are near the camera.
// Draw 3D debug lines and triangles.
DrawLines3D(view);
@ -2192,7 +2192,7 @@ namespace TEN::Renderer
SetCullMode(CullMode::CounterClockwise);
SetDepthState(DepthState::Write);
// Draw room geometry first if applicable for a given pass.
// Draw room geometry first, if applicable for a given pass.
if (pass != RendererPass::Transparent && pass != RendererPass::GunFlashes)
DrawRooms(view, pass);
@ -2206,10 +2206,9 @@ namespace TEN::Renderer
for (auto& mirror : view.Mirrors)
{
_currentMirror = &mirror;
DrawObjects(pass, view, mirror.ReflectPlayer, mirror.ReflectMoveables, mirror.ReflectStatics, mirror.ReflectSprites);
DrawObjects(pass, view, mirror.ReflectLara, mirror.ReflectMoveables, mirror.ReflectStatics, mirror.ReflectSprites);
_currentMirror = nullptr;
}
SetCullMode(CullMode::CounterClockwise);
}
}
@ -2252,7 +2251,7 @@ namespace TEN::Renderer
DrawDebris(view, pass); // Debris mostly originate from shatter statics.
}
// Sorted sprites already collected at beginning of frame.
// Sorted sprites are already collected at the beginning of frame.
if (sprites && pass != RendererPass::CollectTransparentFaces)
DrawSprites(view, pass);
@ -2513,14 +2512,14 @@ namespace TEN::Renderer
for (auto it = view.SortedStaticsToDraw.begin(); it != view.SortedStaticsToDraw.end(); it++)
{
auto statics = it->second;
std::vector<RendererStatic*> statics = it->second;
auto* refStatic = statics[0];
auto& refStaticObj = GetStaticRendererObject(refStatic->ObjectNumber);
RendererStatic* refStatic = statics[0];
RendererObject& refStaticObj = GetStaticRendererObject(refStatic->ObjectNumber);
if (refStaticObj.ObjectMeshes.size() == 0)
continue;
auto* refMesh = refStaticObj.ObjectMeshes[0];
RendererMesh* refMesh = refStaticObj.ObjectMeshes[0];
int staticsCount = (int)statics.size();
int bucketSize = INSTANCED_STATIC_MESH_BUCKET_SIZE;
@ -2533,13 +2532,13 @@ namespace TEN::Renderer
for (int s = baseStaticIndex; s < max; s++)
{
auto* current = statics[s];
auto* room = &_rooms[current->RoomNumber];
RendererStatic* current = statics[s];
RendererRoom* room = &_rooms[current->RoomNumber];
if (IgnoreReflectionPassForRoom(current->RoomNumber))
continue;
auto world = current->World;
Matrix world = current->World;
ReflectMatrixOptionally(world);
_stInstancedStaticMeshBuffer.StaticMeshes[instancesCount].World = world;
@ -2548,7 +2547,9 @@ namespace TEN::Renderer
_stInstancedStaticMeshBuffer.StaticMeshes[instancesCount].LightMode = (int)refMesh->LightMode;
if (rendererPass != RendererPass::GBuffer)
{
BindInstancedStaticLights(current->LightsToDraw, instancesCount);
}
instancesCount++;
}
@ -2559,16 +2560,21 @@ namespace TEN::Renderer
{
_cbInstancedStaticMeshBuffer.UpdateData(_stInstancedStaticMeshBuffer, _context.Get());
for (const auto& bucket : refMesh->Buckets)
for (auto& bucket : refMesh->Buckets)
{
if (bucket.NumVertices == 0)
{
continue;
}
int passes = rendererPass == RendererPass::Opaque && bucket.BlendMode == BlendMode::AlphaTest ? 2 : 1;
for (int p = 0; p < passes; p++)
{
if (!SetupBlendModeAndAlphaTest(bucket.BlendMode, rendererPass, p))
{
continue;
}
BindTexture(TextureRegister::ColorMap,
&std::get<0>(_staticTextures[bucket.Texture]),
@ -2588,17 +2594,18 @@ namespace TEN::Renderer
}
else
{
// Collect sorted blend modes faces ordered by room if doing transparent pass.
// Collect sorted blend modes faces ordered by room, if transparent pass
for (auto it = view.SortedStaticsToDraw.begin(); it != view.SortedStaticsToDraw.end(); it++)
{
auto statics = it->second;
std::vector<RendererStatic*> statics = it->second;
auto* refStatic = statics[0];
auto& refStaticObj = GetStaticRendererObject(refStatic->ObjectNumber);
RendererStatic* refStatic = statics[0];
RendererObject& refStaticObj = GetStaticRendererObject(refStatic->ObjectNumber);
if (refStaticObj.ObjectMeshes.size() == 0)
continue;
auto* refMesh = refStaticObj.ObjectMeshes[0];
RendererMesh* refMesh = refStaticObj.ObjectMeshes[0];
for (int i = 0; i < statics.size(); i++)
{
@ -2607,13 +2614,15 @@ namespace TEN::Renderer
auto& bucket = refMesh->Buckets[j];
if (bucket.NumVertices == 0)
{
continue;
}
if (IsSortedBlendMode(bucket.BlendMode))
{
for (int p = 0; p < bucket.Polygons.size(); p++)
{
auto object = RendererSortableObject{};
RendererSortableObject object;
object.ObjectType = RendererObjectType::Static;
object.Bucket = &bucket;
@ -3292,8 +3301,8 @@ namespace TEN::Renderer
{
for (int i = 0; i < view.TransparentObjectsToDraw.size(); i++)
{
auto* object = &view.TransparentObjectsToDraw[i];
auto lastObjectType = (i > 0 ? view.TransparentObjectsToDraw[i - 1].ObjectType : RendererObjectType::Unknown);
RendererSortableObject* object = &view.TransparentObjectsToDraw[i];
RendererObjectType lastObjectType = (i > 0 ? view.TransparentObjectsToDraw[i - 1].ObjectType : RendererObjectType::Unknown);
_sortedPolygonsVertices.clear();
_sortedPolygonsIndices.clear();
@ -3310,7 +3319,7 @@ namespace TEN::Renderer
view.TransparentObjectsToDraw[i].Bucket->BlendMode == object->Bucket->BlendMode &&
_sortedPolygonsIndices.size() + (view.TransparentObjectsToDraw[i].Polygon->Shape == 0 ? 6 : 3) < MAX_TRANSPARENT_VERTICES)
{
auto* currentObject = &view.TransparentObjectsToDraw[i];
RendererSortableObject* currentObject = &view.TransparentObjectsToDraw[i];
_sortedPolygonsIndices.bulk_push_back(
_roomsIndices.data(),
currentObject->Polygon->BaseIndex,
@ -3321,7 +3330,9 @@ namespace TEN::Renderer
DrawRoomSorted(object, lastObjectType, view);
if (i == view.TransparentObjectsToDraw.size())
{
return;
}
i--;
}
@ -3334,7 +3345,7 @@ namespace TEN::Renderer
view.TransparentObjectsToDraw[i].Bucket->BlendMode == object->Bucket->BlendMode &&
_sortedPolygonsIndices.size() + (view.TransparentObjectsToDraw[i].Polygon->Shape == 0 ? 6 : 3) < MAX_TRANSPARENT_VERTICES)
{
auto* currentObject = &view.TransparentObjectsToDraw[i];
RendererSortableObject* currentObject = &view.TransparentObjectsToDraw[i];
_sortedPolygonsIndices.bulk_push_back(
_moveablesIndices.data(),
currentObject->Polygon->BaseIndex,
@ -3345,7 +3356,9 @@ namespace TEN::Renderer
DrawItemSorted(object, lastObjectType, view);
if (i == view.TransparentObjectsToDraw.size())
{
return;
}
i--;
}
@ -3359,7 +3372,7 @@ namespace TEN::Renderer
view.TransparentObjectsToDraw[i].Bucket->BlendMode == object->Bucket->BlendMode &&
_sortedPolygonsIndices.size() + (view.TransparentObjectsToDraw[i].Polygon->Shape == 0 ? 6 : 3) < MAX_TRANSPARENT_VERTICES)
{
auto* currentObject = &view.TransparentObjectsToDraw[i];
RendererSortableObject* currentObject = &view.TransparentObjectsToDraw[i];
_sortedPolygonsIndices.bulk_push_back(
_staticsIndices.data(),
currentObject->Polygon->BaseIndex,
@ -3370,7 +3383,9 @@ namespace TEN::Renderer
DrawStaticSorted(object, lastObjectType, view);
if (i == view.TransparentObjectsToDraw.size())
{
return;
}
i--;
}
@ -3383,7 +3398,7 @@ namespace TEN::Renderer
view.TransparentObjectsToDraw[i].Bucket->BlendMode == object->Bucket->BlendMode &&
_sortedPolygonsIndices.size() + (view.TransparentObjectsToDraw[i].Polygon->Shape == 0 ? 6 : 3) < MAX_TRANSPARENT_VERTICES)
{
auto* currentObject = &view.TransparentObjectsToDraw[i];
RendererSortableObject* currentObject = &view.TransparentObjectsToDraw[i];
_sortedPolygonsIndices.bulk_push_back(
_staticsIndices.data(),
currentObject->Polygon->BaseIndex,
@ -3394,7 +3409,9 @@ namespace TEN::Renderer
DrawMoveableAsStaticSorted(object, lastObjectType, view);
if (i == view.TransparentObjectsToDraw.size())
{
return;
}
i--;
}
@ -3443,7 +3460,7 @@ namespace TEN::Renderer
uv2 = spr->Sprite->UV[2];
uv3 = spr->Sprite->UV[3];
auto world = GetWorldMatrixForSprite(currentObject->Sprite, view);
Matrix world = GetWorldMatrixForSprite(currentObject->Sprite, view);
Vertex v0;
v0.Position = Vector3::Transform(p0t, world);
@ -3620,7 +3637,7 @@ namespace TEN::Renderer
BindShader(_sStatics);
auto world = objectInfo->Static->World;
Matrix world = objectInfo->Static->World;
_stStatic.World = world;
_stStatic.Color = objectInfo->Static->Color;
@ -3658,7 +3675,7 @@ namespace TEN::Renderer
BindShader(_sStatics);
auto world = objectInfo->World;
Matrix world = objectInfo->World;
_stStatic.World = world;
_stStatic.Color = Vector4::One;

View file

@ -1285,23 +1285,19 @@ namespace TEN::Renderer
auto spriteMatrix = Matrix::Identity;
auto scaleMatrix = Matrix::CreateScale(sprite->Width * sprite->Scale, sprite->Height * sprite->Scale, sprite->Scale);
auto spritePos = sprite->pos;
Vector3 spritePosition = sprite->pos;
if (sprite->Type == SpriteType::ThreeD)
{
ReflectMatrixOptionally(spriteMatrix);
}
else
{
ReflectVectorOptionally(spritePos);
}
ReflectVectorOptionally(spritePosition);
switch (sprite->Type)
{
case SpriteType::Billboard:
{
auto cameraUp = Vector3(view.Camera.View._12, view.Camera.View._22, view.Camera.View._32);
spriteMatrix = scaleMatrix * Matrix::CreateRotationZ(sprite->Rotation) * Matrix::CreateBillboard(spritePos, Camera.pos.ToVector3(), cameraUp);
spriteMatrix = scaleMatrix * Matrix::CreateRotationZ(sprite->Rotation) * Matrix::CreateBillboard(spritePosition, Camera.pos.ToVector3(), cameraUp);
}
break;
@ -1310,7 +1306,7 @@ namespace TEN::Renderer
auto rotMatrix = Matrix::CreateRotationY(sprite->Rotation);
auto quadForward = Vector3(0.0f, 0.0f, 1.0f);
spriteMatrix = scaleMatrix * Matrix::CreateConstrainedBillboard(
spritePos,
spritePosition,
Camera.pos.ToVector3(),
sprite->ConstrainAxis,
nullptr,
@ -1320,9 +1316,9 @@ namespace TEN::Renderer
case SpriteType::LookAtBillboard:
{
auto translationMatrix = Matrix::CreateTranslation(spritePos);
auto tMatrix = Matrix::CreateTranslation(spritePosition);
auto rotMatrix = Matrix::CreateRotationZ(sprite->Rotation) * Matrix::CreateLookAt(Vector3::Zero, sprite->LookAtAxis, Vector3::UnitZ);
spriteMatrix = scaleMatrix * rotMatrix * translationMatrix;
spriteMatrix = scaleMatrix * rotMatrix * tMatrix;
}
break;
@ -1338,7 +1334,7 @@ namespace TEN::Renderer
{
const auto& room = _rooms[effect->RoomNumber];
auto world = effect->InterpolatedWorld;
Matrix world = effect->InterpolatedWorld;
ReflectMatrixOptionally(world);
_stStatic.World = world;

View file

@ -359,10 +359,9 @@ namespace TEN::Renderer
void Renderer::CollectMirrors(RenderView& renderView)
{
// Collect mirrors first because they are needed while collecting moveables.
for (const auto& mirror : g_Level.Mirrors)
// Collect mirrors first, because they are needed while collecting items
for (auto& mirror : g_Level.Mirrors)
{
// TODO: Avoid LaraItem global.
if (mirror.RoomNumber != Camera.pos.RoomNumber && mirror.RoomNumber != LaraItem->RoomNumber)
continue;
@ -370,9 +369,10 @@ namespace TEN::Renderer
continue;
auto& rendererMirror = renderView.Mirrors.emplace_back();
rendererMirror.RoomNumber = mirror.RoomNumber;
rendererMirror.ReflectionMatrix = mirror.ReflectionMatrix;
rendererMirror.ReflectPlayer = mirror.ReflectPlayer;
rendererMirror.ReflectLara = mirror.ReflectLara;
rendererMirror.ReflectMoveables = mirror.ReflectMoveables;
rendererMirror.ReflectStatics = mirror.ReflectStatics;
rendererMirror.ReflectSprites = mirror.ReflectSprites;
@ -385,100 +385,98 @@ namespace TEN::Renderer
if (_rooms.size() < roomNumber)
return;
auto& rendererRoom = _rooms[roomNumber];
const auto& room = g_Level.Rooms[rendererRoom.RoomNumber];
auto& room = _rooms[roomNumber];
auto* r = &g_Level.Rooms[room.RoomNumber];
bool isRoomReflected = IsRoomReflected(renderView, roomNumber);
bool roomIsReflected = RoomIsReflected(renderView, roomNumber);
short itemNumber = NO_VALUE;
for (itemNumber = room.itemNumber; itemNumber != NO_VALUE; itemNumber = g_Level.Items[itemNumber].NextItem)
short itemNum = NO_VALUE;
for (itemNum = r->itemNumber; itemNum != NO_VALUE; itemNum = g_Level.Items[itemNum].NextItem)
{
const auto& item = g_Level.Items[itemNumber];
auto* item = &g_Level.Items[itemNum];
if (item.ObjectNumber == ID_LARA && itemNumber == g_Level.Items[itemNumber].NextItem)
if (item->ObjectNumber == ID_LARA && itemNum == g_Level.Items[itemNum].NextItem)
break;
if (item.Status == ITEM_INVISIBLE)
if (item->Status == ITEM_INVISIBLE)
continue;
if (item.ObjectNumber == ID_LARA && (SpotcamOverlay || SpotcamDontDrawLara))
if (item->ObjectNumber == ID_LARA && (SpotcamOverlay || SpotcamDontDrawLara))
continue;
if (item.ObjectNumber == ID_LARA && CurrentLevel == 0 && !g_GameFlow->IsLaraInTitleEnabled())
if (item->ObjectNumber == ID_LARA && CurrentLevel == 0 && !g_GameFlow->IsLaraInTitleEnabled())
continue;
if (!_moveableObjects[item.ObjectNumber].has_value())
if (!_moveableObjects[item->ObjectNumber].has_value())
continue;
auto& obj = _moveableObjects[item.ObjectNumber].value();
auto& obj = _moveableObjects[item->ObjectNumber].value();
if (obj.DoNotDraw)
continue;
// Clip object by frustum only if it doesn't cast shadows and is not in mirror room,
// otherwise disappearing shadows or reflections may be seen if object gets out of frustum.
if (!isRoomReflected && obj.ShadowType == ShadowMode::None)
// Clip object by frustum only if it doesn't cast shadows and is not in the mirror room.
// Otherwise we may see disappearing shadows or reflections if object gets out of frustum.
if (!roomIsReflected && obj.ShadowType == ShadowMode::None)
{
// Get all spheres and check if frustum intersects any of them.
auto spheres = GetSpheres(itemNumber);
auto spheres = GetSpheres(itemNum);
bool inFrustum = false;
for (int i = 0; !inFrustum, i < spheres.size(); i++)
{
// Blow up sphere radius by half for cases of too small calculated spheres.
if (renderView.Camera.Frustum.SphereInFrustum(spheres[i].Center, spheres[i].Radius * 1.5f))
inFrustum = true;
}
if (!inFrustum)
continue;
}
auto newItem = _items[itemNumber];
auto newItem = &_items[itemNum];
newItem.ItemNumber = itemNumber;
newItem.ObjectID = item.ObjectNumber;
newItem.Color = item.Model.Color;
newItem.Position = item.Pose.Position.ToVector3();
newItem.Translation = Matrix::CreateTranslation(newItem.Position.x, newItem.Position.y, newItem.Position.z);
newItem.Rotation = item.Pose.Orientation.ToRotationMatrix();
newItem.Scale = Matrix::CreateScale(1.0f);
newItem.World = newItem.Rotation * newItem.Translation;
newItem->ItemNumber = itemNum;
newItem->ObjectID = item->ObjectNumber;
newItem->Color = item->Model.Color;
newItem->Position = item->Pose.Position.ToVector3();
newItem->Translation = Matrix::CreateTranslation(newItem->Position.x, newItem->Position.y, newItem->Position.z);
newItem->Rotation = item->Pose.Orientation.ToRotationMatrix();
newItem->Scale = Matrix::CreateScale(1.0f);
newItem->World = newItem->Rotation * newItem->Translation;
// Disable interpolation either when renderer slot or item slot has flag.
// Renderer slot has no interpolation flag set in case it is fetched for first time (e.g. item first time in frustum).
newItem.DisableInterpolation = item.DisableInterpolation || newItem.DisableInterpolation;
// Renderer slot has no interpolation flag set in case it is fetched for the first time (e.g. item first time in frustum).
newItem->DisableInterpolation = item->DisableInterpolation || newItem->DisableInterpolation;
if (newItem.DisableInterpolation)
if (newItem->DisableInterpolation)
{
// NOTE: Interpolation always returns same result.
newItem.PrevPosition = newItem.Position;
newItem.PrevTranslation = newItem.Translation;
newItem.PrevRotation = newItem.Rotation;
newItem.PrevWorld = newItem.World;
// NOTE: Interpolation alwasy returns same result.
newItem->PrevPosition = newItem->Position;
newItem->PrevTranslation = newItem->Translation;
newItem->PrevRotation = newItem->Rotation;
newItem->PrevWorld = newItem->World;
// Otherwise all frames until next ControlPhase will not be interpolated.
newItem.DisableInterpolation = false;
// Otherwise all frames until the next ControlPhase will not be interpolated.
newItem->DisableInterpolation = false;
for (int j = 0; j < MAX_BONES; j++)
newItem.PrevAnimTransforms[j] = newItem.AnimTransforms[j];
newItem->PrevAnimTransforms[j] = newItem->AnimTransforms[j];
}
// Force interpolation only for player in player freeze mode.
bool forceValue = g_GameFlow->CurrentFreezeMode == FreezeMode::Player && item.ObjectNumber == ID_LARA;
// Force interpolation only for Lara in player freeze mode.
bool forceValue = g_GameFlow->CurrentFreezeMode == FreezeMode::Player && item->ObjectNumber == ID_LARA;
newItem.InterpolatedPosition = Vector3::Lerp(newItem.PrevPosition, newItem.Position, GetInterpolationFactor(forceValue));
newItem.InterpolatedTranslation = Matrix::Lerp(newItem.PrevTranslation, newItem.Translation, GetInterpolationFactor(forceValue));
newItem.InterpolatedRotation = Matrix::Lerp(newItem.InterpolatedRotation, newItem.Rotation, GetInterpolationFactor(forceValue));
newItem.InterpolatedWorld = Matrix::Lerp(newItem.PrevWorld, newItem.World, GetInterpolationFactor(forceValue));
newItem->InterpolatedPosition = Vector3::Lerp(newItem->PrevPosition, newItem->Position, GetInterpolationFactor(forceValue));
newItem->InterpolatedTranslation = Matrix::Lerp(newItem->PrevTranslation, newItem->Translation, GetInterpolationFactor(forceValue));
newItem->InterpolatedRotation = Matrix::Lerp(newItem->InterpolatedRotation, newItem->Rotation, GetInterpolationFactor(forceValue));
newItem->InterpolatedWorld = Matrix::Lerp(newItem->PrevWorld, newItem->World, GetInterpolationFactor(forceValue));
for (int j = 0; j < MAX_BONES; j++)
newItem.InterpolatedAnimTransforms[j] = Matrix::Lerp(newItem.PrevAnimTransforms[j], newItem.AnimTransforms[j], GetInterpolationFactor(forceValue));
newItem->InterpolatedAnimTransforms[j] = Matrix::Lerp(newItem->PrevAnimTransforms[j], newItem->AnimTransforms[j], GetInterpolationFactor(forceValue));
CalculateLightFades(&newItem);
CollectLightsForItem(&newItem);
CalculateLightFades(newItem);
CollectLightsForItem(newItem);
rendererRoom.ItemsToDraw.push_back(&newItem);
room.ItemsToDraw.push_back(newItem);
}
}
@ -493,7 +491,7 @@ namespace TEN::Renderer
if (r->mesh.empty())
return;
bool roomIsReflected = IsRoomReflected(renderView, roomNumber);
bool roomIsReflected = RoomIsReflected(renderView, roomNumber);
for (int i = 0; i < room.Statics.size(); i++)
{

View file

@ -600,11 +600,10 @@ namespace TEN::Renderer
return rendererItem->BoneOrientations[boneID];
}
bool Renderer::IsRoomReflected(RenderView& renderView, int roomNumber)
bool Renderer::RoomIsReflected(RenderView& renderView, int roomNumber)
{
for (const auto& mirror : renderView.Mirrors)
for (auto& mirror : renderView.Mirrors)
{
// TODO: Avoid LaraItem global.
if (roomNumber == mirror.RoomNumber && (Camera.pos.RoomNumber == mirror.RoomNumber || LaraItem->RoomNumber == mirror.RoomNumber))
return true;
}

View file

@ -288,7 +288,6 @@ void Renderer::UpdateLaraAnimations(bool force)
void TEN::Renderer::Renderer::DrawLara(RenderView& view, RendererPass rendererPass)
{
// TODO: Avoid Lara global.
// Don't draw player if using optics (but still draw reflections).
if (Lara.Control.Look.OpticRange != 0 && _currentMirror == nullptr)
return;

View file

@ -129,6 +129,7 @@ namespace TEN::Renderer
DrawTriangles(3, 0);
_doingFullscreenPass = false;
}

View file

@ -1,17 +1,20 @@
#pragma once
#include <SimpleMath.h>
namespace TEN::Renderer::Structures
{
using namespace DirectX;
using namespace DirectX::SimpleMath;
struct RendererMirror
{
int RoomNumber = 0;
Plane Plane = SimpleMath::Plane();
Matrix ReflectionMatrix = Matrix::Identity;
bool ReflectPlayer = false;
bool ReflectMoveables = false;
bool ReflectStatics = false;
bool ReflectSprites = false;
bool ReflectLights = false;
short RoomNumber;
Plane Plane;
Matrix ReflectionMatrix;
bool ReflectLara;
bool ReflectMoveables;
bool ReflectStatics;
bool ReflectSprites;
bool ReflectLights;
};
}

View file

@ -1522,6 +1522,7 @@ void LoadBoxes()
void LoadMirrors()
{
int mirrorCount = ReadCount();
TENLog("Mirror count: " + std::to_string(mirrorCount), LogLevel::Info);
g_Level.Mirrors.reserve(mirrorCount);
@ -1529,20 +1530,27 @@ void LoadMirrors()
{
auto& mirror = g_Level.Mirrors.emplace_back();
mirror.RoomNumber = ReadInt16(); // TODO: Write Int32 to level instead. Short isn't used for room numbers anymore.
mirror.RoomNumber = ReadInt16();
mirror.Plane.x = ReadFloat();
mirror.Plane.y = ReadFloat();
mirror.Plane.z = ReadFloat();
mirror.Plane.w = ReadFloat();
mirror.ReflectPlayer = ReadBool();
mirror.ReflectLara = ReadBool();
mirror.ReflectMoveables = ReadBool();
mirror.ReflectStatics = ReadBool();
mirror.ReflectSprites = ReadBool();
mirror.ReflectLights = ReadBool();
mirror.Enabled = true;
mirror.ReflectionMatrix = Matrix::CreateReflection(mirror.Plane);
Plane plane = Plane(
Vector3(mirror.Plane.x,
mirror.Plane.y,
mirror.Plane.z),
mirror.Plane.w);
mirror.ReflectionMatrix = Matrix::CreateReflection(plane);
}
}

View file

@ -85,18 +85,17 @@ struct MESH
std::vector<BUCKET> buckets;
};
struct MirrorData
struct MirrorInfo
{
int RoomNumber = 0;
Plane Plane = SimpleMath::Plane();
Matrix ReflectionMatrix = Matrix::Identity;
bool Enabled = false;
bool ReflectPlayer = false;
bool ReflectMoveables = false;
bool ReflectStatics = false;
bool ReflectLights = false;
bool ReflectSprites = false;
short RoomNumber;
Vector4 Plane;
Matrix ReflectionMatrix;
bool ReflectLara;
bool ReflectMoveables;
bool ReflectStatics;
bool ReflectLights;
bool ReflectSprites;
bool Enabled;
};
// LevelData
@ -137,7 +136,7 @@ struct LEVEL
std::vector<int> LoopedEventSetIndices = {};
std::vector<AI_OBJECT> AIObjects = {};
std::vector<SPRITE> Sprites = {};
std::vector<MirrorData> Mirrors = {};
std::vector<MirrorInfo> Mirrors = {};
// Texture data
TEXTURE SkyTexture = {};