Commits

Assaf Raman  committed e0e87ca

RTSS sample: Added resources and code that creates geometry in the sample to demonstrate the texture atlas feature.

  • Participants
  • Parent commits 2f23d0f

Comments (0)

Files changed (15)

File Samples/Media/materials/scripts/TextureAtlasSampleOrg.tai

+# TextureAtlasSampleOrg.tai
+# AtlasCreationTool.exe -width 2048 -height 2048 -o TextureAtlasSampleOrg
+#
+# <filename>		<atlas filename>, <atlas idx>, <atlas type>, <woffset>, <hoffset>, <depth offset>, <width>, <height>
+#
+# Texture <filename> can be found in texture atlas <atlas filename>, i.e., 
+# TextureAtlasSampleOrg<idx>.png of <atlas type> type with texture coordinates boundary given by:
+#   A = ( <woffset>, <hoffset> )
+#   B = ( <woffset> + <width>, <hoffset> + <height> )
+#
+# where coordinates (0,0) and (1,1) of the original texture map correspond
+# to coordinates A and B, respectively, in the texture atlas.
+# If the atlas is a volume texture then <depth offset> is the w-coordinate
+# to use the access the appropriate slice in the volume atlas.
+
+ogrelogo-small.jpg		TextureAtlasSampleOrg0.png, 0, 2D, 0.000000, 0.000000, 0.000000, 0.500000, 0.500000
+img2.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.500000, 0.000000, 0.000000, 0.250000, 0.500000
+radial.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.750000, 0.000000, 0.000000, 0.250000, 0.500000
+1d_SPIRAL.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.000000, 0.500000, 0.000000, 0.125000, 0.250000
+img1.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.125000, 0.500000, 0.000000, 0.125000, 0.250000
+Dirt.jpg		TextureAtlasSampleOrg0.png, 0, 2D, 0.250000, 0.500000, 0.000000, 0.125000, 0.250000
+flare.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.375000, 0.500000, 0.000000, 0.125000, 0.250000
+rockwall.tga		TextureAtlasSampleOrg0.png, 0, 2D, 0.500000, 0.500000, 0.000000, 0.125000, 0.250000
+steelhead.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.625000, 0.500000, 0.000000, 0.125000, 0.250000
+RustyBarrel.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.750000, 0.500000, 0.000000, 0.125000, 0.250000
+NMBalls.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.875000, 0.500000, 0.000000, 0.125000, 0.250000
+terr_dirt-grass.jpg		TextureAtlasSampleOrg0.png, 0, 2D, 0.000000, 0.750000, 0.000000, 0.125000, 0.250000
+SmallLeaf_BP.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.125000, 0.750000, 0.000000, 0.062500, 0.250000
+1d_debug.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.187500, 0.750000, 0.000000, 0.062500, 0.125000
+checker.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.250000, 0.750000, 0.000000, 0.062500, 0.125000
+spotlight_image.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.312500, 0.750000, 0.000000, 0.062500, 0.125000
+nm_bk.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.375000, 0.750000, 0.000000, 0.062500, 0.125000
+dirt01.jpg		TextureAtlasSampleOrg0.png, 0, 2D, 0.437500, 0.750000, 0.000000, 0.062500, 0.125000
+tusk.jpg		TextureAtlasSampleOrg0.png, 0, 2D, 0.500000, 0.750000, 0.000000, 0.062500, 0.125000
+LowRes.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.562500, 0.750000, 0.000000, 0.015625, 0.031250
+scr-up-p.png		TextureAtlasSampleOrg0.png, 0, 2D, 0.578125, 0.750000, 0.000000, 0.007813, 0.015625

File Samples/Media/materials/scripts/TextureAtlasSampleWrap.tai

