Commits

duststorm01 committed 989b376 Draft

Experiment with human Instanced characters.
This test shows that creating assets for instancing need serious considerations concerning bonecounts. I'm not there yet.
Fixed human character so it doesn't have shared vertices anymore, to work with Instancing.
Added missing GLSL shader file for Instancing.
Added random animation offset when adding new characters to avoid obvious synchronized movements.

  • Participants
  • Parent commits 47e23ad

Comments (0)

Files changed (10)

Samples/src/OgreRecastPagedCrowdApplication.cpp

 
 
 // TODO this can also be DetourCrowd::MAX_AGENTS or allow setting of Max agents in detourCrowd
-const Ogre::Real OgreRecastPagedCrowdApplication::MAX_CROWD_SIZE = 50;
+const Ogre::Real OgreRecastPagedCrowdApplication::MAX_CROWD_SIZE = 100; // TODO make this a cfg parameter
 
 const Ogre::Real OgreRecastPagedCrowdApplication::RADIUS_EPSILON = 1;
 
     else
         mCrowdSize = OgreDetourCrowd::MAX_AGENTS;
 
-    mCrowdSize = 100;
-
 // TODO make sure crowdSize is a multiple of nbPagedTiles?
 
     mCharacters.reserve(mCrowdSize);
 
         // Create instance manager for managing instances of the robot mesh
         mInstanceManager = mSceneMgr->createInstanceManager(
-                    "RobotInstanceMgr", "robot.mesh",
+                    "CrowdCharacter_1_InstanceMgr", "Gamechar-male.mesh",
                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, instanceTechnique,
                     mCrowdSize); // TODO experiment with batch size
     }
 
     // Iterate over free agent list and distribute evenly
 // TODO allow other distributions
-
-    //for(std::vector<Character*>::iterator iter = mUnassignedCharacters.begin(); iter != mUnassignedCharacters.end(); iter++) {
     int agentsPlaced = 0;
-//    Ogre::String agentsString = "  ";
     while(mUnassignedCharacters.size() != 0 && agentsPlaced < nbAgents) {
         Character *character = mUnassignedCharacters[mUnassignedCharacters.size()-1];
         mUnassignedCharacters.pop_back();
 
         Ogre::Vector3 pos = placeAgent(character, tx, ty);
         mAssignedCharacters.push_back(character);
-        Ogre::Vector2 tilePos = mDetourTileCache->getTileAtPos(pos);
-//        agentsString += Ogre::StringConverter::toString(character->getPosition())+" "+tileToStr(tilePos.x, tilePos.y)+" ";
 
         agentsPlaced++;
     }
 
     character->load(rndPos);
 
+    // Start walking animation at random position to avoid obvious synchronized movement
+    if(INSTANCED_CROWD)
+        ((InstancedCharacter*) character)->randomizeAnimationPosition();
+    else if(OgreRecastApplication::HUMAN_CHARACTERS)
+        ((AnimateableCharacter*) character)->randomizeAnimationPosition();
+// TODO this code replication is stupid. Fix up character classes with a better inheritance scheme, abstracting out demo specific and reusable classes
+
     assignAgentDestination(character);
 
     return rndPos;

include/AnimateableCharacter.h

 
     virtual void show(void);
 
+    void randomizeAnimationPosition(void);
+
 protected:
     bool mDebugDraw;
 

include/InstancedCharacter.h

 
     virtual void show(void);
 
+    void randomizeAnimationPosition(void);
+
 protected:
     bool mDebugDraw;
 

resources/materials/instancing/DepthShadowmapCasterFp.glsl

+
+varying vec2 depth;
+
+void main()
+{
+#if LINEAR_RANGE
+	float finalDepth = depth.x;
+#else
+	float finalDepth = depth.x / depth.y;
+#endif
+	// just smear across all components 
+	// therefore this one needs high individual channel precision
+	gl_FragColor = vec4(finalDepth, finalDepth, finalDepth, 1);
+
+}
+

resources/materials/instancing/Instancing.material

 {
 	set_texture_alias	DiffuseMap	r2skin.jpg
 }
+
+material Examples/Instancing/ShaderBased/Male_0 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_0.png
+}
+
+material Examples/Instancing/ShaderBased/Male_1 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_1.png
+}
+
+material Examples/Instancing/ShaderBased/Male_2 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_2.png
+}
+
+material Examples/Instancing/ShaderBased/Male_3 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_3.png
+}
+
+material Examples/Instancing/ShaderBased/Male_4 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_4.png
+}
+
+material Examples/Instancing/ShaderBased/Male_5 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_5.png
+}
+
+material Examples/Instancing/ShaderBased/Male_6 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_6.png
+}
+
+material Examples/Instancing/ShaderBased/Male_7 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_7.png
+}
+
+material Examples/Instancing/ShaderBased/Male_8 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_8.png
+}
+
+material Examples/Instancing/ShaderBased/Male_9 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_9.png
+}
+
+material Examples/Instancing/ShaderBased/Male_10 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_10.png
+}
+
+material Examples/Instancing/ShaderBased/Male_11 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_11.png
+}
+
+material Examples/Instancing/ShaderBased/Male_12 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_12.png
+}
+
+material Examples/Instancing/ShaderBased/Male_13 : Examples/Instancing/ShaderBased
+{
+	set_texture_alias	DiffuseMap	gameTex_13.png
+}