Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#Actualsteven166

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?


#1steven166

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 :(. Anybody helps me, please?


PARTNERS