Jump to content

  • Log In with Google      Sign In   
  • Create Account


Antigroup

Member Since 12 May 2013
Offline Last Active May 24 2013 12:53 PM

Posts I've Made

In Topic: Updating constant buffers corrupting some of the data

12 May 2013 - 06:56 PM

Thanks. I'm not using D3DX, but I found the option for fxc to use different matrix packing.

 

I'm not sure how the order of the constant buffers is decided, but I got it to work as I'd expect it to using this code:

 

context->VSSetConstantBuffers(0, 1, &perFrameConstantBuffer);
context->VSSetConstantBuffers(1, 1, &perObjectConstantBuffer);
context->VSSetShader(vertexShader, NULL, 0);
	
context->PSSetConstantBuffers(0, 1, &perFrameConstantBuffer);
context->PSSetConstantBuffers(1, 1, &perObjectConstantBuffer);
context->PSSetShader(pixelShader, NULL, 0);

In the shader files, the buffers are the exact same:

cbuffer PerFrameConstantBuffer : register(b0)
{
	float4 lightColor;
	float4 lightAmbientColor;
	float4 lightDirection;
	float4 cameraPosition;
};

cbuffer PerObjectConstantBuffer : register(b1)
{
	float4x4 world;
	float4x4 wvp;
	float4 materialDiffuse;
	float4 materialSpecular;
	float4 materialAmbient;
};


 

This works, I'm just not sure why, but I guess I'll figure it out eventually.

 

Thanks for the help.


In Topic: Updating constant buffers corrupting some of the data

12 May 2013 - 02:57 PM

I thought they should be able to use the same slots, but something in another post I read while trying to figure this out seemed to imply that you should use different slots, and when I used the same slots for both, I got a warning about the constant buffer being smaller than expected for the pixel shader.

 

I just tried using slots 0 and 1 on both again, and for some reason the pixel shader has the buffers in the opposite slots from the way the vertex shader has them, but it works not using this code.

 

context->VSSetConstantBuffers(1, 1, &perFrameConstantBuffer);
context->VSSetConstantBuffers(0, 1, &perObjectConstantBuffer);
context->VSSetShader(vertexShader, NULL, 0);

context->PSSetConstantBuffers(1, 1, &perObjectConstantBuffer);
context->PSSetConstantBuffers(0, 1, &perFrameConstantBuffer);
context->PSSetShader(pixelShader, NULL, 0);

 

 

I'm not sure how the slots for constant buffers are chosen. I thought they would be in the order declared in the shader files. Maybe I'll see how I can use reflection to figure that out rather than trial and error.

 

While I'm asking about constant buffers, when using xnamath matrices (with XMFLOAT4X4 for members), is there a reason for it to be necessary to transpose them before sending them to the constant buffer? I didn't see this mentioned anywhere, but a while back I found that not transposing them lead to very wrong results visually, but everything works fine when you transpose them. Does anybody know why this would be, or should I just keep doing it?


PARTNERS