|
@@ -185,31 +185,7 @@ void BillboardSet::UpdateBatches(const FrameInfo& frame)
|
|
|
|
|
|
|
|
// Calculate fixed screen size scale factor for billboards if needed
|
|
// Calculate fixed screen size scale factor for billboards if needed
|
|
|
if (fixedScreenSize_)
|
|
if (fixedScreenSize_)
|
|
|
- {
|
|
|
|
|
- bufferDirty_ = true;
|
|
|
|
|
- worldBoundingBoxDirty_ = true;
|
|
|
|
|
- float invViewHeight = 1.0f / frame.viewSize_.y_;
|
|
|
|
|
- float halfViewWorldSize = frame.camera_->GetHalfViewSize();
|
|
|
|
|
-
|
|
|
|
|
- if (!frame.camera_->IsOrthographic())
|
|
|
|
|
- {
|
|
|
|
|
- Matrix4 viewProj(frame.camera_->GetProjection(false) * frame.camera_->GetView());
|
|
|
|
|
- const Matrix3x4& worldTransform = node_->GetWorldTransform();
|
|
|
|
|
- Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
|
|
|
|
|
- Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
|
|
|
|
|
-
|
|
|
|
|
- for (unsigned i = 0; i < billboards_.Size(); ++i)
|
|
|
|
|
- {
|
|
|
|
|
- Vector4 projPos(viewProj * Vector4(billboardTransform * billboards_[i].position_, 1.0f));
|
|
|
|
|
- billboards_[i].screenScaleFactor_ = invViewHeight * halfViewWorldSize * projPos.w_;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- for (unsigned i = 0; i < billboards_.Size(); ++i)
|
|
|
|
|
- billboards_[i].screenScaleFactor_ = invViewHeight * halfViewWorldSize;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ CalculateFixedScreenSize(frame);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
distance_ = frame.camera_->GetDistance(GetWorldBoundingBox().Center());
|
|
distance_ = frame.camera_->GetDistance(GetWorldBoundingBox().Center());
|
|
@@ -233,11 +209,9 @@ void BillboardSet::UpdateBatches(const FrameInfo& frame)
|
|
|
|
|
|
|
|
void BillboardSet::UpdateGeometry(const FrameInfo& frame)
|
|
void BillboardSet::UpdateGeometry(const FrameInfo& frame)
|
|
|
{
|
|
{
|
|
|
- if (bufferSizeDirty_ || indexBuffer_->IsDataLost())
|
|
|
|
|
- UpdateBufferSize();
|
|
|
|
|
-
|
|
|
|
|
- if (bufferDirty_ || sortThisFrame_ || vertexBuffer_->IsDataLost())
|
|
|
|
|
- UpdateVertexBuffer(frame);
|
|
|
|
|
|
|
+ // If rendering from multiple views and fixed screen size is in use, re-update scale factors before each render
|
|
|
|
|
+ if (fixedScreenSize_ && viewCameras_.Size() > 1)
|
|
|
|
|
+ CalculateFixedScreenSize(frame);
|
|
|
|
|
|
|
|
// If using camera facing, re-update the rotation for the current view now
|
|
// If using camera facing, re-update the rotation for the current view now
|
|
|
if (faceCameraMode_ != FC_NONE)
|
|
if (faceCameraMode_ != FC_NONE)
|
|
@@ -245,15 +219,20 @@ void BillboardSet::UpdateGeometry(const FrameInfo& frame)
|
|
|
transforms_[1] = Matrix3x4(Vector3::ZERO, frame.camera_->GetFaceCameraRotation(node_->GetWorldPosition(),
|
|
transforms_[1] = Matrix3x4(Vector3::ZERO, frame.camera_->GetFaceCameraRotation(node_->GetWorldPosition(),
|
|
|
node_->GetWorldRotation(), faceCameraMode_), Vector3::ONE);
|
|
node_->GetWorldRotation(), faceCameraMode_), Vector3::ONE);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (bufferSizeDirty_ || indexBuffer_->IsDataLost())
|
|
|
|
|
+ UpdateBufferSize();
|
|
|
|
|
+
|
|
|
|
|
+ if (bufferDirty_ || sortThisFrame_ || vertexBuffer_->IsDataLost())
|
|
|
|
|
+ UpdateVertexBuffer(frame);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
UpdateGeometryType BillboardSet::GetUpdateGeometryType()
|
|
UpdateGeometryType BillboardSet::GetUpdateGeometryType()
|
|
|
{
|
|
{
|
|
|
// If using camera facing, always need some kind of geometry update, in case the billboard set is rendered from several views
|
|
// If using camera facing, always need some kind of geometry update, in case the billboard set is rendered from several views
|
|
|
- if (bufferDirty_ || bufferSizeDirty_ || vertexBuffer_->IsDataLost() || indexBuffer_->IsDataLost() || sortThisFrame_)
|
|
|
|
|
|
|
+ if (bufferDirty_ || bufferSizeDirty_ || vertexBuffer_->IsDataLost() || indexBuffer_->IsDataLost() || sortThisFrame_ ||
|
|
|
|
|
+ faceCameraMode_ != FC_NONE || fixedScreenSize_)
|
|
|
return UPDATE_MAIN_THREAD;
|
|
return UPDATE_MAIN_THREAD;
|
|
|
- else if (faceCameraMode_ != FC_NONE)
|
|
|
|
|
- return UPDATE_WORKER_THREAD;
|
|
|
|
|
else
|
|
else
|
|
|
return UPDATE_NONE;
|
|
return UPDATE_NONE;
|
|
|
}
|
|
}
|
|
@@ -764,4 +743,33 @@ void BillboardSet::MarkPositionsDirty()
|
|
|
bufferDirty_ = true;
|
|
bufferDirty_ = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void BillboardSet::CalculateFixedScreenSize(const FrameInfo& frame)
|
|
|
|
|
+{
|
|
|
|
|
+ float invViewHeight = 1.0f / frame.viewSize_.y_;
|
|
|
|
|
+ float halfViewWorldSize = frame.camera_->GetHalfViewSize();
|
|
|
|
|
+
|
|
|
|
|
+ if (!frame.camera_->IsOrthographic())
|
|
|
|
|
+ {
|
|
|
|
|
+ Matrix4 viewProj(frame.camera_->GetProjection(false) * frame.camera_->GetView());
|
|
|
|
|
+ const Matrix3x4& worldTransform = node_->GetWorldTransform();
|
|
|
|
|
+ Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
|
|
|
|
|
+ Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
|
|
|
|
|
+
|
|
|
|
|
+ for (unsigned i = 0; i < billboards_.Size(); ++i)
|
|
|
|
|
+ {
|
|
|
|
|
+ Vector4 projPos(viewProj * Vector4(billboardTransform * billboards_[i].position_, 1.0f));
|
|
|
|
|
+ billboards_[i].screenScaleFactor_ = invViewHeight * halfViewWorldSize * projPos.w_;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ for (unsigned i = 0; i < billboards_.Size(); ++i)
|
|
|
|
|
+ billboards_[i].screenScaleFactor_ = invViewHeight * halfViewWorldSize;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bufferDirty_ = true;
|
|
|
|
|
+ forceUpdate_ = true;
|
|
|
|
|
+ worldBoundingBoxDirty_ = true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
}
|
|
}
|