BillboardSet.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "Batch.h"
  24. #include "BillboardSet.h"
  25. #include "Camera.h"
  26. #include "Context.h"
  27. #include "Geometry.h"
  28. #include "Graphics.h"
  29. #include "IndexBuffer.h"
  30. #include "Material.h"
  31. #include "MemoryBuffer.h"
  32. #include "Node.h"
  33. #include "OctreeQuery.h"
  34. #include "Profiler.h"
  35. #include "ResourceCache.h"
  36. #include "Sort.h"
  37. #include "VertexBuffer.h"
  38. #include "DebugNew.h"
  39. namespace Urho3D
  40. {
  41. extern const char* GEOMETRY_CATEGORY;
  42. static const float INV_SQRT_TWO = 1.0f / sqrtf(2.0f);
  43. inline bool CompareBillboards(Billboard* lhs, Billboard* rhs)
  44. {
  45. return lhs->sortDistance_ > rhs->sortDistance_;
  46. }
  47. BillboardSet::BillboardSet(Context* context) :
  48. Drawable(context, DRAWABLE_GEOMETRY),
  49. faceCameraAxes_(Vector3::ONE),
  50. animationLodBias_(1.0f),
  51. animationLodTimer_(0.0f),
  52. relative_(true),
  53. scaled_(true),
  54. sorted_(false),
  55. faceCamera_(true),
  56. geometry_(new Geometry(context)),
  57. vertexBuffer_(new VertexBuffer(context_)),
  58. indexBuffer_(new IndexBuffer(context_)),
  59. bufferSizeDirty_(true),
  60. bufferDirty_(true),
  61. forceUpdate_(false),
  62. sortFrameNumber_(0),
  63. previousOffset_(Vector3::ZERO)
  64. {
  65. geometry_->SetVertexBuffer(0, vertexBuffer_, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1 | MASK_TEXCOORD2);
  66. geometry_->SetIndexBuffer(indexBuffer_);
  67. batches_.Resize(1);
  68. batches_[0].geometry_ = geometry_;
  69. batches_[0].geometryType_ = GEOM_BILLBOARD;
  70. batches_[0].worldTransform_ = &transforms_[0];
  71. }
  72. BillboardSet::~BillboardSet()
  73. {
  74. }
  75. void BillboardSet::RegisterObject(Context* context)
  76. {
  77. context->RegisterFactory<BillboardSet>(GEOMETRY_CATEGORY);
  78. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_BOOL, "Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
  79. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_RESOURCEREF, "Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
  80. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_BOOL, "Relative Position", IsRelative, SetRelative, bool, true, AM_DEFAULT);
  81. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_BOOL, "Relative Scale", IsScaled, SetScaled, bool, true, AM_DEFAULT);
  82. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_BOOL, "Sort By Distance", IsSorted, SetSorted, bool, false, AM_DEFAULT);
  83. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_BOOL, "Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
  84. ATTRIBUTE(BillboardSet, VAR_BOOL, "Cast Shadows", castShadows_, false, AM_DEFAULT);
  85. ATTRIBUTE(BillboardSet, VAR_BOOL, "Face Camera", faceCamera_, true, AM_DEFAULT);
  86. ATTRIBUTE(BillboardSet, VAR_VECTOR3, "Face Camera Axes", faceCameraAxes_, Vector3::ONE, AM_DEFAULT);
  87. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_FLOAT, "Draw Distance", GetDrawDistance, SetDrawDistance, float, 0.0f, AM_DEFAULT);
  88. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_FLOAT, "Shadow Distance", GetShadowDistance, SetShadowDistance, float, 0.0f, AM_DEFAULT);
  89. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_FLOAT, "Animation LOD Bias", GetAnimationLodBias, SetAnimationLodBias, float, 1.0f, AM_DEFAULT);
  90. COPY_BASE_ATTRIBUTES(BillboardSet, Drawable);
  91. ACCESSOR_ATTRIBUTE(BillboardSet, VAR_VARIANTVECTOR, "Billboards", GetBillboardsAttr, SetBillboardsAttr, VariantVector, Variant::emptyVariantVector, AM_FILE);
  92. REF_ACCESSOR_ATTRIBUTE(BillboardSet, VAR_BUFFER, "Network Billboards", GetNetBillboardsAttr, SetNetBillboardsAttr, PODVector<unsigned char>, Variant::emptyBuffer, AM_NET | AM_NOEDIT);
  93. }
  94. void BillboardSet::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
  95. {
  96. // If no billboard-level testing, use the Drawable test
  97. if (query.level_ < RAY_TRIANGLE)
  98. {
  99. Drawable::ProcessRayQuery(query, results);
  100. return;
  101. }
  102. // Check ray hit distance to AABB before proceeding with billboard-level tests
  103. if (query.ray_.HitDistance(GetWorldBoundingBox()) >= query.maxDistance_)
  104. return;
  105. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  106. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  107. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  108. for (unsigned i = 0; i < billboards_.Size(); ++i)
  109. {
  110. if (!billboards_[i].enabled_)
  111. continue;
  112. // Approximate the billboards as spheres for raycasting
  113. float size = INV_SQRT_TWO * (billboards_[i].size_.x_ * billboardScale.x_ + billboards_[i].size_.y_ * billboardScale.y_);
  114. Vector3 center = billboardTransform * billboards_[i].position_;
  115. Sphere billboardSphere(center, size);
  116. float distance = query.ray_.HitDistance(billboardSphere);
  117. if (distance < query.maxDistance_)
  118. {
  119. // If the code reaches here then we have a hit
  120. RayQueryResult result;
  121. result.position_ = query.ray_.origin_ + distance * query.ray_.direction_;
  122. result.normal_ = -query.ray_.direction_;
  123. result.distance_ = distance;
  124. result.drawable_ = this;
  125. result.node_ = node_;
  126. result.subObject_ = i;
  127. results.Push(result);
  128. }
  129. }
  130. }
  131. void BillboardSet::UpdateBatches(const FrameInfo& frame)
  132. {
  133. // Check if position relative to camera has changed, and re-sort in that case
  134. Vector3 worldPos = node_->GetWorldPosition();
  135. Vector3 offset = (worldPos - frame.camera_->GetNode()->GetWorldPosition());
  136. if (offset != previousOffset_)
  137. {
  138. previousOffset_ = offset;
  139. if (sorted_)
  140. {
  141. // Sort billboards only once per frame. This means that secondary views will get
  142. // the same sorting as the main view
  143. if (frame.frameNumber_ != sortFrameNumber_)
  144. {
  145. sortFrameNumber_ = frame.frameNumber_;
  146. bufferDirty_ = true;
  147. }
  148. }
  149. }
  150. distance_ = frame.camera_->GetDistance(GetWorldBoundingBox().Center());
  151. // Calculate scaled distance for animation LOD
  152. float scale = GetWorldBoundingBox().Size().DotProduct(DOT_SCALE);
  153. // If there are no billboards, the size becomes zero, and LOD'ed updates no longer happen. Disable LOD in that case
  154. if (scale > M_EPSILON)
  155. lodDistance_ = frame.camera_->GetLodDistance(distance_, scale, lodBias_);
  156. else
  157. lodDistance_ = 0.0f;
  158. batches_[0].distance_ = distance_;
  159. batches_[0].numWorldTransforms_ = 2;
  160. // Billboard positioning
  161. transforms_[0] = relative_ ? node_->GetWorldTransform() : Matrix3x4::IDENTITY;
  162. // Billboard rotation
  163. transforms_[1] = Matrix3x4(Vector3::ZERO, faceCamera_ ? frame.camera_->GetFaceCameraRotation(
  164. node_->GetWorldRotation(), faceCameraAxes_) : node_->GetWorldRotation(), Vector3::ONE);
  165. }
  166. void BillboardSet::UpdateGeometry(const FrameInfo& frame)
  167. {
  168. if (bufferSizeDirty_ || indexBuffer_->IsDataLost())
  169. UpdateBufferSize();
  170. if (bufferDirty_ || vertexBuffer_->IsDataLost())
  171. UpdateVertexBuffer(frame);
  172. }
  173. UpdateGeometryType BillboardSet::GetUpdateGeometryType()
  174. {
  175. if (bufferDirty_ || bufferSizeDirty_ || vertexBuffer_->IsDataLost() || indexBuffer_->IsDataLost())
  176. return UPDATE_MAIN_THREAD;
  177. else
  178. return UPDATE_NONE;
  179. }
  180. void BillboardSet::SetMaterial(Material* material)
  181. {
  182. batches_[0].material_ = material;
  183. MarkNetworkUpdate();
  184. }
  185. void BillboardSet::SetNumBillboards(unsigned num)
  186. {
  187. // Prevent negative value being assigned from the editor
  188. if (num > M_MAX_INT)
  189. num = 0;
  190. if (num > MAX_BILLBOARDS)
  191. num = MAX_BILLBOARDS;
  192. unsigned oldNum = billboards_.Size();
  193. billboards_.Resize(num);
  194. // Set default values to new billboards
  195. for (unsigned i = oldNum; i < num; ++i)
  196. {
  197. billboards_[i].position_ = Vector3::ZERO;
  198. billboards_[i].size_ = Vector2::ONE;
  199. billboards_[i].uv_ = Rect::POSITIVE;
  200. billboards_[i].color_ = Color(1.0f, 1.0f, 1.0f);
  201. billboards_[i].rotation_ = 0.0f;
  202. billboards_[i].enabled_ = false;
  203. }
  204. bufferSizeDirty_ = true;
  205. Commit();
  206. }
  207. void BillboardSet::SetRelative(bool enable)
  208. {
  209. relative_ = enable;
  210. Commit();
  211. }
  212. void BillboardSet::SetScaled(bool enable)
  213. {
  214. scaled_ = enable;
  215. Commit();
  216. }
  217. void BillboardSet::SetSorted(bool enable)
  218. {
  219. sorted_ = enable;
  220. Commit();
  221. }
  222. void BillboardSet::SetFaceCamera(bool enable)
  223. {
  224. faceCamera_ = enable;
  225. MarkNetworkUpdate();
  226. }
  227. void BillboardSet::SetFaceCameraAxes(const Vector3& axes)
  228. {
  229. faceCameraAxes_ = axes;
  230. MarkNetworkUpdate();
  231. }
  232. void BillboardSet::SetAnimationLodBias(float bias)
  233. {
  234. animationLodBias_ = Max(bias, 0.0f);
  235. MarkNetworkUpdate();
  236. }
  237. void BillboardSet::Commit()
  238. {
  239. MarkPositionsDirty();
  240. MarkNetworkUpdate();
  241. }
  242. Material* BillboardSet::GetMaterial() const
  243. {
  244. return batches_[0].material_;
  245. }
  246. Billboard* BillboardSet::GetBillboard(unsigned index)
  247. {
  248. return index < billboards_.Size() ? &billboards_[index] : (Billboard*)0;
  249. }
  250. void BillboardSet::SetMaterialAttr(ResourceRef value)
  251. {
  252. ResourceCache* cache = GetSubsystem<ResourceCache>();
  253. SetMaterial(cache->GetResource<Material>(value.name_));
  254. }
  255. void BillboardSet::SetBillboardsAttr(VariantVector value)
  256. {
  257. unsigned index = 0;
  258. unsigned numBillboards = index < value.Size() ? value[index++].GetUInt() : 0;
  259. SetNumBillboards(numBillboards);
  260. for (PODVector<Billboard>::Iterator i = billboards_.Begin(); i != billboards_.End() && index < value.Size(); ++i)
  261. {
  262. i->position_ = value[index++].GetVector3();
  263. i->size_ = value[index++].GetVector2();
  264. Vector4 uv = value[index++].GetVector4();
  265. i->uv_ = Rect(uv.x_, uv.y_, uv.z_, uv.w_);
  266. i->color_ = value[index++].GetColor();
  267. i->rotation_ = value[index++].GetFloat();
  268. i->enabled_ = value[index++].GetBool();
  269. }
  270. Commit();
  271. }
  272. void BillboardSet::SetNetBillboardsAttr(const PODVector<unsigned char>& value)
  273. {
  274. MemoryBuffer buf(value);
  275. unsigned numBillboards = buf.ReadVLE();
  276. SetNumBillboards(numBillboards);
  277. for (PODVector<Billboard>::Iterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  278. {
  279. i->position_ = buf.ReadVector3();
  280. i->size_ = buf.ReadVector2();
  281. i->uv_ = buf.ReadRect();
  282. i->color_ = buf.ReadColor();
  283. i->rotation_ = buf.ReadFloat();
  284. i->enabled_ = buf.ReadBool();
  285. }
  286. Commit();
  287. }
  288. ResourceRef BillboardSet::GetMaterialAttr() const
  289. {
  290. return GetResourceRef(batches_[0].material_, Material::GetTypeStatic());
  291. }
  292. VariantVector BillboardSet::GetBillboardsAttr() const
  293. {
  294. VariantVector ret;
  295. ret.Reserve(billboards_.Size() * 6 + 1);
  296. ret.Push(billboards_.Size());
  297. for (PODVector<Billboard>::ConstIterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  298. {
  299. ret.Push(i->position_);
  300. ret.Push(i->size_);
  301. ret.Push(Vector4(i->uv_.min_.x_, i->uv_.min_.y_, i->uv_.max_.x_, i->uv_.max_.y_));
  302. ret.Push(i->color_);
  303. ret.Push(i->rotation_);
  304. ret.Push(i->enabled_);
  305. }
  306. return ret;
  307. }
  308. const PODVector<unsigned char>& BillboardSet::GetNetBillboardsAttr() const
  309. {
  310. attrBuffer_.Clear();
  311. attrBuffer_.WriteVLE(billboards_.Size());
  312. for (PODVector<Billboard>::ConstIterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  313. {
  314. attrBuffer_.WriteVector3(i->position_);
  315. attrBuffer_.WriteVector2(i->size_);
  316. attrBuffer_.WriteRect(i->uv_);
  317. attrBuffer_.WriteColor(i->color_);
  318. attrBuffer_.WriteFloat(i->rotation_);
  319. attrBuffer_.WriteBool(i->enabled_);
  320. }
  321. return attrBuffer_.GetBuffer();
  322. }
  323. void BillboardSet::OnWorldBoundingBoxUpdate()
  324. {
  325. unsigned enabledBillboards = 0;
  326. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  327. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  328. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  329. BoundingBox worldBox;
  330. for (unsigned i = 0; i < billboards_.Size(); ++i)
  331. {
  332. if (!billboards_[i].enabled_)
  333. continue;
  334. float size = INV_SQRT_TWO * (billboards_[i].size_.x_ * billboardScale.x_ + billboards_[i].size_.y_ * billboardScale.y_);
  335. Vector3 center = billboardTransform * billboards_[i].position_;
  336. Vector3 edge = Vector3::ONE * size;
  337. worldBox.Merge(BoundingBox(center - edge, center + edge));
  338. ++enabledBillboards;
  339. }
  340. // Always merge the node's own position to ensure particle emitter updates continue when the relative mode is switched
  341. worldBox.Merge(node_->GetWorldPosition());
  342. worldBoundingBox_ = worldBox;
  343. }
  344. void BillboardSet::UpdateBufferSize()
  345. {
  346. unsigned numBillboards = billboards_.Size();
  347. if (vertexBuffer_->GetVertexCount() != numBillboards * 4)
  348. vertexBuffer_->SetSize(numBillboards * 4, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1 | MASK_TEXCOORD2, true);
  349. if (indexBuffer_->GetIndexCount() != numBillboards * 6)
  350. indexBuffer_->SetSize(numBillboards * 6, false);
  351. bufferSizeDirty_ = false;
  352. bufferDirty_ = true;
  353. forceUpdate_ = true;
  354. if (!numBillboards)
  355. return;
  356. // Indices do not change for a given billboard capacity
  357. unsigned short* dest = (unsigned short*)indexBuffer_->Lock(0, numBillboards * 6, true);
  358. if (!dest)
  359. return;
  360. unsigned vertexIndex = 0;
  361. while (numBillboards--)
  362. {
  363. dest[0] = vertexIndex; dest[1] = vertexIndex + 1; dest[2] = vertexIndex + 2;
  364. dest[3] = vertexIndex + 2; dest[4] = vertexIndex + 3; dest[5] = vertexIndex;
  365. dest += 6;
  366. vertexIndex += 4;
  367. }
  368. indexBuffer_->Unlock();
  369. indexBuffer_->ClearDataLost();
  370. }
  371. void BillboardSet::UpdateVertexBuffer(const FrameInfo& frame)
  372. {
  373. // If using animation LOD, accumulate time and see if it is time to update
  374. if (animationLodBias_ > 0.0f && lodDistance_ > 0.0f)
  375. {
  376. animationLodTimer_ += animationLodBias_ * frame.timeStep_ * ANIMATION_LOD_BASESCALE;
  377. if (animationLodTimer_ >= lodDistance_)
  378. animationLodTimer_ = fmodf(animationLodTimer_, lodDistance_);
  379. else
  380. {
  381. // No LOD if immediate update forced
  382. if (!forceUpdate_)
  383. return;
  384. }
  385. }
  386. unsigned numBillboards = billboards_.Size();
  387. unsigned enabledBillboards = 0;
  388. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  389. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  390. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  391. // First check number of enabled billboards
  392. for (unsigned i = 0; i < numBillboards; ++i)
  393. {
  394. if (billboards_[i].enabled_)
  395. ++enabledBillboards;
  396. }
  397. sortedBillboards_.Resize(enabledBillboards);
  398. unsigned index = 0;
  399. // Then set initial sort order and distances
  400. for (unsigned i = 0; i < numBillboards; ++i)
  401. {
  402. Billboard& billboard = billboards_[i];
  403. if (billboard.enabled_)
  404. {
  405. sortedBillboards_[index++] = &billboard;
  406. if (sorted_)
  407. billboard.sortDistance_ = frame.camera_->GetDistanceSquared(billboardTransform * billboards_[i].position_);
  408. }
  409. }
  410. batches_[0].geometry_->SetDrawRange(TRIANGLE_LIST, 0, enabledBillboards * 6, false);
  411. bufferDirty_ = false;
  412. forceUpdate_ = false;
  413. if (!enabledBillboards)
  414. return;
  415. if (sorted_)
  416. Sort(sortedBillboards_.Begin(), sortedBillboards_.End(), CompareBillboards);
  417. float* dest = (float*)vertexBuffer_->Lock(0, enabledBillboards * 4, true);
  418. if (!dest)
  419. return;
  420. for (unsigned i = 0; i < enabledBillboards; ++i)
  421. {
  422. Billboard& billboard = *sortedBillboards_[i];
  423. Vector2 size(billboard.size_.x_ * billboardScale.x_, billboard.size_.y_ * billboardScale.y_);
  424. unsigned color = billboard.color_.ToUInt();
  425. float rotationMatrix[2][2];
  426. rotationMatrix[0][0] = Cos(billboard.rotation_);
  427. rotationMatrix[0][1] = Sin(billboard.rotation_);
  428. rotationMatrix[1][0] = -rotationMatrix[0][1];
  429. rotationMatrix[1][1] = rotationMatrix[0][0];
  430. dest[0] = billboard.position_.x_; dest[1] = billboard.position_.y_; dest[2] = billboard.position_.z_;
  431. ((unsigned&)dest[3]) = color;
  432. dest[4] = billboard.uv_.min_.x_; dest[5] = billboard.uv_.min_.y_;
  433. dest[6] = -size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
  434. dest[7] = -size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];
  435. dest[8] = billboard.position_.x_; dest[9] = billboard.position_.y_; dest[10] = billboard.position_.z_;
  436. ((unsigned&)dest[11]) = color;
  437. dest[12] = billboard.uv_.max_.x_; dest[13] = billboard.uv_.min_.y_;
  438. dest[14] = size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
  439. dest[15] = size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];
  440. dest[16] = billboard.position_.x_; dest[17] = billboard.position_.y_; dest[18] = billboard.position_.z_;
  441. ((unsigned&)dest[19]) = color;
  442. dest[20] = billboard.uv_.max_.x_; dest[21] = billboard.uv_.max_.y_;
  443. dest[22] = size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
  444. dest[23] = size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];
  445. dest[24] = billboard.position_.x_; dest[25] = billboard.position_.y_; dest[26] = billboard.position_.z_;
  446. ((unsigned&)dest[27]) = color;
  447. dest[28] = billboard.uv_.min_.x_; dest[29] = billboard.uv_.max_.y_;
  448. dest[30] = -size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
  449. dest[31] = -size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];
  450. dest += 32;
  451. }
  452. vertexBuffer_->Unlock();
  453. vertexBuffer_->ClearDataLost();
  454. }
  455. void BillboardSet::MarkPositionsDirty()
  456. {
  457. Drawable::OnMarkedDirty(node_);
  458. bufferDirty_ = true;
  459. }
  460. }