Sign in to follow this  

Constant Buffer update

Recommended Posts


I have a constant buffer that I'm updating each frame, it contains one matrix and one float4, the problem seems that the matrix part is updating
while the color part is getting all zeros no matter anything...

my structure oout of shader (i.e. in the source code) is this:

struct BufferInfo
XMFLOAT4 color;

constant buffer declaration is this:
D3D11_BUFFER_DESC constDesc;
constDesc.Usage =D3D11_USAGE_DEFAULT;


the draw/update part:
BufferInfo bufferInfo01;

XMMATRIX world=sprite[i]->GetWorldMatrix();
XMMATRIX mvp=XMMatrixMultiply(world, vpMatrix);

bufferInfo01.mat = mvp;
bufferInfo01.color = color;

the shader part:

cbuffer cbChangesPerFrame : register(b0)
float4 col_;
matrix mvp_;

the pixel shader:
float4 PS_Main(PS_Input frag) : SV_TARGET
return colorMap_.Sample(colorSampler_,frag.tex0)*float4(col_[0],col_[1],col_[2],1.0f);

if I don't use (return colorMap_.Sample(colorSampler_,frag.tex0)*float4(col_[0],col_[1],col_[2],1.0f);) and use this:
return colorMap_.Sample(colorSampler_,frag.tex0)*col_;

the text (since this is a text renderer, it renders text) won't appear (its alpha will be zero) and it will be black since RGB are all zeroes..

seems that only the matrix part is updates, the color part is updates...any suggestions why is this weird thing happening??


Share this post

Link to post
Share on other sites
I mean the text is black in the first case (return colorMap_.Sample(colorSampler_,frag.tex0)*float4(col_[0],col_[1],col_[2],1.0f);)
and it will not appear in the second case (return colorMap_.Sample(colorSampler_,frag.tex0)*float4(col_[0],col_[1],col_[2],1.0f);)

Share this post

Link to post
Share on other sites
[quote name='kubera' timestamp='1329661334' post='4914504']
Please update pixel shader's constants.

Ah yes, good catch I missed that on my first read too.

OP; as Kubera points out you are only updating the constant block for the Vertex Shader and NOT the pixel shader which is where you are trying to read the value from. You have to set the block for each stage of the pipeline you want the values to be updated in.

Share this post

Link to post
Share on other sites

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