Sign in to follow this  

Strange shader behavior due to..

This topic is 3940 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I've experienced some strange shader behavior due to placement of SetMatrix in my code. I was hoping someone could explain to me why this was. When my render code was like this:
for each object obj..
	..
	matWorldViewProj = m_worldMatrix * m_viewMatrix * m_projMatrix;

	m_pRenderEffect->SetTechnique( m_pTechnique );
	UINT nPasses;
	m_pRenderEffect->Begin( &nPasses, 0 );
	for( UINT i = 0; i < nPasses; i++ )
	{
		m_pRenderEffect->BeginPass( i );

		m_pRenderEffect->SetMatrix( "matWorldViewProj", &matWorldViewProj );
		render( obj );

		m_pRenderEffect->EndPass( );
	}
	m_pRenderEffect->End( );
	..

It freaked out, i was unable to control the camera but instead was able to move objects around in a strange way by trying to move the camera However, when my render code was like this:
for each object obj..
	..
	matWorldViewProj = m_worldMatrix * m_viewMatrix * m_projMatrix;

	m_pRenderEffect->SetTechnique( m_pTechnique );
	m_pRenderEffect->SetMatrix( "matWorldViewProj", &matWorldViewProj );
	UINT nPasses;
	m_pRenderEffect->Begin( &nPasses, 0 );
	for( UINT i = 0; i < nPasses; i++ )
	{
		m_pRenderEffect->BeginPass( i );

		render( obj );

		m_pRenderEffect->EndPass( );
	}
	m_pRenderEffect->End( );
	..

Everything worked fine, the camera moved correctly and objects behaved as they should. Why is there a difference where i put
m_pRenderEffect->SetMatrix( "matWorldViewProj", &matWorldViewProj );
?

Share this post


Link to post
Share on other sites
If you change any effect states via ID3DXEffect::Setx functions (e.g. SetMatrix) within a BeginPass/EndPass pair, you have to call ID3DXEffect::CommitChanges for those changes to take effect correctly.

Share this post


Link to post
Share on other sites

This topic is 3940 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this