Пример #1
0
void Billboard::Render(const matrix4x4f &trans, const RenderData *rd)
{
	PROFILE_SCOPED()
	Graphics::Renderer *r = GetRenderer();

	const matrix3x3f rot = trans.GetOrient().Transpose();

	//some hand-tweaked scaling, to make the lights seem larger from distance
	const float size = m_size * Graphics::GetFovFactor() * Clamp(trans.GetTranslate().Length() / 500.f, 0.25f, 15.f);

	const vector3f rotv1 = rot * vector3f(size*0.5f, -size*0.5f, 0.0f);
	const vector3f rotv2 = rot * vector3f(size*0.5f, size*0.5f, 0.0f);

	if( !m_vbuffer.Valid() )
	{
		//create buffer and upload data
		Graphics::VertexBufferDesc vbd;
		vbd.attrib[0].semantic = Graphics::ATTRIB_POSITION;
		vbd.attrib[0].format   = Graphics::ATTRIB_FORMAT_FLOAT3;
		vbd.attrib[1].semantic = Graphics::ATTRIB_UV0;
		vbd.attrib[1].format   = Graphics::ATTRIB_FORMAT_FLOAT2;
		vbd.numVertices = 6;
		vbd.usage = Graphics::BUFFER_USAGE_DYNAMIC;	// we could be updating this per-frame
		m_vbuffer.Reset( r->CreateVertexBuffer(vbd) );
	}

#pragma pack(push, 4)
	struct PosUVVert {
		vector3f pos;
		vector2f uv;
	};
#pragma pack(pop)
	PosUVVert* vtxPtr = m_vbuffer->Map<PosUVVert>(Graphics::BUFFER_MAP_WRITE);
	vtxPtr[0].pos = (m_offset - rotv1); vtxPtr[0].uv = vector2f(0.f, 0.f); //top left
	vtxPtr[1].pos = (m_offset - rotv2); vtxPtr[1].uv = vector2f(0.f, 1.f); //bottom left
	vtxPtr[2].pos = (m_offset + rotv2); vtxPtr[2].uv = vector2f(1.f, 0.f); //top right
	vtxPtr[3].pos = (m_offset + rotv2); vtxPtr[3].uv = vector2f(1.f, 0.f); //top right
	vtxPtr[4].pos = (m_offset - rotv2); vtxPtr[4].uv = vector2f(0.f, 1.f); //bottom left
	vtxPtr[5].pos = (m_offset + rotv1); vtxPtr[5].uv = vector2f(1.f, 1.f); //bottom right
	m_vbuffer->Unmap();

	r->SetTransform(trans);
	r->DrawBuffer(m_vbuffer.Get(), m_renderState, m_material.Get());

	r->GetStats().AddToStatCount(Graphics::Stats::STAT_BILLBOARD, 1);
}
Пример #2
0
void StaticGeometry::DrawBoundingBox(const Aabb &bb)
{
	const vector3f min(bb.min.x, bb.min.y, bb.min.z);
	const vector3f max(bb.max.x, bb.max.y, bb.max.z);
	const vector3f fbl(min.x, min.y, min.z); //front bottom left
	const vector3f fbr(max.x, min.y, min.z); //front bottom right
	const vector3f ftl(min.x, max.y, min.z); //front top left
	const vector3f ftr(max.x, max.y, min.z); //front top right
	const vector3f rtl(min.x, max.y, max.z); //rear top left
	const vector3f rtr(max.x, max.y, max.z); //rear top right
	const vector3f rbl(min.x, min.y, max.z); //rear bottom left
	const vector3f rbr(max.x, min.y, max.z); //rear bottom right

	const Color c(Color::WHITE);

	std::unique_ptr<Graphics::VertexArray> vts(new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_DIFFUSE));

	//Front face
	vts->Add(ftr, c); //3
	vts->Add(fbr, c); //1
	vts->Add(fbl, c); //0

	vts->Add(fbl, c); //0
	vts->Add(ftl, c); //2
	vts->Add(ftr, c); //3

	//Rear face
	vts->Add(rbr, c); //7
	vts->Add(rtr, c); //5
	vts->Add(rbl, c); //6

	vts->Add(rbl, c); //6
	vts->Add(rtr, c); //5
	vts->Add(rtl, c); //4

	//Top face
	vts->Add(rtl, c); //4
	vts->Add(rtr, c); //5
	vts->Add(ftr, c); //3

	vts->Add(ftr, c); //3
	vts->Add(ftl, c); //2
	vts->Add(rtl, c); //4

	//bottom face
	vts->Add(fbr, c); //1
	vts->Add(rbr, c); //7
	vts->Add(rbl, c); //6

	vts->Add(rbl, c); //6
	vts->Add(fbl, c); //0
	vts->Add(fbr, c); //1

	//left face
	vts->Add(fbl, c); //0
	vts->Add(rbl, c); //6
	vts->Add(rtl, c); //4

	vts->Add(rtl, c); //4
	vts->Add(ftl, c); //2
	vts->Add(fbl, c); //0

	//right face
	vts->Add(rtr, c); //5
	vts->Add(rbr, c); //7
	vts->Add(fbr, c); //1

	vts->Add(fbr, c); //1
	vts->Add(ftr, c); //3
	vts->Add(rtr, c); //5

	Graphics::Renderer *r = GetRenderer();

	Graphics::RenderStateDesc rsd;
	rsd.cullMode = Graphics::CULL_NONE;

	RefCountedPtr<Graphics::VertexBuffer> vb;
	//create buffer and upload data
	Graphics::VertexBufferDesc vbd;
	vbd.attrib[0].semantic = Graphics::ATTRIB_POSITION;
	vbd.attrib[0].format   = Graphics::ATTRIB_FORMAT_FLOAT3;
	vbd.attrib[1].semantic = Graphics::ATTRIB_DIFFUSE;
	vbd.attrib[1].format   = Graphics::ATTRIB_FORMAT_UBYTE4;
	vbd.numVertices = vts->GetNumVerts();
	vbd.usage = Graphics::BUFFER_USAGE_STATIC;
	vb.Reset( m_renderer->CreateVertexBuffer(vbd) );
	vb->Populate( *vts );

	r->SetWireFrameMode(true);
	r->DrawBuffer(vb.Get(), r->CreateRenderState(rsd), Graphics::vtxColorMaterial);
	r->SetWireFrameMode(false);
}