Esempio n. 1
0
//----------------------------------------------------------------------------
MaterialInstance* UIMaterial::CreateInstance (Texture2D* texture)
const
{
    MaterialInstance* instance = new0 MaterialInstance(this, 0);
    instance->SetVertexConstant(0, "gPVWMatrix", new0 PVWMatrixConstant());
    instance->SetPixelTexture(0, "gDiffuseSampler", texture);

    return instance;
}
//----------------------------------------------------------------------------
MaterialInstance* Texture2DMaterial::CreateInstance (Texture2D* texture) const
{
	MaterialInstance* instance = new0 MaterialInstance(this, 0);
	instance->SetVertexConstant(0, "gPVWMatrix", new0 PVWMatrixConstant());
	instance->SetPixelTexture(0, "gDiffuseSampler", texture);

	//Shader::SamplerFilter filter = GetPixelShader()->GetFilter(0);
	//if (filter != Shader::SF_NEAREST && filter != Shader::SF_LINEAR
	//	&&  !texture->HasMipmaps() && texture->GetFormat()!=Texture::TF_DXT1
	//	&& texture->GetFormat()!=Texture::TF_DXT3 && texture->GetFormat()!=
	//	Texture::TF_DXT5)
	//{
	//	//texture->GenerateMipmaps();
	//}

	return instance;
}
//----------------------------------------------------------------------------
MaterialInstance* StandardESMaterial_AlphaTest::CreateInstance (
	PX2::Texture2D *diffTex, PX2::Light *dirLight, PX2::Shine* shine) const
{
	MaterialInstance *instance = new0 MaterialInstance(this, 0);

	if (!dirLight)
	{
		dirLight = new0 Light(Light::LT_DIRECTIONAL);
		dirLight->Ambient = Float4(1.0f, 1.0f, 1.0f, 1.0f);
		dirLight->Diffuse = Float4(1.0f, 1.0f, 1.0f, 1.0f);
	}
	if (!shine)
	{
		shine = new0 Shine();
		shine->Ambient = Float4(1.0f, 1.0f, 1.0f, 1.0f);
		shine->Diffuse = Float4(1.0f, 1.0f, 1.0f, 1.0f);
	}

	// vertex
	instance->SetVertexConstant(0, "gPVWMatrix", new0 PVWMatrixConstant());
	instance->SetVertexConstant(0, "gShineEmissive", 
		new0 ShineEmissiveConstant(shine));
	instance->SetVertexConstant(0, "gShineAmbient",
		new0 ShineAmbientConstant(shine));
	instance->SetVertexConstant(0, "gShineDiffuse",
		new0 ShineDiffuseConstant(shine));
	instance->SetVertexConstant(0, "gLightAmbient",
		new0 LightAmbientConstant(dirLight));
	instance->SetVertexConstant(0, "gLightDiffuse",
		new0 LightDiffuseConstant(dirLight));
	instance->SetVertexConstant(0, "gLightModelDirection",
		new0 LightModelDVectorConstant(dirLight));

	// pixel
	if (diffTex)
	{
		if (!diffTex->HasMipmaps())
			diffTex->GenerateMipmaps();
	}

	instance->SetPixelTexture(0, "gDiffuseSampler", diffTex);

	return instance;
}
//----------------------------------------------------------------------------
MaterialInstance* JunglerMaterial::CreateInstance (
	PX2::Texture2D *diffTex, PX2::Light *dirLight, PX2::Shine* shine) const
{
	MaterialInstance *instance = new0 MaterialInstance(this, 0);

	if (!dirLight)
	{
		dirLight = new0 Light(Light::LT_DIRECTIONAL);
		dirLight->Ambient = Float4(1.0f, 1.0f, 1.0f, 1.0f);
		dirLight->Diffuse = Float4(1.0f, 1.0f, 1.0f, 1.0f);
	}
	if (!shine)
	{
		shine = new0 Shine();
		shine->Ambient = Float4(0.3f, 0.3f, 0.3f, 1.0f);
		shine->Diffuse = Float4(1.0f, 1.0f, 1.0f, 1.0f);
	}

	// vertex
	instance->SetVertexConstant(0, "gPVWMatrix", new0 PVWMatrixConstant());
	instance->SetVertexConstant(0, "gShineEmissive", 
		new0 ShineEmissiveConstant(shine));
	instance->SetVertexConstant(0, "gShineAmbient",
		new0 ShineAmbientConstant(shine));
	instance->SetVertexConstant(0, "gShineDiffuse",
		new0 ShineDiffuseConstant(shine));
	instance->SetVertexConstant(0, "gLightColour",
		new0 LightDiffuseConstant(dirLight));
	instance->SetVertexConstant(0, "gLightAttenuation",
		new0 LightAttenuationConstant(dirLight));
	instance->SetVertexConstant(0, "gLightModelDirection",
		new0 LightModelDVectorConstant(dirLight));
	UserConstantPtr userConst = new0 UserConstant();
	instance->SetVertexConstant(0, "gUser", userConst);
	ShaderFloat *cSF = instance->GetVertexConstant(0, "gUser");
	(*cSF)[0] = 0.0f;
	(*cSF)[1] = 1.0f;
	(*cSF)[2] = 0.1f;

	// pixel
	instance->SetPixelTexture(0, "gDiffuseSampler", diffTex);

	return instance;
}
Esempio n. 5
0
//----------------------------------------------------------------------------
void UIText::ReCreate()
{
	if (RU_NONE == mRectUseage)
	{
		PX2_FM.RenderText(this, mFont,
			mText.c_str(), mDrawStyle, mOffset[0], mOffset[1], mSpace, 
			mFontColor, mBorderShadowColor, mShadowBorderSize,
			mFontScale, mIsDoCharTranslate, 0.0f);
	}
	else if (RU_ALIGNS == mRectUseage)
	{
		PX2_FM.RenderTextRect(this, mFont, mText.c_str(),
			mDrawStyle, mTextAligns, mRect, mSpace, mOffset[0], mOffset[1],
			mFontColor, mBorderShadowColor, mShadowBorderSize, mFontScale,
			mIsDoCharTranslate);
	}
	else if (RU_CLIPWARP == mRectUseage)
	{
		PX2_FM.RenderTextRect(this, mFont, mText.c_str(),
			mDrawStyle, mRect, mSpace, mOffset[0], mOffset[1],
			mIsAutoWarp, mFontColor,
			mBorderShadowColor, mShadowBorderSize, mFontScale,
			mIsDoCharTranslate, mIsPointAsPunctuation);
	}

	mFontTex = mFont->GetTexture();

	MaterialInstance *mtlInst = GetMaterialInstance();
	mtlInst->SetPixelTexture(0, "SamplerBase", mFontTex);

	VertexBuffer *vb = GetVertexBuffer();
	IndexBuffer *ib = GetIndexBuffer();

	if ((vb && Renderer::IsOneBind(vb)) || (ib && Renderer::IsOneBind(ib)))
	{
		Renderer::UpdateAll(vb);
		Renderer::UpdateAll(ib);
	}

	mIsNeedReCreate = false;
}
Esempio n. 6
0
//----------------------------------------------------------------------------
void FramesMesh::_Cal(const std::string &texPackFilename)
{
	const TexPack &texPack = PX2_RM.GetTexPack(texPackFilename);
	if (!texPack.IsValid()) return;

	std::string outPath;
	std::string outBaseFilename;
	StringHelp::SplitFilename(texPackFilename, outPath, outBaseFilename);

	std::string outBaseName;
	std::string outExt;
	StringHelp::SplitBaseFilename(outBaseFilename, outBaseName, outExt);

	VertexFormat *vf = PX2_GR.GetVertexFormat(GraphicsRoot::VFT_PCT1);
	SetVertexFormat(vf);

	mNumAllFrames = (int)texPack.Elements.size();
	mNumFramesPerDir = mNumAllFrames / mNumDir;
	if (0 == mNumFramesPerDir)
	{
		//assertion(false, "no frames");
		//return;
	}

	VBIBObj &obj = VBIBManager::GetSingleton().GetVBID(texPackFilename);
	if (obj.IsValued)
	{
		SetVertexBuffer(obj.mVB);
		SetIndexBuffer(obj.mIB);
	}
	else
	{
		int numVertex = mNumAllFrames * 4;
		int numIndex = mNumAllFrames * 6;

		int frameIndex = 0;
		VertexBuffer *vb = new0 VertexBuffer(numVertex, vf->GetStride());
		VertexBufferAccessor vba(vf, vb);
		for (int i = 0; i < mNumDir; i++)
		{
			for (int j = 0; j < mNumFramesPerDir; j++)
			{
				std::string eleName = outBaseName + "_" + StringHelp::IntToString(i * 45) + "_" + StringHelp::IntToString(j + 1);

				const TexPackElement &ele = PX2_RM.GetTexPackElement(texPackFilename, eleName);

				float xPlusPer = 0.0f;
				float widthPer = 0.0f;
				float zPlusPer = 0.0f;
				float heightPer = 0.0f;
				if (0 != ele.OW)
				{
					xPlusPer = (float)ele.OX / (float)ele.OW;
					widthPer = (float)ele.W / (float)ele.OW;
				}
				if (0 != ele.OH)
				{
					zPlusPer = 1.0f - (float)(ele.OY + ele.H) / (float)ele.OH;
					heightPer = (float)ele.H / (float)ele.OH;
				}

				float width = mSize;
				float height = mSize;

				float xPos = 0.0f - width * 0.5f;
				float zPos = 0.0f - height * 0.5f;
				xPos += xPlusPer * width;
				zPos += zPlusPer * height;

				width *= widthPer;
				height *= heightPer;

				Float3 p0 = Float3(xPos, zPos, 0.0f);
				Float3 p1 = Float3(xPos + width, zPos, 0.0f);
				Float3 p2 = Float3(xPos, zPos + height, 0.0f);
				Float3 p3 = Float3(xPos + width, zPos + height, 0.0f);

				float uBegin = (float)ele.X / (float)ele.TexWidth;
				float uEnd = (float)(ele.X + ele.W) / (float)ele.TexWidth;
				float vBegin = (float)(ele.TexHeight - ele.Y - ele.H) / (float)ele.TexHeight;
				float vEnd = (float)(ele.TexHeight - ele.Y) / (float)ele.TexHeight;

				vba.Position<Float3>(frameIndex * 4 + 0) = p0;
				vba.Position<Float3>(frameIndex * 4 + 1) = p1;
				vba.Position<Float3>(frameIndex * 4 + 2) = p2;
				vba.Position<Float3>(frameIndex * 4 + 3) = p3;

				vba.TCoord<Float2>(0, frameIndex * 4 + 0) = Float2(uBegin, vBegin);
				vba.TCoord<Float2>(0, frameIndex * 4 + 1) = Float2(uEnd, vBegin);
				vba.TCoord<Float2>(0, frameIndex * 4 + 2) = Float2(uBegin, vEnd);
				vba.TCoord<Float2>(0, frameIndex * 4 + 3) = Float2(uEnd, vEnd);

				frameIndex++;
			}
		}

		IndexBuffer *ib = new0 IndexBuffer(numIndex, 2);
		for (int i = 0; i < mNumAllFrames; i++)
		{
			unsigned short *indices = (unsigned short*)ib->GetData();
			indices[i * 6 + 0] = (uint16_t)(i * 4 + 0);
			indices[i * 6 + 1] = (uint16_t)(i * 4 + 1);
			indices[i * 6 + 2] = (uint16_t)(i * 4 + 2);
			indices[i * 6 + 3] = (uint16_t)(i * 4 + 1);
			indices[i * 6 + 4] = (uint16_t)(i * 4 + 3);
			indices[i * 6 + 5] = (uint16_t)(i * 4 + 2);
		}

		SetVertexBuffer(vb);
		SetIndexBuffer(ib);

		VBIBManager::GetSingleton().AddVBIB(texPackFilename, vb, ib);
	}

	Texture2D *tex = (Texture2D*)PX2_RM.BlockLoad(texPack.ImageFullPath);

	MaterialInstance *mi = new0 MaterialInstance(
		"Data/engine_mtls/tex2d/tex2d.px2obj", "tex2d", false);
	mi->SetPixelTexture(0, "SampleBase", tex);
	SetMaterialInstance(mi);

	mi->GetMaterial()->GetCullProperty(0, 0)->Enabled = false;

	mIsNeedReCal = false;
}