| 438 | } |
| 439 | |
| 440 | void 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 ); |
nothing calls this directly
no test coverage detected