//--------------------------------------------------------------------- void TerrainMaterialGeneratorC::SM2Profile::addTechnique( const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt) { Technique* tech = mat->createTechnique(); tech->setSchemeName("GBuffer"); // Only supporting one pass Pass* pass = tech->createPass(); //pass->setName("NO_DEFERRED"); GpuProgramManager& gmgr = GpuProgramManager::getSingleton(); HighLevelGpuProgramManager& hmgr = HighLevelGpuProgramManager::getSingleton(); if (!mShaderGen) { if (hmgr.isLanguageSupported("cg")) mShaderGen = OGRE_NEW ShaderHelperCg(); else { // todo } // 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! } }
//--------------------------------------------------------------------- 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)) { uint numTextures = 1; if (getReceiveDynamicShadowsPSSM()) { numTextures = (uint)getReceiveDynamicShadowsPSSM()->getSplitCount(); } for (uint i = 0; i < numTextures; ++i) { TextureUnitState* tu = pass->createTextureUnitState(); tu->setContentType(TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(ColourValue::White); } } }