diff --git a/Source/Engine/Core/Math/Rectangle.h b/Source/Engine/Core/Math/Rectangle.h index db6813684..13d6dae39 100644 --- a/Source/Engine/Core/Math/Rectangle.h +++ b/Source/Engine/Core/Math/Rectangle.h @@ -57,6 +57,15 @@ public: { } + /// + /// Initializes a new instance of the struct. + /// + /// The location and size packed. + Rectangle(const Float4& packed) + { + Platform::MemoryCopy(this, &packed, sizeof(*this)); + } + public: String ToString() const; diff --git a/Source/Engine/Foliage/Foliage.cpp b/Source/Engine/Foliage/Foliage.cpp index 633a3909b..cb077f880 100644 --- a/Source/Engine/Foliage/Foliage.cpp +++ b/Source/Engine/Foliage/Foliage.cpp @@ -5,6 +5,7 @@ #include "FoliageCluster.h" #include "Engine/Core/Log.h" #include "Engine/Core/Random.h" +#include "Engine/Core/Math/Rectangle.h" #include "Engine/Core/Collections/BitArray.h" #include "Engine/Engine/Engine.h" #include "Engine/Graphics/Graphics.h" @@ -17,6 +18,7 @@ #endif #include "Engine/Level/SceneQuery.h" #include "Engine/Profiler/ProfilerCPU.h" +#include "Engine/Profiler/ProfilerMemory.h" #include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/GlobalSignDistanceFieldPass.h" #include "Engine/Renderer/GI/GlobalSurfaceAtlasPass.h" @@ -140,7 +142,7 @@ void Foliage::DrawInstance(DrawContext& context, FoliageInstance& instance, Mode DrawKey key; key.Mat = drawCall.Material; key.Geo = &meshes.Get()[meshIndex]; - key.Lightmap = instance.Lightmap.TextureIndex; + key.Lightmap = instance.LightmapTextureIndex; auto* e = result.TryGet(key); if (!e) { @@ -158,7 +160,7 @@ void Foliage::DrawInstance(DrawContext& context, FoliageInstance& instance, Mode const Float3 translation = transform.Translation - context.ViewOrigin; Matrix::Transformation(transform.Scale, transform.Orientation, translation, world); constexpr float worldDeterminantSign = 1.0f; - instanceData.Store(world, world, instance.Lightmap.UVsArea, drawCall.Surface.GeometrySize, instance.Random, worldDeterminantSign, lodDitherFactor); + instanceData.Store(world, world, instance.LightmapUVsArea, drawCall.Surface.GeometrySize, instance.Random, worldDeterminantSign, lodDitherFactor); } } @@ -351,7 +353,7 @@ void Foliage::DrawCluster(DrawContext& context, FoliageCluster* cluster, Mesh::D instance.DrawState.PrevWorld = world; // Draw model - draw.Lightmap = _scene->LightmapsData.GetReadyLightmap(instance.Lightmap.TextureIndex); + draw.Lightmap = _scene->LightmapsData.GetReadyLightmap(instance.LightmapTextureIndex); draw.LightmapUVs = &instance.Lightmap.UVsArea; draw.Buffer = &type.Entries; draw.World = &world; @@ -1267,8 +1269,8 @@ void Foliage::Draw(RenderContext& renderContext) draw.ForcedLOD = -1; draw.SortOrder = 0; draw.VertexColors = nullptr; - draw.Lightmap = _scene ? _scene->LightmapsData.GetReadyLightmap(instance.Lightmap.TextureIndex) : nullptr; - draw.LightmapUVs = &instance.Lightmap.UVsArea; + draw.Lightmap = _scene ? _scene->LightmapsData.GetReadyLightmap(instance.LightmapTextureIndex) : nullptr; + draw.LightmapUVs = &instance.LightmapUVsArea; draw.Buffer = &type.Entries; draw.World = &world; draw.DrawState = &instance.DrawState; @@ -1367,7 +1369,8 @@ struct InstanceEncoded2 Float3 Translation; Quaternion Orientation; Float3 Scale; - LightmapEntry Lightmap; + int32 LightmapTextureIndex; + Rectangle LightmapUVsArea; static const int32 Size = 68; static const int32 Base64Size = GetInstanceBase64Size(Size); @@ -1435,7 +1438,10 @@ struct FoliageWriter // Lightmap data (if used) if (data.HasLightmap) - Memory.Write(instance.Lightmap); + { + Memory.Write(instance.LightmapTextureIndex); + Memory.Write(instance.LightmapUVsArea); + } // Move to the next instance InstanceCounter++; @@ -1519,7 +1525,10 @@ struct FoliageReader q.Normalize(); instance.Transform.Orientation = q; if (data.HasLightmap) - memory.Read(instance.Lightmap); + { + memory.Read(instance.LightmapTextureIndex); + memory.Read(instance.LightmapUVsArea); + } } } }; @@ -1656,7 +1665,7 @@ void Foliage::Deserialize(DeserializeStream& stream, ISerializeModifier* modifie instance.Transform.Translation = enc.Translation; instance.Transform.Orientation = enc.Orientation; instance.Transform.Scale = enc.Scale; - instance.Lightmap = LightmapEntry(); + instance.LightmapTextureIndex = -1; } } else @@ -1680,7 +1689,8 @@ void Foliage::Deserialize(DeserializeStream& stream, ISerializeModifier* modifie instance.Transform.Translation = enc.Translation; instance.Transform.Orientation = enc.Orientation; instance.Transform.Scale = enc.Scale; - instance.Lightmap = enc.Lightmap; + instance.LightmapTextureIndex = enc.LightmapTextureIndex; + instance.LightmapUVsArea = Half4(enc.LightmapUVsArea); } } } diff --git a/Source/Engine/Foliage/FoliageInstance.h b/Source/Engine/Foliage/FoliageInstance.h index 76037f0f4..7cd5d51ba 100644 --- a/Source/Engine/Foliage/FoliageInstance.h +++ b/Source/Engine/Foliage/FoliageInstance.h @@ -4,6 +4,7 @@ #include "Engine/Core/Math/Transform.h" #include "Engine/Core/Math/BoundingSphere.h" +#include "Engine/Core/Math/Half.h" #include "Engine/Renderer/DrawCall.h" #include "Engine/Level/Scene/Lightmap.h" @@ -29,6 +30,11 @@ API_STRUCT(NoPod) struct FLAXENGINE_API FoliageInstance /// API_FIELD() int32 Type; + /// + /// The lightmap index for the foliage instance. -1 if unused. + /// + int8 LightmapTextureIndex; + /// /// The per-instance random value from range [0;1]. /// @@ -45,9 +51,9 @@ API_STRUCT(NoPod) struct FLAXENGINE_API FoliageInstance API_FIELD() BoundingSphere Bounds; /// - /// The lightmap entry for the foliage instance. + /// Lightmap UVs area that entry occupies (packed Rectangle into Half4). /// - LightmapEntry Lightmap; + Half4 LightmapUVsArea; public: bool operator==(const FoliageInstance& v) const @@ -60,7 +66,7 @@ public: /// FORCE_INLINE bool HasLightmap() const { - return Lightmap.TextureIndex != INVALID_INDEX; + return LightmapTextureIndex != INVALID_INDEX; } /// @@ -68,6 +74,6 @@ public: /// FORCE_INLINE void RemoveLightmap() { - Lightmap.TextureIndex = INVALID_INDEX; + LightmapTextureIndex = INVALID_INDEX; } }; diff --git a/Source/Engine/Graphics/Models/Mesh.cpp b/Source/Engine/Graphics/Models/Mesh.cpp index c2f340645..83545e42e 100644 --- a/Source/Engine/Graphics/Models/Mesh.cpp +++ b/Source/Engine/Graphics/Models/Mesh.cpp @@ -305,7 +305,7 @@ void Mesh::Draw(const RenderContext& renderContext, const DrawInfo& info, float drawCall.Surface.GeometrySize = _box.GetSize(); drawCall.Surface.PrevWorld = info.DrawState->PrevWorld; drawCall.Surface.Lightmap = (info.Flags & StaticFlags::Lightmap) != StaticFlags::None ? info.Lightmap : nullptr; - drawCall.Surface.LightmapUVsArea = info.LightmapUVs ? *info.LightmapUVs : Rectangle::Empty; + drawCall.Surface.LightmapUVsArea = info.LightmapUVs ? *info.LightmapUVs : Half4::Zero; drawCall.Surface.LODDitherFactor = lodDitherFactor; drawCall.PerInstanceRandom = info.PerInstanceRandom; drawCall.StencilValue = info.StencilValue; @@ -368,7 +368,7 @@ void Mesh::Draw(const RenderContextBatch& renderContextBatch, const DrawInfo& in drawCall.Surface.GeometrySize = _box.GetSize(); drawCall.Surface.PrevWorld = info.DrawState->PrevWorld; drawCall.Surface.Lightmap = (info.Flags & StaticFlags::Lightmap) != StaticFlags::None ? info.Lightmap : nullptr; - drawCall.Surface.LightmapUVsArea = info.LightmapUVs ? *info.LightmapUVs : Rectangle::Empty; + drawCall.Surface.LightmapUVsArea = info.LightmapUVs ? *info.LightmapUVs : Half4::Zero; drawCall.Surface.LODDitherFactor = lodDitherFactor; drawCall.PerInstanceRandom = info.PerInstanceRandom; drawCall.StencilValue = info.StencilValue; diff --git a/Source/Engine/Graphics/Models/MeshBase.h b/Source/Engine/Graphics/Models/MeshBase.h index cb51f466b..2221782d1 100644 --- a/Source/Engine/Graphics/Models/MeshBase.h +++ b/Source/Engine/Graphics/Models/MeshBase.h @@ -375,7 +375,7 @@ public: /// /// The lightmap UVs. /// - const Rectangle* LightmapUVs; + const Half4* LightmapUVs; }; }; diff --git a/Source/Engine/Level/Actors/StaticModel.cpp b/Source/Engine/Level/Actors/StaticModel.cpp index 1fba1ba2e..727a14000 100644 --- a/Source/Engine/Level/Actors/StaticModel.cpp +++ b/Source/Engine/Level/Actors/StaticModel.cpp @@ -1,6 +1,7 @@ // Copyright (c) Wojciech Figat. All rights reserved. #include "StaticModel.h" +#include "Engine/Core/Math/Rectangle.h" #include "Engine/Engine/Engine.h" #include "Engine/Content/Deprecated.h" #include "Engine/Graphics/GPUBuffer.h" @@ -20,6 +21,31 @@ #include "Editor/Editor.h" #endif +void LightmapEntry::Serialize(ISerializable::SerializeStream& stream) +{ + stream.JKEY("LightmapIndex"); + stream.Int(TextureIndex); + + stream.JKEY("LightmapArea"); + stream.Rectangle(UVsArea.ToFloat4()); +} + +void LightmapEntry::Deserialize(ISerializable::DeserializeStream& stream) +{ + ISerializeModifier* modifier = nullptr; + + DESERIALIZE_MEMBER(LightmapIndex, TextureIndex); + { + const auto e = SERIALIZE_FIND_MEMBER(stream, "LightmapArea"); + if (e != stream.MemberEnd()) + { + Rectangle rect; + Serialization::Deserialize(e->value, rect, nullptr); + UVsArea = Half4(rect); + } + } +} + StaticModel::StaticModel(const SpawnParams& params) : ModelInstanceActor(params) , _scaleInLightmap(1.0f) @@ -457,11 +483,7 @@ void StaticModel::Serialize(SerializeStream& stream, const void* otherObj) #endif ) { - stream.JKEY("LightmapIndex"); - stream.Int(Lightmap.TextureIndex); - - stream.JKEY("LightmapArea"); - stream.Rectangle(Lightmap.UVsArea); + Lightmap.Serialize(stream); } stream.JKEY("Buffer"); @@ -502,9 +524,7 @@ void StaticModel::Deserialize(DeserializeStream& stream, ISerializeModifier* mod DESERIALIZE_MEMBER(ForcedLOD, _forcedLod); DESERIALIZE_MEMBER(SortOrder, _sortOrder); DESERIALIZE_MEMBER(DrawModes, _drawModes); - DESERIALIZE_MEMBER(LightmapIndex, Lightmap.TextureIndex); - DESERIALIZE_MEMBER(LightmapArea, Lightmap.UVsArea); - + Lightmap.Deserialize(stream); Entries.DeserializeIfExists(stream, "Buffer", modifier); { diff --git a/Source/Engine/Renderer/DrawCall.h b/Source/Engine/Renderer/DrawCall.h index b71b64874..5acdf6ecd 100644 --- a/Source/Engine/Renderer/DrawCall.h +++ b/Source/Engine/Renderer/DrawCall.h @@ -3,7 +3,7 @@ #pragma once #include "Config.h" -#include "Engine/Core/Math/Rectangle.h" +#include "Engine/Core/Math/Half.h" #include "Engine/Core/Math/Color.h" struct RenderView; @@ -183,13 +183,13 @@ struct DrawCall struct { const Lightmap* Lightmap; - Rectangle LightmapUVsArea; + Half4 LightmapUVsArea; } Features; struct { const Lightmap* Lightmap; - Rectangle LightmapUVsArea; + Half4 LightmapUVsArea; SkinnedMeshDrawData* Skinning; Float3 GeometrySize; // Object geometry size in the world (unscaled). float LODDitherFactor; // The model LOD transition dither progress. @@ -199,7 +199,7 @@ struct DrawCall struct { const Lightmap* Lightmap; - Rectangle LightmapUVsArea; + Half4 LightmapUVsArea; Float4 HeightmapUVScaleBias; Float4 NeighborLOD; Float2 OffsetUV; diff --git a/Source/Engine/Renderer/Editor/LightmapUVsDensity.cpp b/Source/Engine/Renderer/Editor/LightmapUVsDensity.cpp index e5a5ccc5b..0c75ce10d 100644 --- a/Source/Engine/Renderer/Editor/LightmapUVsDensity.cpp +++ b/Source/Engine/Renderer/Editor/LightmapUVsDensity.cpp @@ -102,7 +102,7 @@ void LightmapUVsDensityMaterialShader::Bind(BindParameters& params) scaleZ > 0.00001f ? 1.0f / scaleZ : 0.0f); data.LightmapTexelsPerWorldUnit = ShadowsOfMordor::LightmapTexelsPerWorldUnit; data.LightmapSize = 1024.0f; - data.LightmapArea = drawCall.Surface.LightmapUVsArea; + data.LightmapArea = drawCall.Surface.LightmapUVsArea.ToFloat4(); const ModelLOD* drawCallModelLod; float scaleInLightmap = drawCall.Surface.LODDitherFactor; // Reuse field if (scaleInLightmap < 0.0f) diff --git a/Source/Engine/Renderer/Lightmaps.h b/Source/Engine/Renderer/Lightmaps.h index d2a0f7569..aa0c04099 100644 --- a/Source/Engine/Renderer/Lightmaps.h +++ b/Source/Engine/Renderer/Lightmaps.h @@ -3,7 +3,7 @@ #pragma once #include "Engine/Core/Types/Guid.h" -#include "Engine/Core/Math/Rectangle.h" +#include "Engine/Core/Math/Half.h" #include "Engine/Core/ISerializable.h" #if USE_EDITOR @@ -42,21 +42,24 @@ struct LightmapEntry /// /// Index of the lightmap /// - int32 TextureIndex; + int16 TextureIndex; /// /// Lightmap UVs area that entry occupies /// - Rectangle UVsArea; + Half4 UVsArea; /// /// Init /// LightmapEntry() : TextureIndex(INVALID_INDEX) - , UVsArea(Rectangle::Empty) + , UVsArea(Half4::Zero) { } + + void Serialize(ISerializable::SerializeStream& stream); + void Deserialize(ISerializable::DeserializeStream& stream); }; template<> diff --git a/Source/Engine/Renderer/RenderList.cpp b/Source/Engine/Renderer/RenderList.cpp index 6687bdc97..90ad13574 100644 --- a/Source/Engine/Renderer/RenderList.cpp +++ b/Source/Engine/Renderer/RenderList.cpp @@ -1,6 +1,8 @@ // Copyright (c) Wojciech Figat. All rights reserved. #include "RenderList.h" +#include "Engine/Core/Log.h" +#include "Engine/Core/Math/Half.h" #include "Engine/Core/Collections/Sorting.h" #include "Engine/Graphics/Materials/IMaterial.h" #include "Engine/Graphics/Materials/MaterialShader.h" @@ -12,11 +14,9 @@ #include "Engine/Graphics/RenderTools.h" #include "Engine/Graphics/Graphics.h" #include "Engine/Graphics/PostProcessEffect.h" +#include "Engine/Graphics/Shaders/GPUVertexLayout.h" #include "Engine/Profiler/Profiler.h" #include "Engine/Content/Assets/CubeTexture.h" -#include "Engine/Core/Log.h" -#include "Engine/Core/Math/Half.h" -#include "Engine/Graphics/Shaders/GPUVertexLayout.h" #include "Engine/Level/Scene/Lightmap.h" #include "Engine/Level/Actors/PostFxVolume.h" @@ -47,10 +47,9 @@ namespace } } -void ShaderObjectData::Store(const Matrix& worldMatrix, const Matrix& prevWorldMatrix, const Rectangle& lightmapUVsArea, const Float3& geometrySize, float perInstanceRandom, float worldDeterminantSign, float lodDitherFactor) +void ShaderObjectData::Store(const Matrix& worldMatrix, const Matrix& prevWorldMatrix, const Half4& lightmapUVsArea, const Float3& geometrySize, float perInstanceRandom, float worldDeterminantSign, float lodDitherFactor) { - Half4 lightmapUVsAreaPacked(*(Float4*)&lightmapUVsArea); - Float2 lightmapUVsAreaPackedAliased = *(Float2*)&lightmapUVsAreaPacked; + Float2 lightmapUVsAreaPackedAliased = *(Float2*)&lightmapUVsArea; Raw[0] = Float4(worldMatrix.M11, worldMatrix.M12, worldMatrix.M13, worldMatrix.M41); Raw[1] = Float4(worldMatrix.M21, worldMatrix.M22, worldMatrix.M23, worldMatrix.M42); Raw[2] = Float4(worldMatrix.M31, worldMatrix.M32, worldMatrix.M33, worldMatrix.M43); @@ -62,7 +61,7 @@ void ShaderObjectData::Store(const Matrix& worldMatrix, const Matrix& prevWorldM // TODO: pack WorldDeterminantSign and LODDitherFactor } -void ShaderObjectData::Load(Matrix& worldMatrix, Matrix& prevWorldMatrix, Rectangle& lightmapUVsArea, Float3& geometrySize, float& perInstanceRandom, float& worldDeterminantSign, float& lodDitherFactor) const +void ShaderObjectData::Load(Matrix& worldMatrix, Matrix& prevWorldMatrix, Half4& lightmapUVsArea, Float3& geometrySize, float& perInstanceRandom, float& worldDeterminantSign, float& lodDitherFactor) const { worldMatrix.SetRow1(Float4(Float3(Raw[0]), 0.0f)); worldMatrix.SetRow2(Float4(Float3(Raw[1]), 0.0f)); @@ -77,8 +76,7 @@ void ShaderObjectData::Load(Matrix& worldMatrix, Matrix& prevWorldMatrix, Rectan worldDeterminantSign = Raw[7].X; lodDitherFactor = Raw[7].Y; Float2 lightmapUVsAreaPackedAliased(Raw[7].Z, Raw[7].W); - Half4 lightmapUVsAreaPacked(*(Half4*)&lightmapUVsAreaPackedAliased); - *(Float4*)&lightmapUVsArea = lightmapUVsAreaPacked.ToFloat4(); + lightmapUVsArea = *(Half4*)&lightmapUVsAreaPackedAliased; } bool RenderLightData::CanRenderShadow(const RenderView& view) const diff --git a/Source/Engine/Renderer/RenderList.h b/Source/Engine/Renderer/RenderList.h index b401f0af0..8e64e072b 100644 --- a/Source/Engine/Renderer/RenderList.h +++ b/Source/Engine/Renderer/RenderList.h @@ -22,6 +22,7 @@ class IPostFxSettingsProvider; class CubeTexture; struct RenderContext; struct RenderContextBatch; +struct Half4; struct RenderLightData { @@ -683,8 +684,8 @@ GPU_CB_STRUCT(ShaderObjectData { Float4 Raw[8]; - void FLAXENGINE_API Store(const Matrix& worldMatrix, const Matrix& prevWorldMatrix, const Rectangle& lightmapUVsArea, const Float3& geometrySize, float perInstanceRandom = 0.0f, float worldDeterminantSign = 1.0f, float lodDitherFactor = 0.0f); - void FLAXENGINE_API Load(Matrix& worldMatrix, Matrix& prevWorldMatrix, Rectangle& lightmapUVsArea, Float3& geometrySize, float& perInstanceRandom, float& worldDeterminantSign, float& lodDitherFactor) const; + void FLAXENGINE_API Store(const Matrix& worldMatrix, const Matrix& prevWorldMatrix, const Half4& lightmapUVsAreaPacked, const Float3& geometrySize, float perInstanceRandom = 0.0f, float worldDeterminantSign = 1.0f, float lodDitherFactor = 0.0f); + void FLAXENGINE_API Load(Matrix& worldMatrix, Matrix& prevWorldMatrix, Half4& lightmapUVsArea, Float3& geometrySize, float& perInstanceRandom, float& worldDeterminantSign, float& lodDitherFactor) const; FORCE_INLINE void Store(const DrawCall& drawCall) { diff --git a/Source/Engine/ShadowsOfMordor/AtlasChartsPacker.h b/Source/Engine/ShadowsOfMordor/AtlasChartsPacker.h index 708715bdd..892942516 100644 --- a/Source/Engine/ShadowsOfMordor/AtlasChartsPacker.h +++ b/Source/Engine/ShadowsOfMordor/AtlasChartsPacker.h @@ -26,7 +26,7 @@ namespace ShadowsOfMordor { Chart = chart; const float invSize = 1.0f / (int32)settings->AtlasSize; - chart->Result.UVsArea = Rectangle(X * invSize, Y * invSize, chart->Width * invSize, chart->Height * invSize); + chart->Result.UVsArea = Half4(X * invSize, Y * invSize, chart->Width * invSize, chart->Height * invSize); } }; diff --git a/Source/Engine/ShadowsOfMordor/Builder.Entries.cpp b/Source/Engine/ShadowsOfMordor/Builder.Entries.cpp index 733779e39..56d3de1d7 100644 --- a/Source/Engine/ShadowsOfMordor/Builder.Entries.cpp +++ b/Source/Engine/ShadowsOfMordor/Builder.Entries.cpp @@ -172,28 +172,24 @@ void ShadowsOfMordor::Builder::updateEntries() if (e.ChartIndex == INVALID_INDEX) { // Removed previously baked lightmap info - LightmapEntry emptyEntry; switch (e.Type) { case GeometryType::StaticModel: { - auto staticModel = e.AsStaticModel.Actor; - if (staticModel) - staticModel->Lightmap = emptyEntry; + if (auto staticModel = e.AsStaticModel.Actor) + staticModel->RemoveLightmap(); } break; case GeometryType::Terrain: { - auto terrain = e.AsTerrain.Actor; - if (terrain) - terrain->GetPatch(e.AsTerrain.PatchIndex)->Chunks[e.AsTerrain.ChunkIndex].Lightmap = emptyEntry; + if (auto terrain = e.AsTerrain.Actor) + terrain->GetPatch(e.AsTerrain.PatchIndex)->Chunks[e.AsTerrain.ChunkIndex].RemoveLightmap(); } break; case GeometryType::Foliage: { - auto foliage = e.AsFoliage.Actor; - if (foliage) - foliage->Instances[e.AsFoliage.InstanceIndex].Lightmap = emptyEntry; + if (auto foliage = e.AsFoliage.Actor) + foliage->Instances[e.AsFoliage.InstanceIndex].RemoveLightmap(); } break; } @@ -202,8 +198,10 @@ void ShadowsOfMordor::Builder::updateEntries() auto& chart = scene->Charts[e.ChartIndex]; // Update result uvs by taking into account lightmap uvs box - chart.Result.UVsArea.Size /= e.UVsBox.Size; - chart.Result.UVsArea.Location += e.UVsBox.Location * chart.Result.UVsArea.Size; + Rectangle rect = chart.Result.UVsArea.ToFloat4(); + rect.Size /= e.UVsBox.Size; + rect.Location += e.UVsBox.Location * rect.Size; + chart.Result.UVsArea = Half4(rect); switch (e.Type) { @@ -243,7 +241,9 @@ void ShadowsOfMordor::Builder::updateEntries() if (foliage) { // Update data - foliage->Instances[e.AsFoliage.InstanceIndex].Lightmap = chart.Result; + auto& instance = foliage->Instances[e.AsFoliage.InstanceIndex]; + instance.LightmapTextureIndex = (int8)chart.Result.TextureIndex; + instance.LightmapUVsArea = chart.Result.UVsArea; } else { diff --git a/Source/Engine/ShadowsOfMordor/Builder.Jobs.cpp b/Source/Engine/ShadowsOfMordor/Builder.Jobs.cpp index b77ee51b6..678cad294 100644 --- a/Source/Engine/ShadowsOfMordor/Builder.Jobs.cpp +++ b/Source/Engine/ShadowsOfMordor/Builder.Jobs.cpp @@ -127,7 +127,7 @@ void ShadowsOfMordor::Builder::onJobRender(GPUContext* context) Matrix worldMatrix; staticModel->GetLocalToWorldMatrix(worldMatrix); Matrix::Transpose(worldMatrix, shaderData.WorldMatrix); - shaderData.LightmapArea = staticModel->Lightmap.UVsArea; + shaderData.LightmapArea = staticModel->Lightmap.UVsArea.ToFloat4(); context->UpdateCB(cb, &shaderData); context->BindCB(0, cb); @@ -163,7 +163,7 @@ void ShadowsOfMordor::Builder::onJobRender(GPUContext* context) Matrix world; chunk->GetTransform().GetWorld(world); Matrix::Transpose(world, shaderData.WorldMatrix); - shaderData.LightmapArea = chunk->Lightmap.UVsArea; + shaderData.LightmapArea = chunk->Lightmap.UVsArea.ToFloat4(); shaderData.TerrainChunkSizeLOD0 = TERRAIN_UNITS_PER_VERTEX * chunkSize; shaderData.HeightmapUVScaleBias = chunk->GetHeightmapUVScaleBias(); @@ -199,7 +199,7 @@ void ShadowsOfMordor::Builder::onJobRender(GPUContext* context) Matrix world; foliage->GetTransform().LocalToWorld(instance.Transform).GetWorld(world); Matrix::Transpose(world, shaderData.WorldMatrix); - shaderData.LightmapArea = instance.Lightmap.UVsArea; + shaderData.LightmapArea = instance.LightmapUVsArea.ToFloat4(); context->UpdateCB(cb, &shaderData); context->BindCB(0, cb); diff --git a/Source/Engine/ShadowsOfMordor/Builder.h b/Source/Engine/ShadowsOfMordor/Builder.h index 354d4c39f..a933976dc 100644 --- a/Source/Engine/ShadowsOfMordor/Builder.h +++ b/Source/Engine/ShadowsOfMordor/Builder.h @@ -5,6 +5,7 @@ #include "Engine/Content/Assets/Model.h" #include "Engine/Content/Assets/Shader.h" #include "Engine/Core/Types/DateTime.h" +#include "Engine/Core/Math/Rectangle.h" #include "Engine/CSG/CSGMesh.h" #include "Builder.Config.h" diff --git a/Source/Engine/Terrain/TerrainChunk.cpp b/Source/Engine/Terrain/TerrainChunk.cpp index d1bcb7842..3ffedbe6f 100644 --- a/Source/Engine/Terrain/TerrainChunk.cpp +++ b/Source/Engine/Terrain/TerrainChunk.cpp @@ -120,7 +120,7 @@ void TerrainChunk::Draw(const RenderContext& renderContext) const else { drawCall.Terrain.Lightmap = nullptr; - drawCall.Terrain.LightmapUVsArea = Rectangle::Empty; + drawCall.Terrain.LightmapUVsArea = Half4::Zero; } drawCall.PerInstanceRandom = _perInstanceRandom; drawCall.SetStencilValue(_patch->_terrain->GetLayer()); @@ -181,7 +181,7 @@ void TerrainChunk::Draw(const RenderContext& renderContext, MaterialBase* materi else { drawCall.Terrain.Lightmap = nullptr; - drawCall.Terrain.LightmapUVsArea = Rectangle::Empty; + drawCall.Terrain.LightmapUVsArea = Half4::Zero; } drawCall.PerInstanceRandom = _perInstanceRandom; drawCall.SetStencilValue(_patch->_terrain->GetLayer()); @@ -311,11 +311,7 @@ void TerrainChunk::Serialize(SerializeStream& stream, const void* otherObj) #endif ) { - stream.JKEY("LightmapIndex"); - stream.Int(Lightmap.TextureIndex); - - stream.JKEY("LightmapArea"); - stream.Rectangle(Lightmap.UVsArea); + Lightmap.Serialize(stream); } } @@ -324,6 +320,5 @@ void TerrainChunk::Deserialize(DeserializeStream& stream, ISerializeModifier* mo DESERIALIZE_MEMBER(Offset, _yOffset); DESERIALIZE_MEMBER(Height, _yHeight); DESERIALIZE_MEMBER(Material, OverrideMaterial); - DESERIALIZE_MEMBER(LightmapIndex, Lightmap.TextureIndex); - DESERIALIZE_MEMBER(LightmapArea, Lightmap.UVsArea); + Lightmap.Deserialize(stream); }