+# TextureAtlasSampleWrap.tai
+# AtlasCreationTool.exe -width 2048 -height 2048 -o TextureAtlasSampleWrap
+#
+# <filename>		<atlas filename>, <atlas idx>, <atlas type>, <woffset>, <hoffset>, <depth offset>, <width>, <height>
+#
+# Texture <filename> can be found in texture atlas <atlas filename>, i.e., 
+# TextureAtlasSampleWrap<idx>.png of <atlas type> type with texture coordinates boundary given by:
+#   A = ( <woffset>, <hoffset> )
+#   B = ( <woffset> + <width>, <hoffset> + <height> )
+#
+# where coordinates (0,0) and (1,1) of the original texture map correspond
+# to coordinates A and B, respectively, in the texture atlas.
+# If the atlas is a volume texture then <depth offset> is the w-coordinate
+# to use the access the appropriate slice in the volume atlas.
+
+ogrelogo-small.jpg		TextureAtlasSampleWrap0.png, 0, 2D, 0.125000, 0.125000, 0.000000, 0.250000, 0.250000
+img2.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.562500, 0.125000, 0.000000, 0.125000, 0.250000
+radial.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.812500, 0.125000, 0.000000, 0.125000, 0.250000
+1d_SPIRAL.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.031250, 0.562500, 0.000000, 0.062500, 0.125000
+img1.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.156250, 0.562500, 0.000000, 0.062500, 0.125000
+Dirt.jpg		TextureAtlasSampleWrap0.png, 0, 2D, 0.281250, 0.562500, 0.000000, 0.062500, 0.125000
+flare.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.406250, 0.562500, 0.000000, 0.062500, 0.125000
+rockwall.tga		TextureAtlasSampleWrap0.png, 0, 2D, 0.531250, 0.562500, 0.000000, 0.062500, 0.125000
+steelhead.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.656250, 0.562500, 0.000000, 0.062500, 0.125000
+RustyBarrel.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.781250, 0.562500, 0.000000, 0.062500, 0.125000
+NMBalls.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.906250, 0.562500, 0.000000, 0.062500, 0.125000
+terr_dirt-grass.jpg		TextureAtlasSampleWrap0.png, 0, 2D, 0.031250, 0.812500, 0.000000, 0.062500, 0.125000
+SmallLeaf_BP.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.140625, 0.812500, 0.000000, 0.031250, 0.125000
+1d_debug.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.203125, 0.781250, 0.000000, 0.031250, 0.062500
+checker.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.265625, 0.781250, 0.000000, 0.031250, 0.062500
+spotlight_image.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.328125, 0.781250, 0.000000, 0.031250, 0.062500
+nm_bk.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.390625, 0.781250, 0.000000, 0.031250, 0.062500
+dirt01.jpg		TextureAtlasSampleWrap0.png, 0, 2D, 0.453125, 0.781250, 0.000000, 0.031250, 0.062500
+tusk.jpg		TextureAtlasSampleWrap0.png, 0, 2D, 0.515625, 0.781250, 0.000000, 0.031250, 0.062500
+LowRes.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.566406, 0.757813, 0.000000, 0.007813, 0.015625
+scr-up-p.png		TextureAtlasSampleWrap0.png, 0, 2D, 0.580078, 0.753906, 0.000000, 0.003906, 0.007813

File Samples/Media/materials/textures/1d_SPIRAL.png

Added
New image

File Samples/Media/materials/textures/1d_debug.png

Added
New image

File Samples/Media/materials/textures/LowRes.png

Added
New image

File Samples/Media/materials/textures/SmallLeaf_BP.png

Added
New image

File Samples/Media/materials/textures/TextureAtlasSampleOrg0.png

Added
New image

File Samples/Media/materials/textures/TextureAtlasSampleWrap0.png

Added
New image

File Samples/Media/materials/textures/checker.png

Added
New image

File Samples/Media/materials/textures/img1.png

Added
New image

File Samples/Media/materials/textures/img2.png

Added
New image

File Samples/Media/materials/textures/radial.png

Added
New image

File Samples/Media/materials/textures/spotlight_image.png

Added
New image

File Samples/ShaderSystem/include/ShaderSystem.h

 
 	/** Update layer blend caption. */
 	void updateLayerBlendingCaption( RTShader::LayeredBlending::BlendMode nextBlendMode );
-// Types.
+
+	ManualObject* createTextureAtlasObject();
+	void createMaterialForTexture( const String & texName, bool isTextureAtlasTexture );
+	// Types.
 protected:
 	typedef vector<Entity*>::type	EntityList;
 	typedef EntityList::iterator	EntityListIterator;

File Samples/ShaderSystem/src/ShaderSystem.cpp

 #include "ShaderSystem.h"
 #include "ShaderExReflectionMap.h"
 #include "OgreShaderExInstancedViewports.h"
-
+#include "OgreShaderExTextureAtlasSampler.h"
 using namespace Ogre;
 using namespace OgreBites;
 
 	childNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
 	childNode->setPosition(-300.0, 100.0, -100.0);
 	childNode->attachObject(entity);
-	
+
+
+	RTShader::RenderState* pMainRenderState = 
+		RTShader::ShaderGenerator::getSingleton().createOrRetrieveRenderState(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME).first;
+	pMainRenderState->addTemplateSubRenderState(
+		Ogre::RTShader::ShaderGenerator::getSingleton().createSubRenderState(
+		Ogre::RTShader::TextureAtlasSampler::Type));
+
+	// Create texture atlas object and node
+	ManualObject* atlasObject = createTextureAtlasObject();
+	childNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
+	childNode->setPosition(-600.0, 0, -850.0);
+	childNode->attachObject(atlasObject);
+
 	createDirectionalLight();
 	createPointLight();
 	createSpotLight();
 
 }
 
