Jump to content
  • Advertisement
Sign in to follow this  
jdub

Constant Buffer Values not being passed correctly?

This topic is 2253 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

Trying to draw a simple model here. The output is pretty screwy so I took a look at the application in PIX and found out that when the shaders are called all Matrices inside the constant buffer are the Identity Matrix. Any Ideas on what's going on here?

Matrices are passed to the shader via the following code:


Matrix view = Matrix.LookAtLH(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
Matrix world = Matrix.Translation(0.0f, 0.0f, 0.0f);
Matrix projection = Matrix.PerspectiveFovLH(0.523598776f, 640 / 480, 1.0f, 1000.0f);
this.setShaderParams(view, world, projection);
//****************************************************************************
private void setShaderParams(Matrix v, Matrix w, Matrix p)
{
BufferDescription bufferDescr = new BufferDescription(
Marshal.SizeOf(typeof(ConstantBuffer)),
ResourceUsage.Default,
BindFlags.ConstantBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
Marshal.SizeOf(typeof(Matrix))
);
DataStream stream = new DataStream(Marshal.SizeOf(typeof(ConstantBuffer)), true, true);
stream.Write<ConstantBuffer>(new ConstantBuffer() { View = Matrix.Transpose(v), World = Matrix.Transpose(w), Projection = Matrix.Transpose(p) });
stream.Position = 0;
DXBuffer buffer = new DXBuffer(this.device, stream, bufferDescr);
this.context.VertexShader.SetConstantBuffer(buffer, 0);
}


Shader Code:


/////////////////////////////////////////////////
// GLOBALS
/////////////////////////////////////////////////
SamplerState SampleType;
Texture2D Texture;
cbuffer ConstantBuffer : register( b0 )
{
matrix View;
matrix World;
matrix Projection;
};
struct VS_INPUT
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
float3 Normal : NORMAL;
};
struct PS_INPUT
{
float4 Position : SV_POSITION;
float2 TexCoord : TEXCOORD0;
float3 Normal : NORMAL;
};
PS_INPUT VShader( VS_INPUT input )
{
PS_INPUT output = (PS_INPUT)0;

input.Position.w = 1.0f;
output.Position = mul(input.Position, World);
output.Position = mul(output.Position, View);
output.Position = mul(output.Position, Projection);
output.TexCoord = input.TexCoord;
return output;
}
float4 PShader( PS_INPUT input ) : SV_TARGET
{
return float4(0.0f,0.0f,0.0f,1.0f);
}

Share this post


Link to post
Share on other sites
Advertisement
This seems similar to your previous problem, where you're code appears ok, but it just aint' working. So there must be something you're missing somewhere else I'd say. Have you set the vertex shader by the time you set the constant buffer ? And a mistake i make sometimes is that I'm accidently setting data to the wrong shader, because ive swapped out a shader and missed a line or two. Edited by Gavin Williams

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!