MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / capture

Method capture

Engine/source/util/imposterCapture.cpp:440–506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

438}
439
440void ImposterCapture::capture( const MatrixF &rotMatrix,
441 GBitmap **imposterOut,
442 GBitmap **normalMapOut )
443{
444 GFXTransformSaver saver;
445
446 // this version of the snapshot function renders the shape to a black texture, then to white, then reads bitmaps
447 // back for both renders and combines them, restoring the alpha and color values. this is based on the
448 // TGE implementation. it is not fast due to the copy and software combination operations. the generated bitmaps
449 // are upside-down (which is how TGE generated them...)
450
451 (*imposterOut) = new GBitmap( mDim, mDim, false, GFXFormatR8G8B8A8 );
452 (*normalMapOut) = new GBitmap( mDim, mDim, false, GFXFormatR8G8B8A8 );
453
454 // The object to world transform.
455 MatrixF centerMat( true );
456 centerMat.setPosition( -mCenter );
457 MatrixF objMatrix( rotMatrix );
458 objMatrix.mul( centerMat );
459 GFX->setWorldMatrix( objMatrix );
460
461 // The view transform.
462 MatrixF view( EulerF( M_PI_F / 2.0f, 0, M_PI_F ), Point3F( 0, 0, -10.0f * mRadius ) );
463 mRenderPass->assignSharedXform( RenderPassManager::View, view );
464
465 mRenderPass->assignSharedXform( RenderPassManager::Projection, GFX->getProjectionMatrix() );
466
467 // Render the diffuse pass.
468 mRenderPass->clear();
469 mMeshRenderBin->getMatOverrideDelegate().bind( ImposterCaptureMaterialHook::getDiffuseInst );
470 _renderToTexture( mBlackTex, mBlackBmp, ColorI(0, 0, 0, 0) );
471 _renderToTexture( mWhiteTex, mWhiteBmp, ColorI(255, 255, 255, 255) );
472
473 // Now render the normals.
474 mRenderPass->clear();
475 mMeshRenderBin->getMatOverrideDelegate().bind( ImposterCaptureMaterialHook::getNormalsInst );
476 _renderToTexture( mNormalTex, *normalMapOut, ColorI(0, 0, 0, 0) );
477
478
479 _separateAlpha( *imposterOut );
480 _convertDXT5nm( *normalMapOut );
481
482 if ( 0 )
483 {
484 // Render out the bitmaps for debug purposes.
485 FileStream fs;
486 if ( fs.open( "./blackbmp.png", Torque::FS::File::Write ) )
487 mBlackBmp->writeBitmap( "png", fs );
488
489 fs.close();
490
491 if ( fs.open( "./whitebmp.png", Torque::FS::File::Write ) )
492 mWhiteBmp->writeBitmap( "png", fs );
493
494 fs.close();
495
496 if ( fs.open( "./normalbmp.png", Torque::FS::File::Write ) )
497 (*normalMapOut)->writeBitmap( "png", fs );

Callers

nothing calls this directly

Calls 12

assignSharedXformMethod · 0.80
getProjectionMatrixMethod · 0.80
writeBitmapMethod · 0.80
openMethod · 0.65
closeMethod · 0.65
Point3FClass · 0.50
ColorIClass · 0.50
setPositionMethod · 0.45
mulMethod · 0.45
setWorldMatrixMethod · 0.45
clearMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected