Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to update a matrix array for shader in DirectX 11?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 steven166   Members   -  Reputation: 234

Like
0Likes
Like

Posted 28 January 2013 - 02:06 AM

I am trying to update a matrix array, then send to GPU but it is not working. I tried 2 ways, first I updated a matrix array in a constant buffer using map/unmap. The second method is using SetMatrixArray() in an effect.

 

The first method source code.

    HRESULT hr;
    D3D11_MAPPED_SUBRESOURCE MappedResource;
    V( pd3dImmediateContext->Map( g_pcbVSPerFrame11, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
    CB_VS_PER_FRAME* pVSPerFrame = ( CB_VS_PER_FRAME* )MappedResource.pData;

	XMMATRIX M1 = XMMatrixTranslation(30.0f, 2.0f, 10.0f);
	XMMATRIX M2 = XMMatrixIdentity();	
	XMMATRIX M3 = XMMatrixIdentity();

	pVSPerFrame->g_mMatrixArray[0] = M1;
	pVSPerFrame->g_mMatrixArray[1] = M2;
	pVSPerFrame->g_mMatrixArray[2] = M3;

    pd3dImmediateContext->Unmap( g_pcbVSPerFrame11, 0 );
    pd3dImmediateContext->VSSetConstantBuffers( 1, 1, &g_pcbVSPerFrame11 );		

 

Shader:

VS_OUTPUT RenderSceneVS( VS_INPUT input )
{
    VS_OUTPUT Output;
    float3 vNormalWorldSpace;
    
	float4 temp = 0;
	float3 posL = float3(1.0f, 0.0f, 0.0f);
	temp = mul(float4(input.Position, 1.0f), g_mMatrixArray[1]);
	//temp = mul(float4(posL, 1.0f), g_mMatrixArray[1]);
	//temp = mul(float4(posL, 1.0f), g_mMatrixArray[2]);

    // Transform the position from object space to homogeneous projection space
    Output.Position = mul( float4(temp.xyz, 1.0f), g_mWorldViewProjection );
    
    // Just copy the texture coordinate through
    Output.Color = input.Color; 
    
    return Output;    
}

 

g_mMatrixArray[0], g_mMatrixArray[1] and g_mMatrixArray[2] are the same values (1.0f, 0.0f, 0.0f)

 

 

The second method source code:


        XMMATRIX M1 = XMMatrixIdentity();
	XMMATRIX M2 = XMMatrixTranslation(2.0f, 2.0f, 0.0f);
	XMMATRIX M3 = XMMatrixIdentity();

	g_mMatrixArray.resize(3);

	XMFLOAT4X4* M = &g_mMatrixArray[0];
	g_pMatrixArray->SetMatrixArray(reinterpret_cast<const float*>(&g_mMatrixArray[0]), 0, g_mMatrixArray.size());

 

 

In shader:


cbuffer cbPerFrame : register( b1 )
{
    float4x4 g_mBoneTransform[96];
};

VS_OUTPUT RenderSceneVS( VS_INPUT input )
{
    VS_OUTPUT Output;

	float4 temp = 0;
	float3 posL = float3(1.0f, 0.0f, 0.0f);
	temp = mul(float4(posL, 1.0f), g_mBoneTransform[0]);
		
    // Transform the position from object space to homogeneous projection space
	Output.Position = mul( float4(temp.xyz, 1.0f), g_mWorldViewProjection );    
       
    // Just copy the texture coordinate through
    Output.TextureUV = input.Color;
    
    return Output;    
}

 

 

Both of methods do not work sad.png. Anybody helps me, please?


Edited by steven166, 28 January 2013 - 02:06 AM.


Sponsor:

#2 Zaoshi Kaba   Crossbones+   -  Reputation: 3636

Like
1Likes
Like

Posted 28 January 2013 - 03:16 AM

First method is correct way.

 

I believe you cannot see any change because in your shader you have g_mMatrixArray[1] instead of g_mMatrixArray[0].



#3 steven166   Members   -  Reputation: 234

Like
0Likes
Like

Posted 28 January 2013 - 05:08 AM

Thank Zaoshi Kaba, but I even modify the shader for debug, but values of three arrays are the same (1, 0, 0)

 

cbuffer cbPerFrame: register(b1)
{
float4x4 g_mMatrixArray[10];
}

VS_OUTPUT RenderSceneVS( VS_INPUT input )
{
    VS_OUTPUT Output;    

    float4 temp = 0;
    float3 posL = float3(1.0f, 0.0f, 0.0f);
    float4x4 temp1 = g_mMatrixArray[0] + g_mMatrixArray[1] + g_mMatrixArray[2];
    temp = mul(float4(posL, 1.0f), temp1);

    // Transform the position from object space to homogeneous projection space
    Output.Position = mul( float4(temp.xyz, 1.0f), g_mWorldViewProjection );
    
    Output.Color = input.Color;

    return Output;
}

 

errorls.jpg

 

As you can see the image, all matrices have the same value and they are float1x4 instead of float4x4. I do not understand sad.png


Edited by steven166, 28 January 2013 - 09:20 AM.


#4 Zaoshi Kaba   Crossbones+   -  Reputation: 3636

Like
0Likes
Like

Posted 28 January 2013 - 07:06 AM

cbuffer cbPerFrame: register(t1)
{
float4x4 g_mMatrixArray[10];
}

 

Why register is suddenly t1?



#5 steven166   Members   -  Reputation: 234

Like
0Likes
Like

Posted 28 January 2013 - 09:07 AM

Sorry, I just test it before posting. Actually, it is b1






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS