Jump to content
  • Advertisement
Sign in to follow this  
Xeile

[SlimDX] Constant Buffers with Matrices

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

Hello folks, I got an issue with constant buffers with some matrices defined as element(s). The problem seems that when update a cbuffer the matrices don't get set or get set properly. Here is are a few snippets that explain how I am trying to do it. This is the HLSL code of my shader. Please note the unbuffered Projection matrix in the top aswell.
float4x4 Projection;

// Constant buffer definition
cbuffer Screen
{
	float4x4	Projection2;	
	float4x4	InverseProjection;
};

// Vertex Shader
void VS_Geometry
(
	in	IA_VS_Geometry	input,
	out	VS_PS_Geometry	output
)
{
	output.Position	= mul(float4(input.Position, 1), mul(World, View));
	output.Depth	= output.Position.z;
	output.Position	= mul(output.Position, Projection);
	//output.Position	= mul(output.Position, Projection2);
	output.Normal	= mul(input.Normal, World);
	output.Binormal	= mul(input.Binormal, World);
	output.Tangent	= mul(input.Tangent, World);
	output.Texture	= input.Texture;
}

This code explains how I instantiate the variables used in my code below.
// Screen (c-buffer) variable of type EffectConstantBuffer (SlimDX)
ScreenVariable = Effect.GetConstantBufferByName("Screen");

// Screen (c-buffer) buffer of type Buffer (SlimDX)
ScreenBuffer = new SlimDX.Direct3D10.Buffer(
	Renderer.Device,
	Marshal.SizeOf(typeof(Matrix)) * 2,
	ResourceUsage.Dynamic,
	BindFlags.ConstantBuffer,
	CpuAccessFlags.Write,
	ResourceOptionFlags.None);

This code explains how I update my c-buffers.
using (DataStream stream = ScreenBuffer.Map(MapMode.WriteDiscard, MapFlags.None))
{
	stream.Write<Matrix>(scene.Camera.Projection);
	stream.Write<Matrix>(Matrix.Invert(scene.Camera.Projection));
	stream.Position = 0;
	ScreenBuffer.Unmap();
}

// Update the buffer
ScreenVariable.SetConstantBuffer(ScreenBuffer);

// Update the unbuffered 
ProjectionVariable.SetMatrix(scene.Camera.Projection);

The issue is, when I use the vertex shader as it now is, with the same lines uncommented, every thing works fine. My problem is when I uncomment the line where Projection2 is used instead of Projection, I get to see a blank screen. Has anyone had similar issues and can tell me what I am doing wrong? Kind regards, Xeile

Share this post


Link to post
Share on other sites
Advertisement
No one got an idea? I haven't tried this without SlimDX framework of course, that would mean I have to rewrite a lot first, but I doubt the problem lies there.

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!