Sign in to follow this  
jdub

Constant Buffer Values not being passed correctly?

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:

[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);
}
[/CODE]

Shader Code:

[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);
}
[/CODE]

Share this post


Link to post
Share on other sites
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

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