Fixes for large worlds

This commit is contained in:
Wojtek Figat
2022-07-04 20:35:29 +02:00
parent 8da4e546da
commit 2e947ab85a
3 changed files with 5 additions and 6 deletions

View File

@@ -113,7 +113,7 @@ namespace FlaxEditor
var bounds = BoundingSphere.FromBox(staticModel.Box);
// Pick a proper LOD
var center = (Float3)bounds.Center; // TODO: large-worlds
Float3 center = bounds.Center - renderContext.View.Origin;
int lodIndex = RenderTools.ComputeModelLOD(model, ref center, (float)bounds.Radius, ref renderContext);
var lods = model.LODs;
if (lods == null || lods.Length < lodIndex || lodIndex < 0)

View File

@@ -196,7 +196,7 @@ void Model::Draw(const RenderContext& renderContext, MaterialBase* material, con
const BoundingBox box = GetBox(world);
BoundingSphere sphere;
BoundingSphere::FromBox(box, sphere);
int32 lodIndex = RenderTools::ComputeModelLOD(this, sphere.Center, (float)sphere.Radius, renderContext); // TODO: large-worlds
int32 lodIndex = RenderTools::ComputeModelLOD(this, sphere.Center - renderContext.View.Origin, (float)sphere.Radius, renderContext);
if (lodIndex == -1)
return;
lodIndex += renderContext.View.ModelLODBias;

View File

@@ -113,22 +113,21 @@ void SpriteRender::Draw(RenderContext& renderContext)
auto model = _quadModel.As<Model>();
if (model->GetLoadedLODs() == 0)
return;
auto& view = renderContext.View;
const auto& view = renderContext.View;
Matrix m1, m2, m3, world;
Matrix::Scaling(_size.X, _size.Y, 1.0f, m2);
Matrix::RotationY(PI, m3);
Matrix::Multiply(m2, m3, m1);
// TODO: large-worlds
if (FaceCamera)
{
Matrix::Billboard(_transform.Translation, view.Position, Vector3::Up, view.Direction, m2);
Matrix::Billboard(_transform.Translation - view.Origin, view.Position, Vector3::Up, view.Direction, m2);
Matrix::Multiply(m1, m2, m3);
Matrix::Scaling(_transform.Scale, m1);
Matrix::Multiply(m1, m3, world);
}
else
{
_transform.GetWorld(m2);
view.GetWorldMatrix(_transform, m2);
Matrix::Multiply(m1, m2, world);
}
model->LODs[0].Draw(renderContext, _materialInstance, world, GetStaticFlags(), false, DrawModes, GetPerInstanceRandom());