MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / drawPfx

Method drawPfx

src/render/WorldRender.cpp:523–599  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

521}
522
523void ::Render::drawPfx(World::WorldInstance& world, Components::PfxComponent& pfx, const Render::RenderConfig& config)
524{
525 // TODO: Could optimize this into a global vertexbuffer
526
527 if (!bgfx::isValid(pfx.m_ParticleVB))
528 return;
529
530 // Cache
531 static std::vector<Meshes::WorldStaticMeshVertex> quadVertices;
532
533 Math::float3 right = config.state.cameraWorld.Rotate(Math::float3(1, 0, 0)).normalize() * -0.5f; // 0.5 because they get extended into both directions. We want size 1 in total.
534 Math::float3 up = config.state.cameraWorld.Rotate(Math::float3(0, 1, 0)).normalize() * 0.5f;
535
536 quadVertices.resize(pfx.m_Particles.size() * 6);
537
538 ddPush();
539 for (size_t i = 0; i < pfx.m_Particles.size(); i++)
540 {
541 Components::PfxComponent::Particle& p = pfx.m_Particles[i];
542
543 //ddDrawAxis(pfx.m_Particles[i].position.x, pfx.m_Particles[i].position.y, pfx.m_Particles[i].position.z);
544
545 Utils::billboardQuad(quadVertices[6 * i + 0].Position,
546 quadVertices[6 * i + 1].Position,
547 quadVertices[6 * i + 2].Position,
548 quadVertices[6 * i + 3].Position,
549 quadVertices[6 * i + 4].Position,
550 quadVertices[6 * i + 5].Position,
551 p.position,
552 right * p.size.x,
553 up * p.size.y);
554
555 quadVertices[6 * i + 0].TexCoord = Math::float2(0, 1);
556 quadVertices[6 * i + 1].TexCoord = Math::float2(1, 1);
557 quadVertices[6 * i + 2].TexCoord = Math::float2(0, 0);
558
559 quadVertices[6 * i + 3].TexCoord = Math::float2(0, 0);
560 quadVertices[6 * i + 4].TexCoord = Math::float2(1, 1);
561 quadVertices[6 * i + 5].TexCoord = Math::float2(1, 0);
562
563 for (int j = 0; j < 6; j++)
564 {
565 quadVertices[6 * i + j].Color = p.particleColorU8;
566 }
567 }
568 ddPop();
569
570 if (!pfx.m_Particles.empty())
571 bgfx::updateDynamicVertexBuffer(pfx.m_ParticleVB, 0, bgfx::copy(quadVertices.data(), sizeof(Meshes::WorldStaticMeshVertex) * quadVertices.size()));
572
573 // Do the actual rendering
574 // TODO: Support animated textures
575
576 // Set object-color
577 Math::float4 color(1, 1, 1, 1);
578 bgfx::setUniform(config.uniforms.objectColor, color.v);
579
580 if (pfx.m_Texture.isValid())

Callers

nothing calls this directly

Calls 6

billboardQuadFunction · 0.85
normalizeMethod · 0.80
RotateMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected