[2.2] How to export traditional PCC's textures/info for debugging?

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

[2.2] How to export traditional PCC's textures/info for debugging?

Post by rujialiu » Sat Mar 09, 2019 4:40 am

Hi!

For traditional PCC (non-per-pixel), how can I save PCC's textures (probe's cubemap, blended cubemap) and useful information for debugging? I can already export probes' information (shape/area/camerapos etc), but I need to save cubemap textures for easier analysis and debugging (for example, I suspect some probe's cubemap is completely black). I used to check textures in RenderDoc but it's very time-consuming.

Is there any code/psedu-code for that? I can save normal 2D textures but since it's cubemap, and the PCC class shared some code for traditional and per-pixel modes, I'm a bit lost...

My current problem is that my catch-all probe (a big probe outside everything) seemed not working in SOME cases. I want to it to be a fallback probe so that even if the camera is outside all "regular" probes, we can still see some reflections (provided by the fallback probe). But in SOME cases, when the camera is outside the main area of interest, all reflections are gone. I think in the current implementation (of traditional PCC), when the camera is not inside any probe, the closest probe will be used, so maybe the probe's cubemap is blank? That's why I want to export probes' cubemaps to inspect manually.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4066
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 228
Contact:

Re: [2.2] How to export traditional PCC's textures/info for debugging?

Post by dark_sylinc » Sat Mar 09, 2019 5:00 am

I was going to say to save to DDS format but I remember DDSCodec2::encodeToFile was not ported to 2.2 yet.

You can still save the faces individually to different PNG files.

Get the cubemap into an Image2 using Image2::convertFromTexture and then see my answer to xrgo regarding saving cubemaps.
In that answer we try to avoid Image2::convertFromTexture and use AsyncTextureTickets because he wants to do realtime streaming from GPU to CPU.
But for debugging, using Image2::convertFromTexture is enough and far more convenient.

Use ParallaxCorrectedCubemapBase::getBindTexture to obtain the cubemap of the blended texture, and iterated through the elements in ParallaxCorrectedCubemapBase::getProbes and use CubemapProbe::getInternalTexture to save each texture.

Additionally, I'd recommend using two WireAabb of different colours (SceneManager::createWireAabb):

Code: Select all

wireAabb0->setToAabb( probe->getArea() );
wireAabb1->setToAabb( probe->getProbeShape() );

//Do this for wireAabb1 too
SceneNode *sceneNode = wireAabb0->getParentSceneNode();
Quaternion qRot;
qRot.FromRotationMatrix( wireAabb0->getOrientation() );
qRot.normalize();
sceneNode->setOrientation( qRot );
That way you should be able to visualize the cube regions of the probes in your scene.


Update: To save the Textures basically do:

Code: Select all

Ogre::TextureGpu *texture;
texture = mParallaxCorrectedCubemapOrig->getBindTexture();
saveCubemap( texture );

const Ogre::CubemapProbeVec &probes = mParallaxCorrectedCubemapOrig->getProbes();
Ogre::CubemapProbeVec::const_iterator itor = probes.begin();
Ogre::CubemapProbeVec::const_iterator end  = probes.end();

while( itor != end )
{
    texture = (*itor)->getInternalTexture();
    saveCubemap( texture );
    ++itor;
}
And saveCubemap (pseudo code) does:

Code: Select all

void saveCubemap( Ogre::TextureGpu *texture )
{
    Ogre::Image2 image;
    //Just first mip, but you may want to debug them all
    image.convertFromTexture( texture, 0, 0 );

    for( face in num_faces )
    {
        Ogre::Image2 img2dView;
        img2dView.loadDynamicImage( image.getData( 0 ).atFromOffsettedOrigin( 0, 0, face ),
                                    image.getWidth(), image.getHeight(), image.getDepthOrSlices(),
                                    Ogre::TextureTypes::Type2D, image.getPixelFormat(),
                                    false, //Do not autodelete
                                    1u ); //Just 1 mip
        img2dView.save( ... );
    }
}
If you need to save the mipmaps too, see my reply to xrgo's post.

When it comes to Per-pixel cubemap, the solution is very similar; except that all live probes live inside mParallaxCorrectedCubemapAuto->getBindTexture(); which has N * 6 faces; where N is maxNumProbes you passed to ParallaxCorrectedCubemapAuto::setEnabled; so there is no need to iterate through the probes.

CubemapProbe::getInternalSliceToArrayTexture contains the index to the cubemap array; which is in range [0; maxNumProbes); but may be outside that range if the probe is disabled.
1 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: [2.2] How to export traditional PCC's textures/info for debugging?

Post by rujialiu » Sat Mar 09, 2019 9:35 am

Thanks for the hints!
0 x

Post Reply