mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-28 15:57:59 +03:00
Cached reflection matrix of mirrors at load time;
Fixed lighting in mirrored items; Added bad cull mode after mirrore debrises drawing; Added mirroring of dynamic lights;
This commit is contained in:
parent
f44a04d057
commit
265283aacf
6 changed files with 39 additions and 17 deletions
|
@ -205,11 +205,11 @@ namespace TEN::Renderer
|
||||||
{
|
{
|
||||||
memcpy(&lights[index], &light, sizeof(ShaderLight));
|
memcpy(&lights[index], &light, sizeof(ShaderLight));
|
||||||
|
|
||||||
if (light.Hash == 0)
|
if (light.Hash != 0)
|
||||||
return;
|
{
|
||||||
|
lights[index].Position = Vector3::Lerp(light.PrevPosition, light.Position, GetInterpolationFactor());
|
||||||
lights[index].Position = Vector3::Lerp(light.PrevPosition, light.Position, GetInterpolationFactor());
|
lights[index].Direction = Vector3::Lerp(light.PrevDirection, light.Direction, GetInterpolationFactor());
|
||||||
lights[index].Direction = Vector3::Lerp(light.PrevDirection, light.Direction, GetInterpolationFactor());
|
}
|
||||||
|
|
||||||
if (mirror != nullptr)
|
if (mirror != nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1607,6 +1607,18 @@ namespace TEN::Renderer
|
||||||
|
|
||||||
StoreInterpolatedDynamicLightData(dynamicLight);
|
StoreInterpolatedDynamicLightData(dynamicLight);
|
||||||
_dynamicLights[_dynamicLightList].push_back(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)
|
||||||
|
@ -1633,6 +1645,17 @@ namespace TEN::Renderer
|
||||||
|
|
||||||
StoreInterpolatedDynamicLightData(dynamicLight);
|
StoreInterpolatedDynamicLightData(dynamicLight);
|
||||||
_dynamicLights[_dynamicLightList].push_back(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::StoreInterpolatedDynamicLightData(RendererLight& light)
|
||||||
|
|
|
@ -1495,7 +1495,7 @@ namespace TEN::Renderer
|
||||||
|
|
||||||
SetBlendMode(BlendMode::Opaque, true);
|
SetBlendMode(BlendMode::Opaque, true);
|
||||||
SetDepthState(DepthState::Write, true);
|
SetDepthState(DepthState::Write, true);
|
||||||
SetCullMode(CullMode::CounterClockwise, true);
|
SetCullMode(mirror != nullptr ? CullMode::Clockwise : CullMode::CounterClockwise, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,17 +36,7 @@ namespace TEN::Renderer
|
||||||
|
|
||||||
rendererMirror.RealRoom = mirror.RealRoom;
|
rendererMirror.RealRoom = mirror.RealRoom;
|
||||||
rendererMirror.VirtualRoom = mirror.VirtualRoom;
|
rendererMirror.VirtualRoom = mirror.VirtualRoom;
|
||||||
rendererMirror.Plane = Plane(
|
rendererMirror.ReflectionMatrix = mirror.ReflectionMatrix;
|
||||||
Vector3(mirror.MirrorPlane.x,
|
|
||||||
mirror.MirrorPlane.y,
|
|
||||||
mirror.MirrorPlane.z),
|
|
||||||
mirror.MirrorPlane.w);
|
|
||||||
|
|
||||||
Plane p = Plane(Vector3(mirror.MirrorPlane.x,
|
|
||||||
mirror.MirrorPlane.y,
|
|
||||||
mirror.MirrorPlane.z), Vector3(0, 0, BLOCK(21)));
|
|
||||||
|
|
||||||
rendererMirror.ReflectionMatrix = Matrix::CreateReflection(rendererMirror.Plane);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -1535,6 +1535,14 @@ void LoadMirrors()
|
||||||
mirror.MirrorPlane.y = ReadFloat();
|
mirror.MirrorPlane.y = ReadFloat();
|
||||||
mirror.MirrorPlane.z = ReadFloat();
|
mirror.MirrorPlane.z = ReadFloat();
|
||||||
mirror.MirrorPlane.w = ReadFloat();
|
mirror.MirrorPlane.w = ReadFloat();
|
||||||
|
|
||||||
|
Plane plane = Plane(
|
||||||
|
Vector3(mirror.MirrorPlane.x,
|
||||||
|
mirror.MirrorPlane.y,
|
||||||
|
mirror.MirrorPlane.z),
|
||||||
|
mirror.MirrorPlane.w);
|
||||||
|
|
||||||
|
mirror.ReflectionMatrix = Matrix::CreateReflection(plane);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@ struct MirrorInfo
|
||||||
short RealRoom;
|
short RealRoom;
|
||||||
short VirtualRoom;
|
short VirtualRoom;
|
||||||
Vector4 MirrorPlane;
|
Vector4 MirrorPlane;
|
||||||
|
Matrix ReflectionMatrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
// LevelData
|
// LevelData
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue