示例#1
0
bool RendererLegacy::DrawPointSprites(int count, const vector3f *positions, Material *material, float size)
{
	if (count < 1 || !material || !material->texture0) return false;

	SetBlendMode(BLEND_ALPHA_ONE);
	SetDepthWrite(false);
	VertexArray va(ATTRIB_POSITION | ATTRIB_UV0, count * 6);

	matrix4x4f rot;
	glGetFloatv(GL_MODELVIEW_MATRIX, &rot[0]);
	rot.ClearToRotOnly();
	rot = rot.InverseOf();

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

	//do two-triangle quads. Could also do indexed surfaces.
	//GL2 renderer should use actual point sprites
	//(see history of Render.cpp for point code remnants)
	for (int i=0; i<count; i++) {
		const vector3f &pos = positions[i];

		va.Add(pos+rotv4, vector2f(0.f, 0.f)); //top left
		va.Add(pos+rotv3, vector2f(0.f, 1.f)); //bottom left
		va.Add(pos+rotv1, vector2f(1.f, 0.f)); //top right

		va.Add(pos+rotv1, vector2f(1.f, 0.f)); //top right
		va.Add(pos+rotv3, vector2f(0.f, 1.f)); //bottom left
		va.Add(pos+rotv2, vector2f(1.f, 1.f)); //bottom right
	}
	DrawTriangles(&va, material);
	SetBlendMode(BLEND_SOLID);
	SetDepthWrite(true);

	return true;
}
示例#2
0
void GLRenderState::Bind()
{
  SetBlend(srcBlend, dstBlend);
  SetBlendFunc(blendFunc);
  SetAlphaTest(alphaTest, alphaRef);
  SetCull(cullMode);
  SetDepthTest(depthTest);
  SetDepthWrite(depthWrite);

/*
  if(!curState)
  {

    curState = this;
    return;
  }

  if(curState->GetSrcBlend()  != srcBlend ||
     curState->GetDstBlend()  != dstBlend)
  {
    SetBlend(srcBlend, dstBlend);
  }

  if(curState->GetBlendFunc() != blendFunc)
  {
    SetBlendFunc(blendFunc);
  }

  if(curState->GetAlphaTest() != alphaTest ||
     curState->GetAlphaRef()   != alphaRef)
  {
    SetAlphaTest(alphaTest, alphaRef);
  }

  if(curState->GetDepthTest() != depthTest)
  {
    SetDepthTest(depthTest);
  }

  if(curState->GetDepthWrite() != depthWrite)
  {
    SetDepthWrite(depthWrite);
  }

  if(curState->GetCullMode() != cullMode)
  {
    SetCull(cullMode);
  }
*/
  curState = this;
}
示例#3
0
    void InitFx_Repeater01()
    {
        // effect
        auto _ps = DiEffectManager::GetInstance().CreateParticleSystemTemplate("Fx_repeater1");
        std::shared_ptr<DiTransformUnit> ps(_ps);

        _ps->Start();
        {
            DiParticleElement* element = _ps->CreateElement();
            element->SetRenderer("Billboard");
            auto emitter = element->CreateEmitter("Box");
            
            auto mat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR | SHADER_FLAG_USE_MAP);
            mat->GetShaderParameter()->WriteTexture2D("map", "glow_01.dds");
            mat->SetBlendMode(BLEND_ADD);
            mat->SetDepthWrite(false);
            element->SetMaterialName(mat->GetName());
            
            ((DiBoxEmitter*)emitter)->SetWidth(50);
            ((DiBoxEmitter*)emitter)->SetHeight(70);
            ((DiBoxEmitter*)emitter)->SetDepth(50);
            emitter->position = DiVec3(0, 165, 5);
            
            auto rt = DI_NEW DiAttributeFixed();
            rt->SetValue(30);
            emitter->SetDynEmissionRate(rt);
            
            auto spd = DI_NEW DiAttributeFixed();
            spd->SetValue(20);
            emitter->SetDynVelocity(spd);
            
            auto ttl = DI_NEW DiAttributeRandom();
            ttl->SetMinMax(1, 2);
            emitter->SetDynTotalTimeToLive(ttl);
            
            auto sz = DI_NEW DiAttributeRandom();
            sz->SetMinMax(20, 40);
            emitter->SetDynParticleAllDimensions(sz);
            
            DiColorController* colorCtrl = (DiColorController*)element->CreateController("Color");
            colorCtrl->AddColour(0, DiColor::Black);
            colorCtrl->AddColour(0.5f, DiColor(0.25f, 1, 0.5f));
            colorCtrl->AddColour(1, DiColor::Black);
        }
        {
            DiParticleElement* element = _ps->CreateElement();
            element->SetRenderer("Billboard");
            auto emitter = element->CreateEmitter("Box");
            
            auto mat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR | SHADER_FLAG_USE_MAP);
            auto texture = mat->GetShaderParameter()->WriteTexture2D("map", "mysticenergy2.dds");
            mat->SetBlendMode(BLEND_ADD);
            mat->SetDepthWrite(false);
            element->SetMaterialName(mat->GetName());
            texture->SetAddressing(AM_CLAMP);
            
            ((DiBoxEmitter*)emitter)->SetWidth(50);
            ((DiBoxEmitter*)emitter)->SetHeight(70);
            ((DiBoxEmitter*)emitter)->SetDepth(50);
            emitter->position = DiVec3(0, 165, 5);
            
            auto rt = DI_NEW DiAttributeFixed();
            rt->SetValue(6);
            emitter->SetDynEmissionRate(rt);
            
            auto spd = DI_NEW DiAttributeFixed();
            spd->SetValue(20);
            emitter->SetDynVelocity(spd);
            
            auto ttl = DI_NEW DiAttributeRandom();
            ttl->SetMinMax(1, 2);
            emitter->SetDynTotalTimeToLive(ttl);
            
            auto sz = DI_NEW DiAttributeRandom();
            sz->SetMinMax(20, 40);
            emitter->SetDynParticleAllDimensions(sz);
            
            DiColorController* colorCtrl = (DiColorController*)element->CreateController("Color");
            colorCtrl->AddColour(0, DiColor::Black);
            colorCtrl->AddColour(0.5f, DiColor(0.25f, 1, 0.5f));
            colorCtrl->AddColour(1, DiColor::Black);
            
            DiTextureRotatorController* texrotCtrl = (DiTextureRotatorController*)element->CreateController("TextureRotator");
            texrotCtrl->SetUseOwnRotationSpeed(true);
            auto rotspeed = DI_NEW DiAttributeRandom();
            rotspeed->SetMinMax(-100, 100);
            texrotCtrl->SetRotationSpeed(rotspeed);
            auto rot = DI_NEW DiAttributeRandom();
            rot->SetMinMax(0, 300);
            texrotCtrl->SetRotation(rot);
        }
        
        // create the editor object from the particle system
        DiEditorManager::Get()->LoadParticleSystem(_ps);
    }