コード例 #1
0
//----------------------------------------------------------------------------
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;
}
コード例 #2
0
ファイル: MaterialNode.cpp プロジェクト: chenwenbin928/tamy
void MaterialNode::createLayout( const MaterialInstance& host ) const
{
    for( OutputsMap::const_iterator it = m_outputs.begin(); it != m_outputs.end(); ++it )
    {
        (*it)->createLayout( host.data() );
    }

    onCreateLayout( host );
}
コード例 #3
0
//----------------------------------------------------------------------------
void RawTerrainPage::UpdateWorldData (double applicationTime)
{
	TriMesh::UpdateWorldData(applicationTime);

	PX2::Light *light = 0;
	for (int i=0; i<(int)mInfulencedLights.size(); i++)
	{
		Light *lit = mInfulencedLights[i];
		if (lit->GetType() == Light::LT_DIRECTIONAL)
		{
			light = lit;
			break;
		}
	}

	if (light!=0 && light!=mDirLight)
	{
		mDirLight = light;

		mMtlInst->SetVertexConstant(0, "gLightColour",
			new0 LightDiffuseConstant(mDirLight));
		mMtlInst->SetVertexConstant(0, "gLightAttenuation",
			new0 LightAttenuationConstant(mDirLight));
		mMtlInst->SetVertexConstant(0, "gLightModelDirection",
			new0 LightModelDVectorConstant(mDirLight));

		for (int i=0; i<(int)mJunglers.size(); i++)
		{
			Jungler *jungler = mJunglers[i];
			
			MaterialInstance *inst = jungler->GetMtlInst();
			if (inst)
			{
				inst->SetVertexConstant(0, "gLightColour",
					new0 LightDiffuseConstant(mDirLight));
				inst->SetVertexConstant(0, "gLightAttenuation",
					new0 LightAttenuationConstant(mDirLight));
				inst->SetVertexConstant(0, "gLightModelDirection",
					new0 LightModelDVectorConstant(mDirLight));
			}
		}
	}
}
コード例 #4
0
ファイル: PX2UIText.cpp プロジェクト: PhoenixSteam/Phoenix3D
//----------------------------------------------------------------------------
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;
}
コード例 #5
0
ファイル: material.cpp プロジェクト: cgaebel/gluon
bool Material::load( const QUrl& url )
{
    if(!url.isValid())
        return false;

    QFile file(url.toLocalFile());
    if(!file.open(QIODevice::ReadOnly))
        return false;

    QByteArray data = file.readAll();

    QList<GluonObject*> objects = GluonCore::GDLHandler::instance()->parseGDL(data, this);
    if(objects.count() <= 0)
        return false;

    GluonCore::GluonObject* obj = objects.at(0);
    QList<QByteArray> properties = obj->dynamicPropertyNames();
    MaterialInstance* defaultInstance = d->instances.find("default").value();

    foreach(QByteArray propertyName, properties)
    {
        if(propertyName == "vertexShader")
        {
            d->vertShaderSource = obj->property(propertyName).toByteArray();
        }
        else if(propertyName == "fragmentShader")
        {
            d->fragShaderSource = obj->property(propertyName).toByteArray();
        }
        else if(propertyName == "languageVersion")
        {
            d->languageVersion = obj->property(propertyName).toString();
        }
        else
        {
            defaultInstance->setProperty(propertyName, obj->property(propertyName));
        }
    }

    return true;
}
コード例 #6
0
//----------------------------------------------------------------------------
void BoxSurface::DisableSorting ()
{
	for (int face = 0; face < 6; face++)
	{
		TriMesh* mesh = StaticCast<TriMesh>(GetChild(face));
		MaterialInstance* instance = mesh->GetMaterialInstance();
		const int numPasses = instance->GetNumPasses();
		for (int p = 0; p < numPasses; ++p)
		{
			const MaterialPass* pass = instance->GetPass(p);
			CullProperty* cproperty = pass->GetCullProperty();
			cproperty->Enabled = true;
			DepthProperty* dproperty = pass->GetDepthProperty();
			dproperty->Enabled = true;
			dproperty->Writable = true;
			dproperty->Compare = DepthProperty::CM_LEQUAL;
		}
	}

	mDoSort = false;
}
//----------------------------------------------------------------------------
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;
}
コード例 #8
0
ファイル: MNCamera.cpp プロジェクト: chenwenbin928/tamy
void MNCamera::preRender( Renderer& renderer, const MaterialInstance& instance, const MaterialEntity& entity ) const
{
   Camera& camera = renderer.getActiveCamera();

   RuntimeDataBuffer& data = instance.data();
   m_nearZ->setValue( data, camera.getNearClippingPlane() );
   m_farZ->setValue( data, camera.getFarClippingPlane() );
   m_viewportWidth->setValue( data, (float)renderer.getViewportWidth() );
   m_viewportHeight->setValue( data, (float)renderer.getViewportHeight() );

   Matrix invMtx, transInvMtx;

   const Matrix& viewMtx = camera.getViewMtx();
   invMtx.setInverse( viewMtx );
   transInvMtx.setTransposed( invMtx );
   m_invView->setValue( data, transInvMtx );

   const Matrix& projMtx = camera.getProjectionMtx();
   invMtx.setInverse( projMtx );
   transInvMtx.setTransposed( invMtx );
   m_invProj->setValue( data, transInvMtx );
}
コード例 #9
0
void MNSpatialEntity::preRender( Renderer& renderer, const MaterialInstance& instance, const MaterialEntity& entity ) const
{
   RuntimeDataBuffer& data = instance.data();
   SpatialEntity* parentNode = data[ m_parentNode ];
   if ( !parentNode )
   {
      // initialize the parent entity if it wasn't initialized yet
      parentNode = DynamicCast< SpatialEntity >( entity.getParent() );
      data[ m_parentNode ] = parentNode;
   }

   if ( parentNode )
   {
      Camera& camera = renderer.getActiveCamera();

      const Matrix& worldMtx = parentNode->getGlobalMtx();
      m_worldMtx->setValue( data, worldMtx );

      Matrix worldView;
      worldView.setMul( worldMtx, camera.getViewMtx() );
      m_worldViewMtx->setValue( data, worldView );
   }
}
コード例 #10
0
ファイル: MNBool.cpp プロジェクト: chenwenbin928/tamy
void MNBool::preRender( Renderer& renderer, const MaterialInstance& instance, const MaterialEntity& entity ) const
{
    m_output->setValue( instance.data(), m_value );
}
コード例 #11
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;
}
コード例 #12
0
//----------------------------------------------------------------------------
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;
}
コード例 #13
0
void MNSpatialEntity::onCreateLayout( const MaterialInstance& host ) const
{
   RuntimeDataBuffer& data = host.data();
   data.registerVar( m_parentNode );
   data[ m_parentNode ] = NULL;
}
コード例 #14
0
//-----------------------------------------------------------------------------
void ProjTreeItem::SetTreeLevel(ProjTreeLevel level, bool isShowHelpNode)
{
	mTreeLevel = level;
	mIsShowHelpNode = isShowHelpNode;

	Project *proj = DynamicCast<Project>(mObject);
	Scene *scene = DynamicCast<Scene>(mObject);
	if (proj || scene)
		return;

	Actor *actor = DynamicCast<Actor>(mObject);
	Movable *mov = DynamicCast<Movable>(mObject);
	Node *node = DynamicCast<Node>(mObject);
	Renderable *renderable = DynamicCast<Renderable>(mObject);
	EffectableController *effectableCtrl = DynamicCast<EffectableController>(mObject);
	Material *mtl = DynamicCast<Material>(mObject);
	MaterialTechnique *mtlTechnique = DynamicCast<MaterialTechnique>(mObject);
	MaterialPass *mtlPass = DynamicCast<MaterialPass>(mObject);

	if (!mObject)
	{ // IT_CATALOG
		for (int i = 0; i < (int)mChildItems.size(); i++)
		{
			ProjTreeItem *item = mChildItems[i];
			if (item) item->SetTreeLevel(level, isShowHelpNode);
		}
		return;
	}
	else
	{
		ClearChildren();
	}

	bool addCtrl = false;
	bool addModule = false;
	bool addNode = false;
	bool addMaterial = false;

	if (PTL_GENERAL == mTreeLevel)
	{
	}
	else if (PTL_CHILDREN == mTreeLevel)
	{
		if (!scene && !proj && node)
		{
			addNode = true;
		}
	}
	else if (PTL_CONTROLS == mTreeLevel)
	{
		if (!scene && !proj && mov)
		{
			addCtrl = true;
		}

		if (!scene && !proj && node)
		{
			addNode = true;
		}

		if (effectableCtrl)
		{
			addModule = true;
		}
	}
	else if (PTL_MATERIALS == mTreeLevel)
	{
		if (!scene && !proj && mov)
		{
			addCtrl = true;
		}

		if (!scene && !proj && node)
		{
			addNode = true;
		}

		if (renderable)
		{
			addMaterial = true;
		}
	}
	else if (PTL_DETAIL == mTreeLevel)
	{
		if (!scene && !proj && mov)
		{
			addCtrl = true;
		}

		if (!scene && !proj && node)
		{
			addNode = true;
		}

		if (renderable)
		{
			addMaterial = true;
		}
	}

	if (addCtrl)
	{
		int numCtrls = mov->GetNumControllers();
		for (int i = 0; i < numCtrls; i++)
		{
			Controller *ctrl = mov->GetController(i);

			AddChild(ctrl, mIconID, mTreeLevel, mIsShowHelpNode);
		}
	}

	if (addMaterial)
	{
		MaterialInstance *mtlInst = renderable->GetMaterialInstance();
		Material *mtl = mtlInst->GetMaterial();
		AddChild(mtl, mIconID, mTreeLevel, mIsShowHelpNode);
	}
	if (mtl)
	{
		int numTechniques = mtl->GetNumTechniques();
		for (int i = 0; i < numTechniques; i++)
		{
			MaterialTechnique *mtlTechnique = mtl->GetTechnique(i);
			AddChild(mtlTechnique, mIconID, mTreeLevel, isShowHelpNode);
		}
	}
	if (mtlTechnique)
	{
		int numPasses = mtlTechnique->GetNumPasses();
		for (int i = 0; i < numPasses; i++)
		{
			MaterialPass *mtlPass = mtlTechnique->GetPass(i);
			AddChild(mtlPass, mIconID, mTreeLevel, isShowHelpNode);
		}
	}
	if (mtlPass)
	{
		AddChild(mtlPass->GetVertexShader(), mIconID, mTreeLevel, isShowHelpNode);
		AddChild(mtlPass->GetPixelShader(), mIconID, mTreeLevel, isShowHelpNode);

		AddChild(mtlPass->GetAlphaProperty(), mIconID, mTreeLevel, isShowHelpNode);
		AddChild(mtlPass->GetCullProperty(), mIconID, mTreeLevel, isShowHelpNode);
		AddChild(mtlPass->GetDepthProperty(), mIconID, mTreeLevel, isShowHelpNode);
		AddChild(mtlPass->GetOffsetProperty(), mIconID, mTreeLevel, isShowHelpNode);
		AddChild(mtlPass->GetStencilProperty(), mIconID, mTreeLevel, isShowHelpNode);
		AddChild(mtlPass->GetWireProperty(), mIconID, mTreeLevel, isShowHelpNode);
	}

	if (addModule)
	{
		int numModules = effectableCtrl->GetNumModules();
		for (int i = 0; i < numModules; i++)
		{
			EffectModule *module = effectableCtrl->GetModule(i);
			AddChild(module, mIconID, mTreeLevel, mIsShowHelpNode);
		}
	}

	if (addNode)
	{
		int numChildren = node->GetNumChildren();
		for (int i = 0; i < numChildren; i++)
		{
			Movable *child = node->GetChild(i);
			if (child)
			{
				bool ingore = false;
				if (!isShowHelpNode && ("HelpNode" == child->GetName()))
					ingore = true;

				if (!ingore)
				{
					AddChild(child, mIconID, mTreeLevel, mIsShowHelpNode);
				}
			}
		}
	}
}