Ejemplo n.º 1
0
/// Update the instance buffer data for a set of graphics scene object sub-meshes.
///
/// @param[in] pContext  Context in which this job is running.
void UpdateGraphicsSceneSubMeshBuffersJob::Run( JobContext* /*pContext*/ )
{
    const GraphicsSceneObject* pSceneObjects = m_parameters.pSceneObjects;
    HELIUM_ASSERT( pSceneObjects );

    const GraphicsSceneObject::SubMeshData* pSubMeshes = m_parameters.pSubMeshes;
    HELIUM_ASSERT( pSubMeshes );

    float32_t* const* ppConstantBufferData = m_parameters.ppConstantBufferData;
    HELIUM_ASSERT( ppConstantBufferData );

    uint_fast32_t subMeshCount = m_parameters.subMeshCount;
    for( uint_fast32_t subMeshIndex = 0;
        subMeshIndex < subMeshCount;
        ++subMeshIndex, ++pSubMeshes, ++ppConstantBufferData )
    {
        float32_t* pConstantBuffer = *ppConstantBufferData;
        if( !pConstantBuffer )
        {
            continue;
        }

        const GraphicsSceneObject::SubMeshData& rSubMesh = *pSubMeshes;

        size_t sceneObjectIndex = rSubMesh.GetSceneObjectId();
        const GraphicsSceneObject& rSceneObject = pSceneObjects[ sceneObjectIndex ];

        const Simd::Matrix44* pBonePalette = rSceneObject.GetBonePalette();

#if L_USE_GRANNY_ANIMATION
        const void* pBoneData = rSceneObject.GetBoneData();
        HELIUM_ASSERT( pBoneData );

        Simd::Matrix44 inverseBoneReferencePose;
#else
        const Simd::Matrix44* pInverseReferencePose = rSceneObject.GetInverseReferencePose();
        HELIUM_ASSERT( pInverseReferencePose );
#endif

        const uint8_t* pSkinningPaletteMap = rSubMesh.GetSkinningPaletteMap();
        HELIUM_ASSERT( pSkinningPaletteMap );

        Simd::Matrix44 skinningMatrix;

        uint_fast8_t boneCount = rSceneObject.GetBoneCount();
        for( uint_fast8_t boneIndex = 0; boneIndex < boneCount; ++boneIndex )
        {
            size_t skinningPaletteIndex = pSkinningPaletteMap[ boneIndex ];
            if( skinningPaletteIndex >= BONE_COUNT_MAX )
            {
                continue;
            }

            float32_t* pSkinningMatrix43 = pConstantBuffer + skinningPaletteIndex * 12;

            const Simd::Matrix44& rBoneTransform = pBonePalette[ boneIndex ];
#if L_USE_GRANNY_ANIMATION
            Granny::GetInverseBoneReferencePose( inverseBoneReferencePose, pBoneData, boneIndex );
            skinningMatrix.MultiplySet( inverseBoneReferencePose, rBoneTransform );
#else
            const Simd::Matrix44& rInverseBoneReferencePose = pInverseReferencePose[ boneIndex ];
            skinningMatrix.MultiplySet( rInverseBoneReferencePose, rBoneTransform );
#endif

            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 0 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 4 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 8 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 12 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 1 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 5 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 9 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 13 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 2 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 6 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 10 );
            *pSkinningMatrix43       = skinningMatrix.GetElement( 14 );
        }
    }

    JobManager& rJobManager = JobManager::GetStaticInstance();
    rJobManager.ReleaseJob( this );
}
Ejemplo n.º 2
0
void GraphicsSceneView::SetViewAndProjectionMatrices( const Simd::Matrix44& rView, const Simd::Matrix44& rProjection )
{
	m_bDirtyView = false;

	// Set view matrix and extract "look-at" vectors.
	m_viewMatrix = rView;

#if HELIUM_SIMD_SIZE == 16
	m_origin = Simd::Vector3( rView.GetSimdVector( 3 ) );
	m_forward = Simd::Vector3( rView.GetSimdVector( 2 ) );
	m_up = Simd::Vector3( rView.GetSimdVector( 1 ) );
#else
	m_origin = Simd::Vector3( rView.GetElement( 12 ), rView.GetElement( 13 ), rView.GetElement( 14 ) );
	m_forward = Simd::Vector3( rView.GetElement( 8 ), rView.GetElement( 9 ), rView.GetElement( 10 ) );
	m_up = Simd::Vector3( rView.GetElement( 4 ), rView.GetElement( 5 ), rView.GetElement( 6 ) );
#endif

	// Set projection matrix and recover projection parameters.
	m_projectionMatrix = rProjection;

	const float32_t xScale = rProjection.GetElement( 0 );
	const float32_t yScale = rProjection.GetElement( 5 );
	const float32_t zScale = rProjection.GetElement( 10 );
	const float32_t tScale = rProjection.GetElement( 14 );

	m_horizontalFov = 2.0f * Atan( 1.0f / xScale ) * static_cast<float32_t>( HELIUM_RAD_TO_DEG );
	m_aspectRatio = yScale / xScale;
	m_nearClip = -tScale / zScale;
	m_farClip = tScale / (1.0f - zScale);

	// Compute the inverse view and combined inverse view/projection matrices.
	m_viewMatrix.GetInverse( m_inverseViewMatrix );
	m_inverseViewProjectionMatrix.MultiplySet( m_inverseViewMatrix, m_projectionMatrix );

	// Initialize the view frustum.
	m_frustum.Set( m_inverseViewProjectionMatrix.GetTranspose() );
}