//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- 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)); } } } }
//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- 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; }