Page 1 of 1

FPS, batch count and triangle count error using compositor

Posted: Wed Mar 13, 2013 11:21 am
by robert_sasu
There is a big difference between triangles and batch count written to the HUD if I use compositor (in this case bloom) or not. I want every time to watch FPS, batch count and triangle count. Another strange thing is that, when I put precipitation and I have planar reflection even if bloom is working I get the triangles and batch count from the planar reflection, but values are 6 times more then usual. (Precipitations are not done with compositor - it is an elipsoid rendered over the camera you are using and there are textures moving down - performance is better then compositor, and also the effects are slightly better).

This is the code where I get batchCount and TriangleCount. mAdditionalBatchCount and mAdditionalTriangleCount are from PLanarReflection which is another node is SceneManager if precipitation is on.

Code: Select all

    void VideoSystem::UpdateStatus()
    {
        // Sum Batch/triangle count across all render targets.
        unsigned int bc = mAdditionalBatchCount; 
		unsigned int tc = mAdditionalTriangleCount;
        Ogre::RenderSystem::RenderTargetIterator iter =
                Root->getRenderSystem()->getRenderTargetIterator();
        while (iter.hasMoreElements())
        {
            Ogre::RenderTarget* rt = iter.getNext();
			if(rt->isAutoUpdated() || this->PrecipitationsEnabled)
			{
				bc += rt->getBatchCount();
				tc += rt->getTriangleCount();
			}
        }

        // Count fps only from active render forms.
        double fps = 0;
        for each (RenderForm^ rf in this->RenderFormList) 
		{
			Ogre::RenderWindow *ogreWindow = rf->OgreWindow;
            if (ogreWindow) 
			{
                fps += ogreWindow->getAverageFPS();
				bc += ogreWindow->getBatchCount();
				tc += ogreWindow->getTriangleCount();
            }
        }
		// add environment cube map stats
		bc += VideoSystem::CubeMapStats->Batches;
		tc += VideoSystem::CubeMapStats->Triangles;

        fps /= this->RenderFormList->Count;

        AutoMonitorLock lock(SimplePropertyLock);
		
		// Update status
		mStatus.AverageFps = fps;
		mStatus.BatchCount = bc;
		mStatus.TriangleCount = tc;

		Ogre::ColourValue col;
		col = Scene->getAmbientLight();
		mStatus.SceneAmbient = Vector(col.r, col.g, col.b);

        if (Environment->SunLight != nullptr) {
		    col = Environment->SunLight->getDiffuseColour();
		    mStatus.SunDiffuse = Vector(col.r, col.g, col.b);
		    col = Environment->SunLight->getSpecularColour();
		    mStatus.SunSpecular = Vector(col.r, col.g, col.b);
        } else {
            mStatus.SunDiffuse = Vector::Zero;
            mStatus.SunSpecular = Vector::Zero;
        }
        if (Environment->MoonLight != nullptr) {
		    col = Environment->MoonLight->getDiffuseColour();
		    mStatus.MoonDiffuse = Vector(col.r, col.g, col.b);
		    col = Environment->MoonLight->getSpecularColour();
		    mStatus.MoonSpecular = Vector(col.r, col.g, col.b);
        } else {
            mStatus.MoonDiffuse = Vector::Zero;
            mStatus.MoonSpecular = Vector::Zero;
        }
	}
FPS values I consider to be correct, because the situations are slightly different (and there are also other processes running on my PC). The problem is with batchcount and triangle count.
I have tried to put status update before rendering and after rendering the values are the same.
Any suggestion what to do ?

Bloom off
Image

Bloom on
Image

Bloom on, but rain
Image

Re: FPS, batch count and triangle count error using composit

Posted: Wed Mar 13, 2013 2:49 pm
by drwbns
Looks like a compositor bug to me...

Re: FPS, batch count and triangle count error using composit

Posted: Wed Mar 13, 2013 3:11 pm
by robert_sasu
I hoped it would not be a compositor bug, in this project I am using Ogre1.7, and will not port it just to Ogre1.9, but after I resolved most of the bugs of that repo when using DirectX 11 Render System.

In the last picture you can see a lot of triangles, which I can't really explain. As planar reflection adds just 360k (360000) triangles, the scene rendered again. The fog is totally ogre based.
The rain is created like this: a manual object, elipsoid with 16 rings and 16 segments and 3 textures using to texture that elipsoid, the textures are 1024*1024. The performance is barely affected by rain, without planar reflection there is a 3 FPS drop. (same place) So that plus 1.5million triangles are just error on calculation again (I think).
Can anyone help me out with this, by giving me suggestion what to modify in UpdateStatus function to work - just the second part when rain is on, as the first part I consider to be compositor bug?

Re: FPS, batch count and triangle count error using composit

Posted: Wed Mar 13, 2013 3:36 pm
by drwbns
Maybe the bug source is where the batch and triangle counts are calculated. Are compositors being ignored there?

Re: FPS, batch count and triangle count error using composit

Posted: Wed Mar 13, 2013 3:51 pm
by robert_sasu
The code of calculating traingles and batches is on my first post. I do not ignore compositor.

Re: FPS, batch count and triangle count error using composit

Posted: Wed Mar 13, 2013 5:49 pm
by scrawl
Well I am using this code and it works fine even with compositors.

Code: Select all

        unsigned int triCount = 0;
        unsigned int batchCount = 0;

        if (compositorsEnabled)
        {
            CompositorInstance* c = NULL;
            CompositorChain* chain = CompositorManager::getSingleton().getCompositorChain (viewport);
            // accumlate tris & batches from all compositors with all their render targets
            for (unsigned int i=0; i < chain->getNumCompositors(); ++i)
            {
                if (chain->getCompositor(i)->getEnabled())
                {
                    c = chain->getCompositor(i);
                    RenderTarget* rt;
                    for (unsigned int j = 0; j < c->getTechnique()->getNumTargetPasses(); ++j)
                    {
                        std::string textureName = c->getTechnique()->getTargetPass(j)->getOutputName();
                        rt = c->getRenderTarget(textureName);
                        triCount += rt->getTriangleCount();
                        batchCount += rt->getBatchCount();
                    }
                }
            }
        }
        else
        {
            triCount = stats.triangleCount;
            batchCount = stats.batchCount;
        }
I guess compositor render targets are not present in the RenderTargetIterator, because they're pretty much internal.

Re: FPS, batch count and triangle count error using composit

Posted: Wed Mar 13, 2013 10:30 pm
by robert_sasu
Thanks scrawl for your response and code :) I will try it Friday.

Re: FPS, batch count and triangle count error using composit

Posted: Thu Jan 15, 2015 11:26 pm
by Rykemapo
I realize this thread is old, but there seemed to be no closure, i.e. "Thanks I tried it and it worked".
I ran into the same problem and scrawl's code works.

Thanks, I tried it and it worked.

Re: FPS, batch count and triangle count error using composit

Posted: Fri Jan 16, 2015 3:16 am
by scrawl
Haha, good to know :)