Page 1 of 1

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

Posted: Sat Mar 09, 2019 4:40 am
by rujialiu

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.

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

Posted: Sat Mar 09, 2019 5:00 am
by dark_sylinc
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() );
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 );
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 ... );
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.

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

Posted: Sat Mar 09, 2019 9:35 am
by rujialiu
Thanks for the hints!