本文整理汇总了C++中TextureUnitState类的典型用法代码示例。如果您正苦于以下问题:C++ TextureUnitState类的具体用法?C++ TextureUnitState怎么用?C++ TextureUnitState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextureUnitState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: LOG_INFO
//-----------------------------------------------------------------------
void MaterialService::createStandardMaterial(unsigned int idx, std::string matName, std::string textureName,
std::string resourceGroup) {
Image tex;
bool loaded = false; // indicates we were successful finding the texture
StringVectorPtr texnames = ResourceGroupManager::getSingleton().findResourceNames(resourceGroup, textureName
+ ".*");
if (texnames->size() <= 0) {
// no results, try the localised version
// prev. path + /language/filename
String locresname = mConfigService->getLocalisedResourcePath(textureName);
LOG_INFO("Specified resource (%s) was not found, trying localized version: %s", textureName.c_str(), locresname.c_str());
texnames = ResourceGroupManager::getSingleton().findResourceNames(resourceGroup, locresname
+ ".*");
}
String txtfile;
// Let's try the extensions from the extensions vector
StringVector::iterator it = texnames->begin();
for (; it != texnames->end(); it++) { // Try loading every given
try {
tex.load((*it), resourceGroup);
TextureManager::getSingleton().loadImage(textureName, resourceGroup, tex, TEX_TYPE_2D, 5, 1.0f);
txtfile = (*it);
loaded = true;
break; // we got it!
} catch (Ogre::Exception) {
// Nothing. We are trying more extensions
}
}
if (!loaded)
LOG_ERROR("Image %s was not found, texture will be invalid!", textureName.c_str());
// Construct a material out of this texture. We'll just clone the material upstairs to enable lmap-txture combinations
MaterialPtr shadMat = MaterialManager::getSingleton().create(matName, resourceGroup);
shadMat->setReceiveShadows(true);
Pass *shadPass = shadMat->getTechnique(0)->getPass(0);
shadPass->setAmbient(0.5, 0.5, 0.5);
shadPass->setDiffuse(1, 1, 1, 1);
shadPass->setSpecular(1, 1, 1, 1);
TextureUnitState* tus = createAnimatedTextureState(shadPass, txtfile, resourceGroup, 5);
// Set replace on all first layer textures for now
// tus->setColourOperation(LBO_REPLACE);
tus->setTextureAddressingMode(TextureUnitState::TAM_WRAP);
tus->setTextureCoordSet(0);
tus->setTextureFiltering(TFO_BILINEAR);
tus->setTextureUScale(1.0f);
tus->setTextureVScale(1.0f);
// tus->setTextureFiltering(TFO_NONE);
// Set culling mode to none
// shadMat->setCullingMode(CULL_ANTICLOCKWISE);
// No dynamic lighting
shadMat->setLightingEnabled(false);
// DYNL:
shadMat->load();
// standard size
addWorldMaterialTemplate(idx, shadMat);
}
开发者ID:Painpillow,项目名称:openDarkEngine,代码行数:80,代码来源:MaterialService.cpp
示例2: Degree
void Viewer::setupLights ()
{
mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
if ( Ogre::Root::getSingletonPtr()->getRenderSystem()->getCapabilities()->hasCapability(RSC_HWRENDER_TO_TEXTURE) )
{
mSceneMgr->setShadowTextureSettings(1024, 2);
}
else
{
mSceneMgr->setShadowTextureSettings(512, 2);
}
mSceneMgr->setShadowColour(ColourValue(0.5,0.5,0.5));
Light * mSunLight = mSceneMgr->createLight("SunLight");
mSunLight->setCastShadows(true);
mSunLight->setType(Light::LT_SPOTLIGHT);
mSunLight->setPosition(500, 500, 500);
mSunLight->setSpotlightRange(Degree(30), Degree(50));
Vector3 dir;
dir = - mSunLight->getPosition();
dir.normalise();
mSunLight->setDirection(dir);
mSunLight->setDiffuseColour(0.35, 0.35, 0.38);
mSunLight->setSpecularColour(0.9, 0.9, 1);
timeSince = 0.0f;
mBuildMode = BM_NONE;
#if 0
mReflectCam = mSceneMgr->createCamera("ReflectCam");
mRTTTex = mRenderer->getRoot()->getRenderSystem()->createRenderTexture("RttTex", 512, 384,
TEX_TYPE_2D, PF_R8G8B8);
{
mReflectCam = mSceneMgr->createCamera("ReflectCam");
mReflectCam->setPosition(mCamera->getPosition());
mReflectCam->setOrientation(mCamera->getOrientation());
mReflectCam->setNearClipDistance(mCamera->getNearClipDistance());
mReflectCam->setFarClipDistance(mCamera->getFarClipDistance());
Viewport * v = mRTTTex->addViewport(mReflectCam);
mReflectCam->setAspectRatio(Real(v->getWidth()) / Real(v->getHeight()));
v->setOverlaysEnabled(false);
v->setClearEveryFrame(true);
v->setBackgroundColour(ColourValue::Black);
}
MaterialPtr mat = MaterialManager::getSingleton().create("RttMat",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
TextureUnitState * t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
//t->setProjectiveTexturing(true, mReflectCam);
mat->clone("RttMat.over");
//mGui->createWindow(Vector4(16, 16, 512, 384), "RttMat", BetaGUI::WFT_NONE, "");
#endif
}
开发者ID:bytewrench,项目名称:NxOgre-Pinball,代码行数:68,代码来源:Viewer.cpp
示例3: getBlendFactor
void NIFLoader::createMaterial(const String &name,
const Vector &ambient,
const Vector &diffuse,
const Vector &specular,
const Vector &emissive,
float glossiness, float alpha,
int alphaFlags, float alphaTest,
const String &texName)
{
MaterialPtr material = MaterialManager::getSingleton().create(name, resourceGroup);
//Hardware Skinning code, textures may be the wrong color if enabled
/* if(!mSkel.isNull()){
material->removeAllTechniques();
Ogre::Technique* tech = material->createTechnique();
//tech->setSchemeName("blahblah");
Pass* pass = tech->createPass();
pass->setVertexProgram("Ogre/BasicVertexPrograms/AmbientOneTexture");*/
// This assigns the texture to this material. If the texture name is
// a file name, and this file exists (in a resource directory), it
// will automatically be loaded when needed. If not (such as for
// internal NIF textures that we might support later), we should
// already have inserted a manual loader for the texture.
if (!texName.empty())
{
Pass *pass = material->getTechnique(0)->getPass(0);
/*TextureUnitState *txt =*/
pass->createTextureUnitState(texName);
pass->setVertexColourTracking(TVC_DIFFUSE);
// As of yet UNTESTED code from Chris:
/*pass->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
pass->setDepthFunction(Ogre::CMPF_LESS_EQUAL);
pass->setDepthCheckEnabled(true);
// Add transparency if NiAlphaProperty was present
if (alphaFlags != -1)
{
std::cout << "Alpha flags set!" << endl;
if ((alphaFlags&1))
{
pass->setDepthWriteEnabled(false);
pass->setSceneBlending(getBlendFactor((alphaFlags>>1)&0xf),
getBlendFactor((alphaFlags>>5)&0xf));
}
else
pass->setDepthWriteEnabled(true);
if ((alphaFlags>>9)&1)
pass->setAlphaRejectSettings(getTestMode((alphaFlags>>10)&0x7),
alphaTest);
pass->setTransparentSortingEnabled(!((alphaFlags>>13)&1));
}
else
pass->setDepthWriteEnabled(true); */
// Add transparency if NiAlphaProperty was present
if (alphaFlags != -1)
{
// The 237 alpha flags are by far the most common. Check
// NiAlphaProperty in nif/property.h if you need to decode
// other values. 237 basically means normal transparencly.
if (alphaFlags == 237)
{
NifOverrides::TransparencyResult result = NifOverrides::Overrides::getTransparencyOverride(texName);
if (result.first)
{
pass->setAlphaRejectFunction(CMPF_GREATER_EQUAL);
pass->setAlphaRejectValue(result.second);
}
else
{
// Enable transparency
pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
//pass->setDepthCheckEnabled(false);
pass->setDepthWriteEnabled(false);
//std::cout << "alpha 237; material: " << name << " texName: " << texName << std::endl;
}
}
else
warn("Unhandled alpha setting for texture " + texName);
}
else
{
material->getTechnique(0)->setShadowCasterMaterial("depth_shadow_caster_noalpha");
}
}
if (Settings::Manager::getBool("enabled", "Shadows"))
//.........这里部分代码省略.........
开发者ID:Thynix,项目名称:openmw,代码行数:101,代码来源:ogre_nif_loader.cpp
示例4: ShaderHelperCg
//---------------------------------------------------------------------
void TerrainMaterialGeneratorA::SM2Profile::addTechnique(
const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt)
{
Technique* tech = mat->createTechnique();
// Only supporting one pass
Pass* pass = tech->createPass();
GpuProgramManager& gmgr = GpuProgramManager::getSingleton();
HighLevelGpuProgramManager& hmgr = HighLevelGpuProgramManager::getSingleton();
if (!mShaderGen)
{
bool check2x = mLayerNormalMappingEnabled || mLayerParallaxMappingEnabled;
if (hmgr.isLanguageSupported("cg"))
{
mShaderGen = OGRE_NEW ShaderHelperCg();
}
else if (hmgr.isLanguageSupported("hlsl") &&
((check2x && gmgr.isSyntaxSupported("ps_4_0")) ||
(check2x && gmgr.isSyntaxSupported("ps_2_x")) ||
(!check2x && gmgr.isSyntaxSupported("ps_2_0"))))
{
mShaderGen = OGRE_NEW ShaderHelperHLSL();
}
else if (hmgr.isLanguageSupported("glsl"))
{
mShaderGen = OGRE_NEW ShaderHelperGLSL();
}
else if (hmgr.isLanguageSupported("glsles"))
{
mShaderGen = OGRE_NEW ShaderHelperGLSLES();
}
// check SM3 features
mSM3Available = GpuProgramManager::getSingleton().isSyntaxSupported("ps_3_0");
mSM4Available = GpuProgramManager::getSingleton().isSyntaxSupported("ps_4_0");
}
HighLevelGpuProgramPtr vprog = mShaderGen->generateVertexProgram(this, terrain, tt);
HighLevelGpuProgramPtr fprog = mShaderGen->generateFragmentProgram(this, terrain, tt);
pass->setVertexProgram(vprog->getName());
pass->setFragmentProgram(fprog->getName());
if (tt == HIGH_LOD || tt == RENDER_COMPOSITE_MAP)
{
// global normal map
TextureUnitState* tu = pass->createTextureUnitState();
tu->setTextureName(terrain->getTerrainNormalMap()->getName());
tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
// global colour map
if (terrain->getGlobalColourMapEnabled() && isGlobalColourMapEnabled())
{
tu = pass->createTextureUnitState(terrain->getGlobalColourMap()->getName());
tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
}
// light map
if (isLightmapEnabled())
{
tu = pass->createTextureUnitState(terrain->getLightmap()->getName());
tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
}
// blend maps
uint maxLayers = getMaxLayers(terrain);
uint numBlendTextures = std::min(terrain->getBlendTextureCount(maxLayers), terrain->getBlendTextureCount());
uint numLayers = std::min(maxLayers, static_cast<uint>(terrain->getLayerCount()));
for (uint i = 0; i < numBlendTextures; ++i)
{
tu = pass->createTextureUnitState(terrain->getBlendTextureName(i));
tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
}
// layer textures
for (uint i = 0; i < numLayers; ++i)
{
// diffuse / specular
pass->createTextureUnitState(terrain->getLayerTextureName(i, 0));
// normal / height
pass->createTextureUnitState(terrain->getLayerTextureName(i, 1));
}
}
else
{
// LOW_LOD textures
// composite map
TextureUnitState* tu = pass->createTextureUnitState();
tu->setTextureName(terrain->getCompositeMap()->getName());
tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
// That's it!
}
// Add shadow textures (always at the end)
if (isShadowingEnabled(tt, terrain))
//.........这里部分代码省略.........
开发者ID:albmarvil,项目名称:The-Eternal-Sorrow,代码行数:101,代码来源:OgreTerrainMaterialGeneratorA.cpp
示例5: _setVertexTexture
//-----------------------------------------------------------------------
void RenderSystem::_setTextureUnitSettings(size_t texUnit, TextureUnitState& tl)
{
// This method is only ever called to set a texture unit to valid details
// The method _disableTextureUnit is called to turn a unit off
const TexturePtr& tex = tl._getTexturePtr();
// Vertex texture binding?
if (mCurrentCapabilities->hasCapability(RSC_VERTEX_TEXTURE_FETCH) &&
!mCurrentCapabilities->getVertexTextureUnitsShared())
{
if (tl.getBindingType() == TextureUnitState::BT_VERTEX)
{
// Bind vertex texture
_setVertexTexture(texUnit, tex);
// bind nothing to fragment unit (hardware isn't shared but fragment
// unit can't be using the same index
_setTexture(texUnit, true, sNullTexPtr);
}
else
{
// vice versa
_setVertexTexture(texUnit, sNullTexPtr);
_setTexture(texUnit, true, tex);
}
}
else
{
// Shared vertex / fragment textures or no vertex texture support
// Bind texture (may be blank)
_setTexture(texUnit, true, tex);
}
// Set texture coordinate set
_setTextureCoordSet(texUnit, tl.getTextureCoordSet());
// Set texture layer filtering
_setTextureUnitFiltering(texUnit,
tl.getTextureFiltering(FT_MIN),
tl.getTextureFiltering(FT_MAG),
tl.getTextureFiltering(FT_MIP));
// Set texture layer filtering
_setTextureLayerAnisotropy(texUnit, tl.getTextureAnisotropy());
// Set mipmap biasing
_setTextureMipmapBias(texUnit, tl.getTextureMipmapBias());
// Set blend modes
// Note, colour before alpha is important
_setTextureBlendMode(texUnit, tl.getColourBlendMode());
_setTextureBlendMode(texUnit, tl.getAlphaBlendMode());
// Texture addressing mode
const TextureUnitState::UVWAddressingMode& uvw = tl.getTextureAddressingMode();
_setTextureAddressingMode(texUnit, uvw);
// Set texture border colour only if required
if (uvw.u == TextureUnitState::TAM_BORDER ||
uvw.v == TextureUnitState::TAM_BORDER ||
uvw.w == TextureUnitState::TAM_BORDER)
{
_setTextureBorderColour(texUnit, tl.getTextureBorderColour());
}
// Set texture effects
TextureUnitState::EffectMap::iterator effi;
// Iterate over new effects
bool anyCalcs = false;
for (effi = tl.mEffects.begin(); effi != tl.mEffects.end(); ++effi)
{
switch (effi->second.type)
{
case TextureUnitState::ET_ENVIRONMENT_MAP:
if (effi->second.subtype == TextureUnitState::ENV_CURVED)
{
_setTextureCoordCalculation(texUnit, TEXCALC_ENVIRONMENT_MAP);
anyCalcs = true;
}
else if (effi->second.subtype == TextureUnitState::ENV_PLANAR)
{
_setTextureCoordCalculation(texUnit, TEXCALC_ENVIRONMENT_MAP_PLANAR);
anyCalcs = true;
}
else if (effi->second.subtype == TextureUnitState::ENV_REFLECTION)
{
_setTextureCoordCalculation(texUnit, TEXCALC_ENVIRONMENT_MAP_REFLECTION);
anyCalcs = true;
}
else if (effi->second.subtype == TextureUnitState::ENV_NORMAL)
{
_setTextureCoordCalculation(texUnit, TEXCALC_ENVIRONMENT_MAP_NORMAL);
anyCalcs = true;
}
break;
case TextureUnitState::ET_UVSCROLL:
case TextureUnitState::ET_USCROLL:
case TextureUnitState::ET_VSCROLL:
case TextureUnitState::ET_ROTATE:
case TextureUnitState::ET_TRANSFORM:
break;
//.........这里部分代码省略.........
开发者ID:logtcn,项目名称:ogre,代码行数:101,代码来源:OgreRenderSystem.cpp
示例6: if
//-----------------------------------------------------------------------
MaterialPtr Quake3Shader::createAsMaterial(int lightmapNumber)
{
String matName;
StringUtil::StrStreamType str;
String resourceGroup = ResourceGroupManager::getSingleton().getWorldResourceGroupName();
str << mName << "#" << lightmapNumber;
matName = str.str();
MaterialPtr mat = MaterialManager::getSingleton().create(matName,
resourceGroup);
Ogre::Pass* ogrePass = mat->getTechnique(0)->getPass(0);
LogManager::getSingleton().logMessage("Using Q3 shader " + mName, LML_CRITICAL);
for (int p = 0; p < numPasses; ++p)
{
TextureUnitState* t;
// Create basic texture
if (pass[p].textureName == "$lightmap")
{
StringUtil::StrStreamType str2;
str2 << "@lightmap" << lightmapNumber;
t = ogrePass->createTextureUnitState(str2.str());
}
// Animated texture support
else if (pass[p].animNumFrames > 0)
{
Real sequenceTime = pass[p].animNumFrames / pass[p].animFps;
/* Pre-load textures
We need to know if each one was loaded OK since extensions may change for each
Quake3 can still include alternate extension filenames e.g. jpg instead of tga
Pain in the arse - have to check for each frame as letters<n>.tga for example
is different per frame!
*/
for (unsigned int alt = 0; alt < pass[p].animNumFrames; ++alt)
{
if (!ResourceGroupManager::getSingleton().resourceExists(
resourceGroup, pass[p].frames[alt]))
{
// Try alternate extension
pass[p].frames[alt] = getAlternateName(pass[p].frames[alt]);
if (!ResourceGroupManager::getSingleton().resourceExists(
resourceGroup, pass[p].frames[alt]))
{
// stuffed - no texture
continue;
}
}
}
t = ogrePass->createTextureUnitState("");
t->setAnimatedTextureName(pass[p].frames, pass[p].animNumFrames, sequenceTime);
}
else
{
// Quake3 can still include alternate extension filenames e.g. jpg instead of tga
// Pain in the arse - have to check for failure
if (!ResourceGroupManager::getSingleton().resourceExists(
resourceGroup, pass[p].textureName))
{
// Try alternate extension
pass[p].textureName = getAlternateName(pass[p].textureName);
if (!ResourceGroupManager::getSingleton().resourceExists(
resourceGroup, pass[p].textureName))
{
// stuffed - no texture
continue;
}
}
t = ogrePass->createTextureUnitState(pass[p].textureName);
}
// Blending
if (p == 0)
{
// scene blend
mat->setSceneBlending(pass[p].blendSrc, pass[p].blendDest);
if (mat->isTransparent())
mat->setDepthWriteEnabled(false);
t->setColourOperation(LBO_REPLACE);
// Alpha mode
ogrePass->setAlphaRejectSettings(
pass[p].alphaFunc, pass[p].alphaVal);
}
else
{
if (pass[p].customBlend)
{
// Fallback for now
t->setColourOperation(LBO_MODULATE);
}
else
{
// simple layer blend
t->setColourOperation(pass[p].blend);
}
// Alpha mode, prefer 'most alphary'
//.........这里部分代码省略.........
开发者ID:MrLobo,项目名称:El-Rayo-de-Zeus,代码行数:101,代码来源:OgreQuake3Shader.cpp
示例7: clearIlluminationPasses
//-----------------------------------------------------------------------
void Technique::_compileIlluminationPasses(void)
{
clearIlluminationPasses();
if (!checkManuallyOrganisedIlluminationPasses())
{
// Build based on our own heuristics
Passes::iterator i, iend;
iend = mPasses.end();
i = mPasses.begin();
IlluminationStage iStage = IS_AMBIENT;
bool haveAmbient = false;
while (i != iend)
{
IlluminationPass* iPass;
Pass* p = *i;
switch(iStage)
{
case IS_AMBIENT:
// Keep looking for ambient only
if (p->isAmbientOnly())
{
// Add this pass wholesale
iPass = OGRE_NEW IlluminationPass();
iPass->destroyOnShutdown = false;
iPass->originalPass = iPass->pass = p;
iPass->stage = iStage;
mIlluminationPasses.push_back(iPass);
haveAmbient = true;
// progress to next pass
++i;
}
else
{
// Split off any ambient part
if (p->getAmbient() != ColourValue::Black ||
p->getSelfIllumination() != ColourValue::Black ||
p->getAlphaRejectFunction() != CMPF_ALWAYS_PASS)
{
// Copy existing pass
Pass* newPass = OGRE_NEW Pass(this, p->getIndex(), *p);
if (newPass->getAlphaRejectFunction() != CMPF_ALWAYS_PASS)
{
// Alpha rejection passes must retain their transparency, so
// we allow the texture units, but override the colour functions
Pass::TextureUnitStateIterator tusi = newPass->getTextureUnitStateIterator();
while (tusi.hasMoreElements())
{
TextureUnitState* tus = tusi.getNext();
tus->setColourOperationEx(LBX_SOURCE1, LBS_CURRENT);
}
}
else
{
// Remove any texture units
newPass->removeAllTextureUnitStates();
}
// Remove any fragment program
if (newPass->hasFragmentProgram())
newPass->setFragmentProgram("");
// We have to leave vertex program alone (if any) and
// just trust that the author is using light bindings, which
// we will ensure there are none in the ambient pass
newPass->setDiffuse(0, 0, 0, newPass->getDiffuse().a); // Preserving alpha
newPass->setSpecular(ColourValue::Black);
// Calculate hash value for new pass, because we are compiling
// illumination passes on demand, which will loss hash calculate
// before it add to render queue first time.
newPass->_recalculateHash();
iPass = OGRE_NEW IlluminationPass();
iPass->destroyOnShutdown = true;
iPass->originalPass = p;
iPass->pass = newPass;
iPass->stage = iStage;
mIlluminationPasses.push_back(iPass);
haveAmbient = true;
}
if (!haveAmbient)
{
// Make up a new basic pass
Pass* newPass = OGRE_NEW Pass(this, p->getIndex());
newPass->setAmbient(ColourValue::Black);
newPass->setDiffuse(ColourValue::Black);
// Calculate hash value for new pass, because we are compiling
// illumination passes on demand, which will loss hash calculate
// before it add to render queue first time.
newPass->_recalculateHash();
iPass = OGRE_NEW IlluminationPass();
iPass->destroyOnShutdown = true;
//.........这里部分代码省略.........
开发者ID:j-rivero,项目名称:ogre-acornacorn,代码行数:101,代码来源:OgreTechnique.cpp
示例8: loadMesh
void MeshObject::loadMesh()
{
try
{
Ogre::String resourceGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
mesh = static_cast<Ogre::MeshPtr>(Ogre::MeshManager::getSingleton().create(meshName, resourceGroup));
if(backgroundLoading)
{
mesh->setBackgroundLoaded(true);
mesh->addListener(this);
ticket = Ogre::ResourceBackgroundQueue::getSingleton().load(
Ogre::MeshManager::getSingletonPtr()->getResourceType(),
mesh->getName(),
resourceGroup,
false,
0,
0,
0);
// try to load its textures in the background
for(int i=0; i<mesh->getNumSubMeshes(); i++)
{
SubMesh *sm = mesh->getSubMesh(i);
String materialName = sm->getMaterialName();
Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(materialName)); //, resourceGroup));
if(mat.isNull()) continue;
for(int tn=0; tn<mat->getNumTechniques(); tn++)
{
Technique *t = mat->getTechnique(tn);
for(int pn=0; pn<t->getNumPasses(); pn++)
{
Pass *p = t->getPass(pn);
for(int tun=0; tun<p->getNumTextureUnitStates(); tun++)
{
TextureUnitState *tu = p->getTextureUnitState(tun);
String textureName = tu->getTextureName();
// now add this texture to the background loading queue
Ogre::TexturePtr tex = static_cast<Ogre::TexturePtr>(Ogre::TextureManager::getSingleton().create(textureName, resourceGroup));
tex->setBackgroundLoaded(true);
tex->addListener(this);
ticket = Ogre::ResourceBackgroundQueue::getSingleton().load(
Ogre::TextureManager::getSingletonPtr()->getResourceType(),
tex->getName(),
resourceGroup,
false,
0,
0,
0);
}
}
}
}
}
if(!backgroundLoading)
postProcess();
}
catch (Ogre::Exception* e)
{
LOG("exception while loading mesh: " + e->getFullDescription());
}
}
开发者ID:Winceros,项目名称:main,代码行数:65,代码来源:MeshObject.cpp
示例9: ShadowCameraSetupPtr
//.........这里部分代码省略.........
}
mSceneMgr->setShadowTextureSelfShadow(bDepth ? true : false); //-?
mSceneMgr->setShadowCasterRenderBackFaces((bDepth && !bSoft) ? true : false);
mSceneMgr->setShadowTextureCasterMaterial(bDepth ? "shadowcaster_default" : "");
}
mSceneMgr->setShadowColour(Ogre::ColourValue(0,0,0,1));
#if 0 /// TEST overlays
// add overlay elements to show shadow or terrain maps
OverlayManager& mgr = OverlayManager::getSingleton();
Overlay* overlay = mgr.getByName("DebugOverlay");
if (overlay)
mgr.destroy(overlay);
overlay = mgr.create("DebugOverlay");
TexturePtr tex;
#if 0 /// shadow
for (int i = 0; i < pSet->shadow_count; ++i)
{
TexturePtr tex = mSceneMgr->getShadowTexture(i);
#else /// terrain
for (int i = 0; i < 2/*pSet->shadow_count*/; ++i)
{
TexturePtr tex = !terrain ? mSceneMgr->getShadowTexture(i) :
i==0 ? terrain->getCompositeMap() : terrain->getLightmap();
#endif
// Set up a debug panel to display the shadow
if (MaterialManager::getSingleton().resourceExists("Ogre/DebugTexture" + toStr(i)))
MaterialManager::getSingleton().remove("Ogre/DebugTexture" + toStr(i));
MaterialPtr debugMat = MaterialManager::getSingleton().create(
"Ogre/DebugTexture" + toStr(i), rgDef);
debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName());
t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
OverlayContainer* debugPanel;
// destroy container if exists
try
{
if (debugPanel = static_cast<OverlayContainer*>(mgr.getOverlayElement("Ogre/DebugTexPanel" + toStr(i))))
mgr.destroyOverlayElement(debugPanel);
}
catch (Ogre::Exception&) {}
debugPanel = (OverlayContainer*)
(OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugTexPanel" + StringConverter::toString(i)));
debugPanel->_setPosition(0.8, i*0.31); //aspect.. 0.25 0.24
debugPanel->_setDimensions(0.2, 0.3);
debugPanel->setMaterialName(debugMat->getName());
debugPanel->show();
overlay->add2D(debugPanel);
overlay->show();
}
#endif
UpdPSSMMaterials();
// rebuild static geom after materials change
if (vdrTrack)
{
vdrTrack->destroy();
vdrTrack->build();
}
LogO(String("::: Time Shadows: ") + fToStr(ti.getMilliseconds(),0,3) + " ms");
}
/// . . . . . . . .
void CScene::UpdPSSMMaterials()
{
if (app->pSet->shadow_type == Sh_None) return;
if (app->pSet->shadow_count == 1) // 1 tex
{
float dist = app->pSet->shadow_dist;
sh::Vector3* splits = new sh::Vector3(dist, 0,0); //dist*2, dist*3);
sh::Factory::getInstance().setSharedParameter("pssmSplitPoints", sh::makeProperty<sh::Vector3>(splits));
return;
}
if (!mPSSMSetup.get()) return;
//-- pssm params
PSSMShadowCameraSetup* pssmSetup = static_cast<PSSMShadowCameraSetup*>(mPSSMSetup.get());
const PSSMShadowCameraSetup::SplitPointList& sp = pssmSetup->getSplitPoints();
const int last = sp.size()-1;
sh::Vector3* splits = new sh::Vector3(
sp[std::min(1,last)], sp[std::min(2,last)], sp[std::min(3,last)] );
sh::Factory::getInstance().setSharedParameter("pssmSplitPoints", sh::makeProperty<sh::Vector3>(splits));
}
开发者ID:ddxxpp,项目名称:stuntrally,代码行数:101,代码来源:Shadows.cpp
示例10: if
void CarReflection::Create()
{
bFirstFrame = true;
if (pSet->refl_mode == "single") cubetexName = "ReflectionCube"; // single: use 1st cubemap
else if (pSet->refl_mode == "full")
{
cubetexName = "ReflectionCube" + toStr(iIndex);
// first cubemap: no index
if (cubetexName == "ReflectionCube0")
cubetexName = "ReflectionCube";
}
else /* static */
cubetexName = "ReflectionCube";
TextureManager* tm = TextureManager::getSingletonPtr();
int size = ciShadowSizesA[pSet->refl_size]; // /2 ?
// create cube render texture
if (! (pSet->refl_mode == "single" && iIndex != 0) )
{
cubetex = tm->createManual(cubetexName,
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_CUBE_MAP,
size,size, 0/*mips*/, PF_R8G8B8, TU_RENDERTARGET);
//LogO("created rt cube");
for (int face = 0; face < 6; face++)
{
Camera* mCam = pSceneMgr->createCamera("Reflect_" + toStr(iIndex) + "_" + toStr(face));
mCam->setAspectRatio(1.0f); mCam->setFOVy(Degree(90));
mCam->setNearClipDistance(0.1);
//mCam->setFarClipDistance(pSet->refl_dist); //sky-
RenderTarget* mRT = cubetex->getBuffer(face)->getRenderTarget();
//LogO( "rt face Name: " + mRT->getName() );
mRT->removeAllViewports();
Viewport* vp = mRT->addViewport(mCam);
vp->setOverlaysEnabled(false);
vp->setVisibilityMask(RV_MaskReflect);
mRT->setAutoUpdated(false);
//mRT->addListener(this); //-
mCam->setPosition(Vector3::ZERO);
Vector3 lookAt(0,0,0), up(0,0,0), right(0,0,0); switch(face)
{
case 0: lookAt.x =-1; up.y = 1; right.z = 1; break; // +X
case 1: lookAt.x = 1; up.y = 1; right.z =-1; break; // -X
case 2: lookAt.y =-1; up.z = 1; right.x = 1; break; // +Y
case 3: lookAt.y = 1; up.z =-1; right.x = 1; break; // -Y
case 4: lookAt.z = 1; up.y = 1; right.x =-1; break; // +Z
case 5: lookAt.z =-1; up.y = 1; right.x =-1; break; // -Z
}
Quaternion orient( right, up, lookAt ); mCam->setOrientation( orient );
pCams[face] = mCam;
pRTs[face] = mRT;
}
}
// Iterate through our materials and add an index to ReflectionCube texture reference
for (int i=0; i < NumMaterials; i++)
{
MaterialPtr mtr = MaterialManager::getSingleton().getByName(sMtr[i]);
if (!mtr.isNull())
{ Material::TechniqueIterator techIt = mtr->getTechniqueIterator();
while (techIt.hasMoreElements())
{ Technique* tech = techIt.getNext();
Technique::PassIterator passIt = tech->getPassIterator();
while (passIt.hasMoreElements())
{ Pass* pass = passIt.getNext();
Pass::TextureUnitStateIterator tusIt = pass->getTextureUnitStateIterator();
while (tusIt.hasMoreElements())
{
TextureUnitState* tus = tusIt.getNext();
if (tus->getTextureName() == "ReflectionCube")
tus->setTextureName(cubetexName);
} } } } }
}
开发者ID:jsj2008,项目名称:stuntrally,代码行数:76,代码来源:CarReflection.cpp
示例11: while
void MaterialFactory::setShaderParams(MaterialPtr mat)
{
if (mat.isNull()) return;
Material::TechniqueIterator techIt = mat->getTechniqueIterator();
while (techIt.hasMoreElements())
{
Technique* tech = techIt.getNext();
Technique::PassIterator passIt = tech->getPassIterator();
while (passIt.hasMoreElements())
{
Pass* pass = passIt.getNext();
if (pass->hasFragmentProgram())
{
// shadow fading parameters
if ( getShadowsFade()
&& pass->getFragmentProgramParameters()->_findNamedConstantDefinition("fadeStart_farDist", false)
&& mSceneMgr
)
{
float fadeDist;
if (mSceneMgr->getShadowFarDistance() != 0)
fadeDist = getShadowsFadeDistance()/mSceneMgr->getShadowFarDistance();
else
fadeDist = 0.f;
pass->getFragmentProgramParameters()->setNamedConstant("fadeStart_farDist", Vector3(
fadeDist,
mSceneMgr->getShadowFarDistance(),
float(getShadowsFade())
));
}
// terrain lightmap name & size
if ( mTerrain && !mTerrain->getLightmap().isNull() )
{
if (pass->getFragmentProgramParameters()->_findNamedConstantDefinition("terrainWorldSize", false))
pass->getFragmentProgramParameters()->setNamedConstant( "terrainWorldSize", Real( mTerrain->getWorldSize() ) );
Pass::TextureUnitStateIterator tusIt = pass->getTextureUnitStateIterator();
while (tusIt.hasMoreElements())
{
TextureUnitState* tus = tusIt.getNext();
if (tus->getName() == "terrainLightMap")
{
tus->setTextureName( mTerrain->getLightmap()->getName() );
}
}
}
if (pass->getFragmentProgramParameters()->_findNamedConstantDefinition("invTerSize", false))
pass->getFragmentProgramParameters()->setNamedConstant("invTerSize", 1.f / Real(pApp->sc.td.fTerWorldSize));
// pssm split points
if ( pass->getFragmentProgramParameters()->_findNamedConstantDefinition("pssmSplitPoints", false) && mPSSM)
{
const PSSMShadowCameraSetup::SplitPointList& splitPointList = mPSSM->getSplitPoints();
Vector4 splitPoints;
for (size_t i = 0; i < splitPointList.size(); ++i)
splitPoints[i] = splitPointList[i];
pass->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);
}
}
}
}
}
开发者ID:sureandrew,项目名称:stuntrally,代码行数:67,代码来源:MaterialFactory.cpp
示例12: createIndexBuffer
//.........这里部分代码省略.........
// 1.0f .. a/(a+1)
// coordinate
vertices[x*4*elemsize+y*elemsize+0] = xcoord*(mSize/2.0f);
vertices[x*4*elemsize+y*elemsize+1] = ycoord*(mSize/2.0f);
vertices[x*4*elemsize+y*elemsize+2] = zcoord*(mSize/2.0f);
// normal
vertices[x*4*elemsize+y*elemsize+3] = 0.0f;
vertices[x*4*elemsize+y*elemsize+4] = 0.0f;
vertices[x*4*elemsize+y*elemsize+5] = 1.0f;
// tex
vertices[x*4*elemsize+y*elemsize+6] = xcoord*sqrtf(3.0f);
vertices[x*4*elemsize+y*elemsize+7] = ycoord*sqrtf(3.0f);
vertices[x*4*elemsize+y*elemsize+8] = zcoord*sqrtf(3.0f);
}
}
unsigned short *faces = new unsigned short[mSlices*6];
for(x=0; x<mSlices; x++)
{
faces[x*6+0] = x*4+0;
faces[x*6+1] = x*4+1;
faces[x*6+2] = x*4+2;
faces[x*6+3] = x*4+1;
faces[x*6+4] = x*4+2;
faces[x*6+5] = x*4+3;
}
// Setup buffers
vdata->vertexStart = 0;
vdata->vertexCount = nvertices;
VertexDeclaration* decl = vdata->vertexDeclaration;
VertexBufferBinding* bind = vdata->vertexBufferBinding;
size_t offset = 0;
decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
offset += VertexElement::getTypeSize(VET_FLOAT3);
decl->addElement(0, offset, VET_FLOAT3, VES_TEXTURE_COORDINATES);
offset += VertexElement::getTypeSize(VET_FLOAT3);
HardwareVertexBufferSharedPtr vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, nvertices, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
bind->setBinding(0, vbuf);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
mSlices*6,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
idata->indexBuffer = ibuf;
idata->indexCount = mSlices*6;
idata->indexStart = 0;
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
// Delete temporary buffers
delete [] vertices;
delete [] faces;
// Now make the render operation
mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
mRenderOp.indexData = idata;
mRenderOp.vertexData = vdata;
mRenderOp.useIndexes = true;
// Create a brand new private material
if (!ResourceGroupManager::getSingleton().resourceGroupExists("VolumeRenderable"))
{
ResourceGroupManager::getSingleton().createResourceGroup("VolumeRenderable");
}
MaterialPtr material =
MaterialManager::getSingleton().create(mTexture, "VolumeRenderable",
false, 0); // Manual, loader
// Remove pre-created technique from defaults
material->removeAllTechniques();
// Create a techinique and a pass and a texture unit
Technique * technique = material->createTechnique();
Pass * pass = technique->createPass();
TextureUnitState * textureUnit = pass->createTextureUnitState();
// Set pass parameters
pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
pass->setDepthWriteEnabled(false);
pass->setCullingMode(CULL_NONE);
pass->setLightingEnabled(false);
// Set texture unit parameters
textureUnit->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
textureUnit->setTextureName(mTexture, TEX_TYPE_3D);
textureUnit->setTextureFiltering(TFO_TRILINEAR);
mUnit = textureUnit;
mMaterial = material;
}
开发者ID:j-rivero,项目名称:ogre-acornacorn,代码行数:101,代码来源:VolumeRenderable.cpp
示例13: defined
//---------------------------------------------------------------------
bool Technique::checkHardwareSupport(bool autoManageTextureUnits, StringStream& compileErrors)
{
// Go through each pass, checking requirements
Passes::iterator i;
unsigned short passNum = 0;
const RenderSystemCapabilities* caps =
Root::getSingleton().getRenderSystem()->getCapabilities();
unsigned short numTexUnits = caps->getNumTextureUnits();
for (i = mPasses.begin(); i != mPasses.end(); ++i, ++passNum)
{
Pass* currPass = *i;
// Adjust pass index
currPass->_notifyIndex(passNum);
// Check for advanced blending operation support
if((currPass->getSceneBlendingOperation() != SBO_ADD || currPass->getSceneBlendingOperationAlpha() != SBO_ADD) &&
!caps->hasCapability(RSC_ADVANCED_BLEND_OPERATIONS))
{
return false;
}
// Check texture unit requirements
size_t numTexUnitsRequested = currPass->getNumTextureUnitStates();
// Don't trust getNumTextureUnits for programmable
if(!currPass->hasFragmentProgram())
{
#if defined(OGRE_PRETEND_TEXTURE_UNITS) && OGRE_PRETEND_TEXTURE_UNITS > 0
if (numTexUnits > OGRE_PRETEND_TEXTURE_UNITS)
numTexUnits = OGRE_PRETEND_TEXTURE_UNITS;
#endif
if (numTexUnitsRequested > numTexUnits)
{
if (!autoManageTextureUnits)
{
// The user disabled auto pass split
compileErrors << "Pass " << passNum <<
": Too many texture units for the current hardware and no splitting allowed."
<< std::endl;
return false;
}
else if (currPass->hasVertexProgram())
{
// Can't do this one, and can't split a programmable pass
compileErrors << "Pass " << passNum <<
": Too many texture units for the current hardware and "
"cannot split programmable passes."
<< std::endl;
return false;
}
}
}
if (currPass->hasComputeProgram())
{
// Check fragment program version
if (!currPass->getComputeProgram()->isSupported())
{
// Can't do this one
compileErrors << "Pass " << passNum <<
": Compute program " << currPass->getComputeProgram()->getName()
<< " cannot be used - ";
if (currPass->getComputeProgram()->hasCompileError())
compileErrors << "compile error.";
else
compileErrors << "not supported.";
compileErrors << std::endl;
return false;
}
}
if (currPass->hasVertexProgram())
{
// Check vertex program version
if (!currPass->getVertexProgram()->isSupported() )
{
// Can't do this one
compileErrors << "Pass " << passNum <<
": Vertex program " << currPass->getVertexProgram()->getName()
<< " cannot be used - ";
if (currPass->getVertexProgram()->hasCompileError())
compileErrors << "compile error.";
else
compileErrors << "not supported.";
compileErrors << std::endl;
return false;
}
}
if (currPass->hasTessellationHullProgram())
{
// Check tessellation control program version
if (!currPass->getTessellationHullProgram()->isSupported() )
{
// Can't do this one
compileErrors << "Pass " << passNum <<
": Tessellation Hull program " << currPass->getTessellationHullProgram()->getName()
<< " cannot be used - ";
if (currPass->getTessellationHullProgram()->hasCompileError())
compileErrors << "compile error.";
else
compileErrors << "not supported.";
//.........这里部分代码省略.........
开发者ID:j-rivero,项目名称:ogre-acornacorn,代码行数:101,代码来源:OgreTechnique.cpp
示例14: createBackground
// Create the background nebulae
void createBackground(SceneManager *sceneMgr) {
// Get the background image
String bgImage = ScriptSystem::getSingleton().getScriptString("backgroundImage");
MaterialPtr mat = MaterialManager::getSingleton().getByName("Background");
mat->getTechnique(0)->getPass(0)->getT
|
请发表评论