Esempio n. 1
0
void Material::Draw(PolygonGroup * group, InstanceMaterialState * instanceMaterialState)
{
	if(!RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::MATERIAL_DRAW))
	{
		return;
	}

	if(isTranslucent && !RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::TRANSPARENT_DRAW))
	{
		return;
	}

	if(!isTranslucent && !RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::OPAQUE_DRAW))
	{
		return;
	}

	//Dizz: uniformFogDensity != -1 is a check if fog is inabled in shader
	if(isFogEnabled && (uniformFogDensity != -1) && !RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::FOG_ENABLE))
	{
		RebuildShader();
	}

	if(isFogEnabled && (uniformFogDensity == -1) && RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::FOG_ENABLE))
	{
		RebuildShader();
	}

	RenderManager::Instance()->SetRenderData(group->renderDataObject);

	eBlendMode oldSrc;
	eBlendMode oldDst;
	if(isAlphablend)
	{
		oldSrc = RenderManager::Instance()->GetSrcBlend();
		oldDst = RenderManager::Instance()->GetDestBlend();
	}

	PrepareRenderState(instanceMaterialState);

    // TODO: rethink this code
    if (group->renderDataObject->GetIndexBufferID() != 0)
    {
        RenderManager::Instance()->HWDrawElements(PRIMITIVETYPE_TRIANGLELIST, group->indexCount, EIF_16, 0);
    }
    else
    {
        RenderManager::Instance()->HWDrawElements(PRIMITIVETYPE_TRIANGLELIST, group->indexCount, EIF_16, group->indexArray);
    }

    
	//RenderManager::Instance()->SetTexture(0, 1); 
	//RenderManager::Instance()->SetState(RenderStateBlock::DEFAULT_3D_STATE);
	//if(isAlphablend)
	//{
	//	RenderManager::Instance()->SetBlendMode(oldSrc, oldDst);
	//}
}
Esempio n. 2
0
Material::eValidationResult Material::Validate(PolygonGroup * polygonGroup)
{
    RebuildShader();
    /*
        General check if number of attributes in shader is 
     */
    int32 format = polygonGroup->GetFormat();
    int32 formatBitCount = 0; // number of attributes in polygroup available in the shader
    for (int bit = 1; bit <= EVF_HIGHER_BIT; bit <<= 1)
    {
        if (format & bit)
        {
            if (shader->GetAttributeIndex((eVertexFormat)bit) != -1)
                formatBitCount++;
        }
    }
    // Check if we have more attributes 
    if (shader->GetAttributeCount() > formatBitCount)
    {
        //shader->Get
        
        
        
        return VALIDATE_INCOMPATIBLE;
    }
    
    
    return VALIDATE_COMPATIBLE;
}
Esempio n. 3
0
void Material::SetSetupLightmap(bool _isSetupLightmap)
{
	if(isSetupLightmap != _isSetupLightmap)
	{
		isSetupLightmap = _isSetupLightmap;
		RebuildShader();
	}
}
Esempio n. 4
0
void Material::SetAlphablend(bool _isAlphablend)
{
	isAlphablend = _isAlphablend;
	RebuildShader();
}
Esempio n. 5
0
void Material::SetFog(bool _isFogEnabled)
{
    isFogEnabled = _isFogEnabled;
    RebuildShader();
}
Esempio n. 6
0
void Material::SetOpaque(bool _isOpaque)
{
    isTranslucent = _isOpaque;
    RebuildShader();
}
Esempio n. 7
0
void Material::SetType(eType _type)
{
    type = _type;
    RebuildShader();
}
Esempio n. 8
0
void Material::EnableTextureShift(const bool & isEnabled)
{
    isTexture0ShiftEnabled = isEnabled;
    RebuildShader();
    
}
Esempio n. 9
0
void Material::EnableFlatColor(const bool & isEnabled)
{
    isFlatColorEnabled = isEnabled;
    RebuildShader();
    
}
Esempio n. 10
0
void Material::Draw(PolygonGroup * group, InstanceMaterialState * instanceMaterialState)
{
	if(!RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::MATERIAL_DRAW))
	{
		return;
	}

	if(isOpaque && !RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::OPAQUE_DRAW))
	{
		return;
	}

	//Dizz: uniformFogDensity != -1 is a check if fog is inabled in shader
	if(isFogEnabled && (uniformFogDensity != -1) && !RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::FOG_ENABLE))
	{
		RebuildShader();
	}

	if(isFogEnabled && (uniformFogDensity == -1) && RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::FOG_ENABLE))
	{
		RebuildShader();
	}

	RenderManager::Instance()->SetRenderData(group->renderDataObject);

	eBlendMode oldSrc;
	eBlendMode oldDst;
	if(isAlphablend)
	{
		oldSrc = RenderManager::Instance()->GetSrcBlend();
		oldDst = RenderManager::Instance()->GetDestBlend();
	}

	PrepareRenderState();

    if (instanceMaterialState)
    {
        Camera * camera = scene->GetCurrentCamera();
        LightNode * lightNode0 = instanceMaterialState->GetLight(0);
        if (lightNode0 && camera)
        {
            if (uniformLightPosition0 != -1)
            {
                const Matrix4 & matrix = camera->GetMatrix();
                Vector3 lightPosition0InCameraSpace = lightNode0->GetPosition() * matrix;
                
                shader->SetUniformValue(uniformLightPosition0, lightPosition0InCameraSpace); 
            }
            if (uniformMaterialLightAmbientColor != -1)
            {
                shader->SetUniformValue(uniformMaterialLightAmbientColor, lightNode0->GetAmbientColor() * GetAmbientColor());
            }
            if (uniformMaterialLightDiffuseColor != -1)
            {
                shader->SetUniformValue(uniformMaterialLightDiffuseColor, lightNode0->GetDiffuseColor() * GetDiffuseColor());
            }
            if (uniformMaterialLightSpecularColor != -1)
            {
                shader->SetUniformValue(uniformMaterialLightSpecularColor, lightNode0->GetSpecularColor() * GetSpecularColor());
            }
            if (uniformMaterialSpecularShininess != -1)
            {
                shader->SetUniformValue(uniformMaterialSpecularShininess, shininess);
            }
            
            if (uniformLightIntensity0 != -1)
            {
                shader->SetUniformValue(uniformLightIntensity0, lightNode0->GetIntensity());
            }
            if (uniformLightAttenuationQ != -1)
            {
                //shader->SetUniformValue(uniformLightAttenuationQ, lightNode0->GetAttenuation());
            }
        }
    }
    
    // TODO: rethink this code
    if (group->renderDataObject->GetIndexBufferID() != 0)
	{
		RenderManager::Instance()->HWDrawElements(PRIMITIVETYPE_TRIANGLELIST, group->indexCount, EIF_16, 0);
	}else
	{
		RenderManager::Instance()->HWDrawElements(PRIMITIVETYPE_TRIANGLELIST, group->indexCount, EIF_16, group->indexArray);
	}
    
	RenderManager::Instance()->SetTexture(0, 1); 
	RenderManager::Instance()->SetState(RenderStateBlock::DEFAULT_3D_STATE);
	if(isAlphablend)
	{
		RenderManager::Instance()->SetBlendMode(oldSrc, oldDst);
	}
}
Esempio n. 11
0
void Material::SetOpaque(bool _isOpaque)
{
    isOpaque = _isOpaque;
    RebuildShader();
}