# [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.

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

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&lt;Matrix&gt;(scene.Camera.Projection);
stream.Write&lt;Matrix&gt;(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 on other sites
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.

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
16
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632593
• Total Posts
3007270

×