Jump to content

View more

Image of the Day

The beast has a mighty searchlight of evil! #screenshotsaturday https://t.co/bzKepOojDL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Constant Buffer Values not being passed correctly?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 jdub   Members   

459
Like
0Likes
Like

Posted 18 September 2012 - 11:28 AM

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);
}

J.W.

#2 Gavin Williams   Members   

974
Like
0Likes
Like

Posted 18 September 2012 - 09:22 PM

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, 18 September 2012 - 09:24 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.