diff --git a/Source/Engine/Foliage/Foliage.cpp b/Source/Engine/Foliage/Foliage.cpp index 257256c97..d6a8fba44 100644 --- a/Source/Engine/Foliage/Foliage.cpp +++ b/Source/Engine/Foliage/Foliage.cpp @@ -85,7 +85,7 @@ void Foliage::AddToCluster(ChunkedArrayLODs[lod].Meshes; + const auto& meshes = model->LODs.Get()[lod].Meshes; for (int32 meshIndex = 0; meshIndex < meshes.Count(); meshIndex++) { auto& drawCall = drawCallsLists[lod][meshIndex]; @@ -94,7 +94,7 @@ void Foliage::DrawInstance(RenderContext& renderContext, FoliageInstance& instan DrawKey key; key.Mat = drawCall.DrawCall.Material; - key.Geo = &meshes[meshIndex]; + key.Geo = &meshes.Get()[meshIndex]; key.Lightmap = instance.Lightmap.TextureIndex; auto* e = result.TryGet(key); if (!e) @@ -108,7 +108,8 @@ void Foliage::DrawInstance(RenderContext& renderContext, FoliageInstance& instan auto& instanceData = e->Instances.AddOne(); Matrix world; const Transform transform = _transform.LocalToWorld(instance.Transform); - renderContext.View.GetWorldMatrix(transform, world); + const Float3 translation = transform.Translation - renderContext.View.Origin; + Matrix::Transformation(transform.Scale, transform.Orientation, translation, world); instanceData.InstanceOrigin = Float3(world.M41, world.M42, world.M43); instanceData.PerInstanceRandom = instance.Random; instanceData.InstanceTransform1 = Float3(world.M11, world.M12, world.M13); @@ -154,7 +155,7 @@ void Foliage::DrawCluster(RenderContext& renderContext, FoliageCluster* cluster, const auto model = type.Model.Get(); for (int32 i = 0; i < cluster->Instances.Count(); i++) { - auto& instance = *cluster->Instances[i]; + auto& instance = *cluster->Instances.Get()[i]; BoundingSphere sphere = instance.Bounds; sphere.Center -= viewOrigin; if (Float3::Distance(renderContext.View.Position, sphere.Center) - (float)sphere.Radius < instance.CullDistance && @@ -294,7 +295,8 @@ void Foliage::DrawCluster(RenderContext& renderContext, FoliageCluster* cluster, { Matrix world; const Transform transform = _transform.LocalToWorld(instance.Transform); - renderContext.View.GetWorldMatrix(transform, world); + const Float3 translation = transform.Translation - renderContext.View.Origin; + Matrix::Transformation(transform.Scale, transform.Orientation, translation, world); // Disable motion blur instance.DrawState.PrevWorld = world; diff --git a/Source/Engine/Level/Actors/AnimatedModel.cpp b/Source/Engine/Level/Actors/AnimatedModel.cpp index 55b19d054..d8692b210 100644 --- a/Source/Engine/Level/Actors/AnimatedModel.cpp +++ b/Source/Engine/Level/Actors/AnimatedModel.cpp @@ -699,45 +699,38 @@ void AnimatedModel::Update() void AnimatedModel::Draw(RenderContext& renderContext) { + if (!SkinnedModel || !SkinnedModel->IsLoaded()) + return; if (renderContext.View.Pass == DrawPass::GlobalSDF) return; // TODO: Animated Model rendering to Global SDF if (renderContext.View.Pass == DrawPass::GlobalSurfaceAtlas) return; // No supported Matrix world; - renderContext.View.GetWorldMatrix(_transform, world); + const Float3 translation = _transform.Translation - renderContext.View.Origin; + Matrix::Transformation(_transform.Scale, _transform.Orientation, translation, world); GEOMETRY_DRAW_STATE_EVENT_BEGIN(_drawState, world); - if (SkinnedModel && SkinnedModel->IsLoaded()) + _lastMinDstSqr = Math::Min(_lastMinDstSqr, Vector3::DistanceSquared(_transform.Translation, renderContext.View.Position + renderContext.View.Origin)); + if (_skinningData.IsReady()) { - _lastMinDstSqr = Math::Min(_lastMinDstSqr, Vector3::DistanceSquared(_transform.Translation, renderContext.View.Position + renderContext.View.Origin)); + _skinningData.Flush(GPUDevice::Instance->GetMainContext()); - if (_skinningData.IsReady()) - { -#if USE_EDITOR - // Disable motion blur effects in editor without play mode enabled to hide minor artifacts on objects moving - if (!Editor::IsPlayMode) - _drawState.PrevWorld = world; -#endif + SkinnedMesh::DrawInfo draw; + draw.Buffer = &Entries; + draw.Skinning = &_skinningData; + draw.BlendShapes = &_blendShapes; + draw.World = &world; + draw.DrawState = &_drawState; + PRAGMA_DISABLE_DEPRECATION_WARNINGS + draw.DrawModes = (DrawPass)(DrawModes & renderContext.View.GetShadowsDrawPassMask(ShadowsMode)); + PRAGMA_ENABLE_DEPRECATION_WARNINGS + draw.Bounds = _sphere; + draw.Bounds.Center -= renderContext.View.Origin; + draw.PerInstanceRandom = GetPerInstanceRandom(); + draw.LODBias = LODBias; + draw.ForcedLOD = ForcedLOD; - _skinningData.Flush(GPUDevice::Instance->GetMainContext()); - - SkinnedMesh::DrawInfo draw; - draw.Buffer = &Entries; - draw.Skinning = &_skinningData; - draw.BlendShapes = &_blendShapes; - draw.World = &world; - draw.DrawState = &_drawState; - PRAGMA_DISABLE_DEPRECATION_WARNINGS - draw.DrawModes = (DrawPass)(DrawModes & renderContext.View.GetShadowsDrawPassMask(ShadowsMode)); - PRAGMA_ENABLE_DEPRECATION_WARNINGS - draw.Bounds = _sphere; - draw.Bounds.Center -= renderContext.View.Origin; - draw.PerInstanceRandom = GetPerInstanceRandom(); - draw.LODBias = LODBias; - draw.ForcedLOD = ForcedLOD; - - SkinnedModel->Draw(renderContext, draw); - } + SkinnedModel->Draw(renderContext, draw); } GEOMETRY_DRAW_STATE_EVENT_END(_drawState, world); @@ -749,17 +742,13 @@ void AnimatedModel::Draw(RenderContextBatch& renderContextBatch) return; const RenderContext& renderContext = renderContextBatch.GetMainContext(); Matrix world; - renderContext.View.GetWorldMatrix(_transform, world); + const Float3 translation = _transform.Translation - renderContext.View.Origin; + Matrix::Transformation(_transform.Scale, _transform.Orientation, translation, world); GEOMETRY_DRAW_STATE_EVENT_BEGIN(_drawState, world); + _lastMinDstSqr = Math::Min(_lastMinDstSqr, Vector3::DistanceSquared(_transform.Translation, renderContext.View.Position + renderContext.View.Origin)); if (_skinningData.IsReady()) { -#if USE_EDITOR - // Disable motion blur effects in editor without play mode enabled to hide minor artifacts on objects moving - if (!Editor::IsPlayMode) - _drawState.PrevWorld = world; -#endif - _skinningData.Flush(GPUDevice::Instance->GetMainContext()); SkinnedMesh::DrawInfo draw; @@ -792,6 +781,7 @@ void AnimatedModel::Draw(RenderContextBatch& renderContextBatch) } PRAGMA_ENABLE_DEPRECATION_WARNINGS } + GEOMETRY_DRAW_STATE_EVENT_END(_drawState, world); } diff --git a/Source/Engine/Level/Actors/StaticModel.cpp b/Source/Engine/Level/Actors/StaticModel.cpp index ed81fa353..49af285d3 100644 --- a/Source/Engine/Level/Actors/StaticModel.cpp +++ b/Source/Engine/Level/Actors/StaticModel.cpp @@ -269,18 +269,12 @@ void StaticModel::Draw(RenderContext& renderContext) return; } Matrix world; - renderContext.View.GetWorldMatrix(_transform, world); + const Float3 translation = _transform.Translation - renderContext.View.Origin; + Matrix::Transformation(_transform.Scale, _transform.Orientation, translation, world); GEOMETRY_DRAW_STATE_EVENT_BEGIN(_drawState, world); - if (_vertexColorsDirty) FlushVertexColors(); -#if USE_EDITOR - // Disable motion blur effects in editor without play mode enabled to hide minor artifacts on objects moving - if (!Editor::IsPlayMode) - _drawState.PrevWorld = world; -#endif - Mesh::DrawInfo draw; draw.Buffer = &Entries; draw.World = &world; @@ -307,18 +301,12 @@ void StaticModel::Draw(RenderContextBatch& renderContextBatch) return; const RenderContext& renderContext = renderContextBatch.GetMainContext(); Matrix world; - renderContext.View.GetWorldMatrix(_transform, world); + const Float3 translation = _transform.Translation - renderContext.View.Origin; + Matrix::Transformation(_transform.Scale, _transform.Orientation, translation, world); GEOMETRY_DRAW_STATE_EVENT_BEGIN(_drawState, world); - if (_vertexColorsDirty) FlushVertexColors(); -#if USE_EDITOR - // Disable motion blur effects in editor without play mode enabled to hide minor artifacts on objects moving - if (!Editor::IsPlayMode) - _drawState.PrevWorld = world; -#endif - Mesh::DrawInfo draw; draw.Buffer = &Entries; draw.World = &world; diff --git a/Source/Engine/UI/TextRender.cpp b/Source/Engine/UI/TextRender.cpp index e35542dae..8adad4ae3 100644 --- a/Source/Engine/UI/TextRender.cpp +++ b/Source/Engine/UI/TextRender.cpp @@ -352,12 +352,6 @@ void TextRender::Draw(RenderContext& renderContext) const DrawPass drawModes = (DrawPass)(DrawModes & renderContext.View.Pass & (uint32)renderContext.View.GetShadowsDrawPassMask(ShadowsMode)); if (_vb0.Data.Count() > 0 && drawModes != DrawPass::None) { -#if USE_EDITOR - // Disable motion blur effects in editor without play mode enabled to hide minor artifacts on objects moving - if (!Editor::IsPlayMode) - _drawState.PrevWorld = world; -#endif - // Flush buffers if (_buffersDirty) {