+void Sample_ShaderSystem::createMaterialForTexture( const String & texName, bool isTextureAtlasTexture )
+{
+	MaterialManager * matMgr = MaterialManager::getSingletonPtr();
+	if ( matMgr->resourceExists(texName) == false )
+	{
+		MaterialPtr newMat = matMgr->create(texName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+		newMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
+		TextureUnitState* pState = newMat->getTechnique(0)->getPass(0)->createTextureUnitState(texName);
+		if(isTextureAtlasTexture) 
+		{
+			// to solve wrap edge bleed
+			pState->setTextureFiltering(TFO_TRILINEAR);
+		}
+	}
+
+}
+
+ManualObject* Sample_ShaderSystem::createTextureAtlasObject()
+{
+	TextureAtlasSamplerFactory * textureAtlasSamplerFactory = 
+		static_cast<TextureAtlasSamplerFactory *>(mShaderGenerator->getSubRenderStateFactory(TextureAtlasSampler::Type));
+	TextureAtlasTable textureAtlasTable;
+
+	DataStreamPtr taiFile = Ogre::ResourceGroupManager::getSingleton().openResource("TextureAtlasSampleWrap.tai");
+
+	textureAtlasSamplerFactory->addTexutreAtlasDefinition(taiFile, &textureAtlasTable);
+
+	//Generate the geometry that will seed the particle system
+	ManualObject* textureAtlasObject = mSceneMgr->createManualObject("TextureAtlasObject");
+
+	int sliceSize = 30.0;
+	int wrapSize = 5.0;
+
+	String curMatName;
+
+	// create original texture geometry
+	for( size_t i = 0 ; i < textureAtlasTable.size() ; i++ )
+	{
+		bool changeMat = (curMatName != textureAtlasTable[i].atlasTextureName);
+
+		if (changeMat)
+		{
+			if (curMatName.empty() == false) // we don't want to end before we begin
+			{
+				textureAtlasObject->end();
+			}
+
+			curMatName = textureAtlasTable[i].originalTextureName;
+			createMaterialForTexture(curMatName, false);
+			textureAtlasObject->begin(curMatName, RenderOperation::OT_TRIANGLE_LIST);
+		}
+
+		// triangle 0
+		textureAtlasObject->position(i * sliceSize, 0, 0); //Position
+		textureAtlasObject->textureCoord(0,0); //UV
+
+		textureAtlasObject->position(i * sliceSize, 0, sliceSize); //Position
+		textureAtlasObject->textureCoord(0,wrapSize); //UV
+
+		textureAtlasObject->position((i + 1) * sliceSize, 0 , sliceSize); //Position
+		textureAtlasObject->textureCoord(wrapSize,wrapSize); //UV
+
+		// triangle 1
+		textureAtlasObject->position(i * sliceSize, 0, 0); //Position
+		textureAtlasObject->textureCoord(0,0); //UV
+
+		textureAtlasObject->position((i + 1) * sliceSize, 0, sliceSize); //Position
+		textureAtlasObject->textureCoord(wrapSize,wrapSize); //UV
+
+		textureAtlasObject->position((i + 1) * sliceSize, 0, 0); //Position
+		textureAtlasObject->textureCoord(wrapSize, 0); //UV
+
+	}
+
+	// create texture atlas geometry
+	for( size_t i = 0 ; i < textureAtlasTable.size() ; i++ )
+	{
+		bool changeMat = (curMatName != textureAtlasTable[i].atlasTextureName);
+
+		if (changeMat)
+		{
+			if (curMatName.empty() == false) // we don't want to end before we begin
+			{
+				textureAtlasObject->end();
+			}
+
+			curMatName = textureAtlasTable[i].atlasTextureName;
+			createMaterialForTexture(curMatName, true);
+			textureAtlasObject->begin(curMatName, RenderOperation::OT_TRIANGLE_LIST);
+		}
+
+		// triangle 0
+		textureAtlasObject->position(i * sliceSize, 0, sliceSize); //Position
+		textureAtlasObject->textureCoord(0,0); //UV
+		textureAtlasObject->textureCoord(textureAtlasTable[i].indexInAtlas); //Texture ID
+
+		textureAtlasObject->position(i * sliceSize, 0, sliceSize * 2); //Position
+		textureAtlasObject->textureCoord(0,wrapSize); //UV
+		textureAtlasObject->textureCoord(textureAtlasTable[i].indexInAtlas); //Texture ID
+
+		textureAtlasObject->position((i + 1) * sliceSize, 0 , sliceSize * 2); //Position
+		textureAtlasObject->textureCoord(wrapSize,wrapSize); //UV
+		textureAtlasObject->textureCoord(textureAtlasTable[i].indexInAtlas); //Texture ID
+
+		// triangle 1
+		textureAtlasObject->position(i * sliceSize, 0, sliceSize); //Position
+		textureAtlasObject->textureCoord(0,0); //UV
+		textureAtlasObject->textureCoord(textureAtlasTable[i].indexInAtlas); //Texture ID
+
+		textureAtlasObject->position((i + 1) * sliceSize, 0, sliceSize * 2); //Position
+		textureAtlasObject->textureCoord(wrapSize,wrapSize); //UV
+		textureAtlasObject->textureCoord(textureAtlasTable[i].indexInAtlas); //Texture ID
+
+		textureAtlasObject->position((i + 1) * sliceSize, 0, sliceSize); //Position
+		textureAtlasObject->textureCoord(wrapSize, 0); //UV
+		textureAtlasObject->textureCoord(textureAtlasTable[i].indexInAtlas); //Texture ID
+
+	}
+
+	textureAtlasObject->end();
+
+	return textureAtlasObject;
+}
+