Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

104 Neutral

About Cadde

  • Rank
  1. Thank you! Though i am having a hard time following along with your description (too technical for me, i am still a newbie at D3D, SlimDX and shaders. (Or at least i consider myself to be one) I will read through it several times to see if i can understand it any better but the first two questions that spring to mind is: 1. How would this look in shader code, should i declare an array and use that to determine which texture coordinates i need in shader code? Please show me an example of what i need to do here since i have no idea at all. 2. An example in code would be nice too, i know there are lots of different types of resources i can update but i am not so sure about arrays. Do i even send arrays? Maybe i just send an 8 bit texture? Like i said, i am pretty clueless and i figure stuff out as i go. ------ That aside, I've managed to pass a 2048x2048 texture to my GPU and am testing by rebuilding the entire vertex buffer every frame. Currently i have a 200 x 200 grid of quads that are fed random tu and tv values each update and i am running at 77 FPS. That is beyond expectations for me, i have never been able to run so fast before. I am using a GeForce GTX580 and an I7 at ~3.6 GHz in case anyone wants to know. Mind you, this is the first crude testing. I don't intend to update the entire vertex buffer like this but only the texture values (something i still have to figure out how to do unless someone shows me how) and eventually optimize that down to one byte per character. As of current with some quickie math... 201x201x6 vertices = 242,406 vertices per frame- vertex data size is 24 so that's 5,817,744 per frame. (or ~5.5 MB per frame) Running at 77 FPS, that's 427.21 MB/s sent to the GPU. What a waste but this is just how i work, it helps me organize and think ahead since i never actually plan ahead that much. Edit: Oh and i think (if it's possible) i am going to have a static char buffer so if it isn't updated at all then it would reuse the old one already present on the GPU. In case it wasn't clear before. Which brings up another question, say i want to alter a specific row and/or a specific column or region etc in my little console window. It's possible to just update a portion of the char array without having to update the whole buffer/whatever right? I like performance and say i wanted to make some sort of ASCII animation on the virtual screen without updating the entire thing then that would be possible too right?
  2. I have used ID3DXFont in the past, for full page updates (That is, scrolling text like in a command prompt) it's simply too slow. My idea is to have the bitmap font texture stored in video memory and only alter the texture coordinates when the window needs to be updated. Keep in mind that ID3DXFont too sends texture resources to the hardware after you have created a batch. Thus, sending a full 80x50 grid of characters is as expensive as sending a texture. The difference is i can get rid of some overhead doing it with pre-allocated font maps. XNA does this but i am not so sure it's the optimal solution either. So in essence, my question really is. How can i update a grid of quads that are already assigned to hardware without sending the full vertex buffer every frame. All i am interested in is setting the texture coordinates and if possible, sending only byte arrays to the shader since i only intend to use up to 255 different characters.
  3. I have come to a point where i want to render LOTS of text. My idea here is i want to render the text to a "screen" in my 3D space. I have a few ideas on how i want to do it but i am not sure if it's going to be a good solution. I have fiddled with text rendering in the past with GDI, GDI+ and even in XNA but every time i have run into a limiting factor performance wise. My goal here is to make a computer screen kinda deal with a console. I want it to be as fast as possible to allow text to flash by as fast as it would in your average command prompt. (Not even this has been working for me in the past, always too slow) My first idea is to render the text to a surface and then send that surface to a single quad representing the screen. The downside here is that sending such large textures (I am thinking 1920x1080 in size which obviously would translate to a 2048x2048 texture) every frame or even every other frame etc would still be very slow. So my second idea was to make a single texture, a bitmap font and send that to the GPU once and have X number of quads times Y number of quads for rows and columns. Then update an array or likewise with the tu and tv values for each quad. So if my screen has 80 columns and 50 rows then that would be 4,000 * 2 floats = 32,000 bytes per frame. At least that would be an improvement over sending a new 2048x2048 texture which would be ~16 Megabytes per frame. Then my third idea was to somehow handle the texture coordinates on the GPU and simply sending bytes describing what goes in each column and row. So i have a texture on the GPU and 8,000 triangles. They don't have any texture coordinates assigned initially and i send a stream of 4,000 bytes per frame that the shader would use to set the appropriate texture coordinates. (Obviously i am going for a monospace font here too) Of course the screen wouldn't need to be updates once every frame but i am looking for at least 60 updates per second per virtual screen. And i would love to have more than 80x50 columns and rows too! Which option would be the most viable one and could anyone provide an example for me if he/she has one in mind? For instance, i have no idea of how to actually implement the third option in shader code and even the second option is untested territory for me. Thanks in advance for any help! I will now attempt to make a testbed using at least the 2nd option. //Cadde EDIT: I am also looking for any other alternatives that would be easier to implement and still fast. Those three options where just off the top of my head.
  4. Cadde

    The evolution of Direct3D?

    Well i don't know much about the history of DirectX... And despite some rumblings about the accuracy of Wikipedia it's at least a good start to get a brief overview of DX history. There are two articles of interest, one covering DirectX and the other covering Direct3D. Instead of me linking them just google "DirectX" and "Direct3D" and you will find them in the top 3 results. Beyond that you might have to google each and every version of DirectX and Direct3D separately and build a history from there. Unless of course you can find a game developer that has been around since 1992 and is willing to share his knowledge with you. To answer your question "why it was necessary to" it's simply because demand exceeded the capabilities of the latest version and hardware grew ever faster and more capable. OpenGL played a big part in speeding up the development of DirectX and when OpenGL slowed down (version 1.3) so did DirectX (Version 9.0 a, b, c) and furthermore, the Xbox and PS3 can only use hardware compatible with DirectX 9 and OpenGL | ES 1.0 (OpenGL 1.3) with some features of OGL | ES 2.0 (OpenGL 2.0) respectively. Only 'recently' (with the arrival of Vista, DirectX 10) an enormous demand has arrived for MORE. As gamers and developers demand ever higher fidelity in rendering (graphics) both hardware and drivers need to match the expecations. So, simply put... It needed to evolve because we wanted more! And there are many many more techniques to come as hardware grows, not necessarily in speed but in width.
  5. DOH! It works, you are a god and all that. Now i have a working example to go from to fix my other ones. Thanks! EDIT: Ok, this is what i have learned for all this so far. For projection, a near plane of 0.0f does [color=#ff0000]NOT work. One does indeed need to transpose the matrices. How i managed to get anything useful out of not transposing them i will never know. (Matrix math is still beyond me...) It helps to pay attention when you code, as Mike pointed out you have to set a proper stride. It was initially very unclear to me how to use constant buffers and the answer from Mike on stackoverflow never mentioned that you had to set then to the shaders using SetConstantBuffers. This could have been realized had i known anything about D3D in the first place or by simply looking into the DX SDK examples. Point is, never give up and when you get stuck make sure you don't start assuming things as i did. Now, a quick example on how to properly update constant buffers in case anyone else finds themselves in a similar situation: A simple shader with 3 constant buffers: cbuffer WorldMatrixBuffer : register(b0) { matrix world; }; cbuffer ViewMatrixBuffer : register(b1) { matrix view; }; cbuffer ProjectionMatrixBuffer : register(b2) { matrix projection; }; struct VS_IN { float4 position : POSITION; }; struct PS_IN { float4 position : SV_POSITION; }; PS_IN VShader(VS_IN input) { PS_IN output; output.position = input.position; output.position = mul(output.position, world); output.position = mul(output.position, view); output.position = mul(output.position, projection); return output; } float4 PShader(PS_IN input) : SV_Target { return float4(1.0, 1.0, 0.0, 1.0); } This will take in a vertex buffer, multiply it's positions by the world, view and projection matrices that are defined in their own separate constant buffers. It passes the information along down the rasterizer where each pixel is set to a solid yellow color. One could gain a little bit of performance by multiplying the view and projection matrices before sending them to the shader and using a combined viewProjection cbuffer to reduce the number of mul() operations in the vertex shader stage. For the sake of clarity i have decided not to do this here. The registers (b0, b1 and b2) are defined so we can assign them in code using their respective indexes (slots) and to update and assign them you need (in code): A Buffer with the ConstantBuffer bind, Default resource usage and in this case, no CPU access flags. A data stream to write matrix data to. A matrix is 64 bytes large (float4x4, 16 floats of 4 bytes each) thus you need to have 64 bytes of memory allocated to write to these constant buffers. A context to call UpdateSubresoruce(). Sample code: // Create the projection matrix buffer. projectionMatrixBuffer = new Buffer ( device, new BufferDescription { BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.None, SizeInBytes = Marshal.SizeOf(projection), Usage = ResourceUsage.Default, } ); // Update the projection constant buffer. using (DataStream data = new DataStream(Marshal.SizeOf(projection), true, true)) { data.Write(Matrix.Transpose(projection)); data.Position = 0; context.UpdateSubresource(new DataBox(0, 0, data), projectionMatrixBuffer, 0); } So first we create a buffer with the proper buffer description. Marshal.SizeOf() resides in System.Runtime.InteropServices and is used to determine the size of Types (Classes) and objects (assigned variables) which is helpful if you don't want to manually calculate the size of each constant buffer. In this case i write the matrix directly to the stream but if your cbuffer has more than one element in it it may be useful to create a structure or class to contain all elements of the constant buffer in it before writing to the buffer. For example: [StructLayout(LayoutKind.Sequential)] class HerpClass { public Matrix world; public Matrix view; public Matrix projection; } struct HerpStruct { public Matrix world; public Matrix view; public Matrix projection; } ... int classSize = Marshal.SizeOf(typeof(HerpClass)); // Is 192 (64 * 3) int structSize = Marshal.SizeOf(typeof(HerpStruct)); // Is 192 (64 * 3) Adding any private variables to these classes will still count towards the total size of the class/structure so don't do it. (No i didn't either btw if you thought so, i just want to cover this incase someone gets any ideas.) The reason you need "[StructLayout(LayoutKind.Sequential)]" on the class is because otherwise Marshal.SizeOf will produce an ArgumentException that reads "HerpClass cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed." Thus, using a struct is your best option and structs and classes are pretty much the same things anyways. Yes, you can create a constructor thus enabling you to use "new HerpClass(world, view, projection);" if you so desire. Right, moving on... Before you render you need to set the buffers to the vertex shader (and pixel shader where needed, they are separate) and to do that you do this: // Set the vertex and pixel shaders to the active rendering pipeline. context.VertexShader.Set(vertexShader); context.VertexShader.SetConstantBuffers(new Buffer[] { worldMatrixBuffer }, 0, 1); context.VertexShader.SetConstantBuffers(new Buffer[] { viewMatrixBuffer }, 1, 1); context.VertexShader.SetConstantBuffers(new Buffer[] { projectionMatrixBuffer }, 2, 1); context.PixelShader.Set(pixelShader); context.DrawIndexed(indexCount, 0, 0); Now, i included the Vertex/PixelShader.Set() here as well as the DrawIndexed and Present calls for clarity. You can do it any way you like, but the gist of it all is you set them BEFORE the draw calls. Obviously setting the projection for each mesh you draw is excessive and wastes precious cycles. You only need to set the projection when you change the shader or your projection changes. Like from a form resize or if you are zooming the view or changing the view distance. The same applies with the view matrix, that only needs to be when the camera moves or you switch shaders. To summarize then. Create buffers in code that match the buffers in the shader. Write to the buffers in code when the world, view or projection matrices change using a data stream and update them in the context using UpdateSubresource. Set them to the shader using SetConstantBuffers when the shader is changed. The second argument to the function call is the index as defined in the shader file. Happy coding! //Cadde And once again, thanks for the assist!
  6. Bump and update. I converted the code in the DirectX SDK for Direct3D 11 Tutorial 7 into SlimDX code line by line. (Or at least i think i did) Only a few minor changes/additions needed to be made considering c++ is by far superior to C# when it comes to sizeof() and other such "unsafe" and dangerous things... (UGH) Either way, here is the conversion (Attached file) if anyone is interested in looking at it. I experience the same problems as before... Nothing get's shown on screen when using UpdateSubresource and SetConstantbuffers. I know the code works in C++ but it doesn't do it when i convert to C# and SlimDX. I am at a total loss here. Thanks for any assistance! //Cadde EDIT: Some additional information... Using SlimDX January 2012 version. .Net 2.0 Tried 32 and 64 bit SlimDX dll's for .net 2.0 It works when i use the Effect class. But doing it the "right" way doesn't work at all for me.
  7. Ok, so i decided to make a test bed for this particular thing because like i said, i cannot come to grasps with how to use the constant buffers. It has all been written from scratch to make a proper test this time. Program.cs using System; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; using SlimDX; using SlimDX.Direct3D11; using SlimDX.DXGI; using SlimDX.D3DCompiler; using SlimDX.Windows; using Device = SlimDX.Direct3D11.Device; using Buffer = SlimDX.Direct3D11.Buffer; using Resource = SlimDX.Direct3D11.Resource; namespace SlimDX_Testbed { static class Program { [STAThread] static void Main() { // ---------------------------------------------------------------------------------------------------- // Form, device, render target and viewport creation. RenderForm form = new RenderForm("SlimDX Testbed"); Device device; DeviceContext context; SwapChain swapChain; FeatureLevel[] featureLevels; RenderTargetView renderTarget; Viewport viewport; // Width and height of form and viewport etc. int width = 1600; int height = 900; form.ClientSize = new Size(width, height); featureLevels = new[] { FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, }; // Create device and swap chain. Device.CreateWithSwapChain ( DriverType.Hardware, DeviceCreationFlags.Debug, featureLevels, new SwapChainDescription { BufferCount = 2, Flags = SwapChainFlags.AllowModeSwitch, IsWindowed = true, ModeDescription = new ModeDescription { Format = Format.R8G8B8A8_UNorm, Width = width, Height = height, RefreshRate = new Rational(60, 1), Scaling = DisplayModeScaling.Unspecified, ScanlineOrdering = DisplayModeScanlineOrdering.Progressive, }, OutputHandle = form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput, }, out device, out swapChain ); // Assign the context. context = device.ImmediateContext; // Create the render target view. using (Resource resource = Resource.FromSwapChain<Texture2D>(swapChain, 0)) renderTarget = new RenderTargetView ( device, resource, new RenderTargetViewDescription { Dimension = RenderTargetViewDimension.Texture2D, Format = Format.R8G8B8A8_UNorm, MipSlice = 0, } ); // Create the viewport. viewport = new Viewport(0.0f, 0.0f, width, height, 0.0f, 1.0f); // Assign the render targets and viewport to the context. context.OutputMerger.SetTargets(renderTarget); context.Rasterizer.SetViewports(viewport); // ---------------------------------------------------------------------------------------------------- // Model DataStream vertexData; DataStream indexData; Buffer vertexBuffer; Buffer indexBuffer; VertexBufferBinding[] binding; int vertexCount = 8; int indexCount = 36; // Create the vertex data stream. vertexData = new DataStream(12 * vertexCount, true, true); // Create a 1x1x1 cube. // We will be using TriangleList primitive topology here. vertexData.Write(new Vector3(-1.0f, 1.0f, 1.0f)); // FTL 0 vertexData.Write(new Vector3( 1.0f, 1.0f, 1.0f)); // FTR 1 vertexData.Write(new Vector3(-1.0f, -1.0f, 1.0f)); // FBL 2 vertexData.Write(new Vector3( 1.0f, -1.0f, 1.0f)); // FBR 3 vertexData.Write(new Vector3(-1.0f, 1.0f, -1.0f)); // BTL 4 vertexData.Write(new Vector3( 1.0f, 1.0f, -1.0f)); // BTR 5 vertexData.Write(new Vector3(-1.0f, -1.0f, -1.0f)); // BBL 6 vertexData.Write(new Vector3( 1.0f, -1.0f, -1.0f)); // BBR 7 // Create the index data stream. indexData = new DataStream(sizeof(UInt32) * indexCount, true, true); // Assign the indices for 12 triangles making up the cube indexData.WriteRange<UInt32> ( new UInt32[] { // Front 0, 1, 2, // 1 2, 1, 3, // 2 // Right 1, 5, 3, // 1 3, 5, 7, // 2 // Back 5, 4, 7, // 1 7, 4, 6, // 2 // Left 4, 0, 6, // 1 6, 0, 2, // 2 // Top 4, 5, 0, // 1 0, 5, 1, // 2 // Bottom 2, 3, 6, // 1 6, 3, 7, // 2 } ); // return the reading positions. vertexData.Position = 0; indexData.Position = 0; // Create the vertex buffer. vertexBuffer = new Buffer ( device, vertexData, new BufferDescription { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 12 * vertexCount, StructureByteStride = 0, Usage = ResourceUsage.Default, } ); // Create the index buffer. indexBuffer = new Buffer ( device, indexData, new BufferDescription { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = sizeof(UInt32) * indexCount, StructureByteStride = 0, Usage = ResourceUsage.Default, } ); // Create the vertex bidnings. binding = new[] { new VertexBufferBinding(vertexBuffer, 12, 0), }; // Assign the vertex and index buffers to the rendering pipeline. context.InputAssembler.SetVertexBuffers(0, binding); context.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0); // ---------------------------------------------------------------------------------------------------- // Shaders. VertexShader vertexShader; PixelShader pixelShader; InputElement[] elements; InputLayout layout; ShaderSignature inputSignature; // Create the vertex shader. using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile("ColorShader.fx", "VShader", "vs_5_0", ShaderFlags.Debug | ShaderFlags.EnableStrictness, EffectFlags.None)) { inputSignature = ShaderSignature.GetInputSignature(bytecode); vertexShader = new VertexShader(device, bytecode); } // Create the pixel shader. using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile("ColorShader.fx", "PShader", "ps_5_0", ShaderFlags.Debug | ShaderFlags.EnableStrictness, EffectFlags.None)) pixelShader = new PixelShader(device, bytecode); elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0), }; layout = new InputLayout(device, inputSignature, elements); // Set the vertex and pixel shaders to the active rendering pipeline. context.VertexShader.Set(vertexShader); context.PixelShader.Set(pixelShader); // Set the layout and primitive topology. context.InputAssembler.InputLayout = layout; context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; // ---------------------------------------------------------------------------------------------------- // Matrices Matrix world = Matrix.Identity; Matrix view = Matrix.Identity; Matrix projection = Matrix.PerspectiveFovRH(ToRad(45.0f), (float)width / height, 0.0f, 10000.0f); Matrix viewProjection = view * projection; DataStream worldMatrixData; Buffer worldMatrixBuffer; DataStream viewProjectionMatrixData; Buffer viewProjectionMatrixBuffer; // Create the world matrix data stream. worldMatrixData = new DataStream(64, true, true); // Create the world matrix buffer. worldMatrixBuffer = new Buffer ( device, new BufferDescription { BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 64, StructureByteStride = 0, Usage = ResourceUsage.Default, } ); // Create the combined view and projection matrix data stream. viewProjectionMatrixData = new DataStream(64, true, true); // Create the combined view and projection matrix buffer. viewProjectionMatrixBuffer = new Buffer ( device, new BufferDescription { BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 64, StructureByteStride = 0, Usage = ResourceUsage.Default, } ); Buffer[] constantBuffers = new[] { worldMatrixBuffer, viewProjectionMatrixBuffer, }; context.VertexShader.SetConstantBuffers(constantBuffers, 0, 2); // ---------------------------------------------------------------------------------------------------- // Application loop. Stopwatch sw = new Stopwatch(); double lastUpdate = 0.0f; double updateFrequency = 1.0f / 20; form.KeyDown += (o, e) => { if (e.KeyCode == Keys.Escape) form.Close(); }; MessagePump.Run ( form, () => { if (!sw.IsRunning) sw.Start(); // Update every <updateFrequency> seconds. if (sw.Elapsed.TotalSeconds - lastUpdate >= updateFrequency) { // UPDATE() // Set the view matrix. // Set the "camera" (view) to 0, 0, 0 looking down the negative Z axis using 0, 1, 0 as the up vector. view = Matrix.LookAtRH(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, -1.0f), Vector3.UnitY); // Update the viewProjection matrix. viewProjection = projection * view; // Commented this out because it doesn't behave as it should. // viewProjection = Matrix.Transpose(viewProjection); // Update the matrix constant buffers. viewProjectionMatrixData.Write(viewProjection); viewProjectionMatrixData.Position = 0; context.UpdateSubresource(new DataBox(0, 0, viewProjectionMatrixData), viewProjectionMatrixBuffer, 0); lastUpdate = sw.Elapsed.TotalSeconds; } // RENDER() // Set the world matrix. // Move the cube along the z axis between -10.0f and 10.0f. float z = (float)Math.Cos(sw.Elapsed.TotalSeconds) * 20; world = Matrix.Translation(new Vector3(0.0f, 0.0f, z)); // Commented this out because it doesn't behave as it should. //world = Matrix.Transpose(world); // Update the matrix constant buffers. worldMatrixData.Write(world); worldMatrixData.Position = 0; context.UpdateSubresource(new DataBox(0, 0, worldMatrixData), worldMatrixBuffer, 0); context.ClearRenderTargetView(renderTarget, new Color4(1.0f, 0.0f, 0.1f, 0.2f)); context.DrawIndexed(indexCount, 0, 0); swapChain.Present(0, PresentFlags.None); } ); // ---------------------------------------------------------------------------------------------------- // Cleanup. // Matrix constant buffers. if (worldMatrixBuffer != null) worldMatrixBuffer.Dispose(); if (viewProjectionMatrixBuffer != null) viewProjectionMatrixBuffer.Dispose(); if (worldMatrixData != null) { worldMatrixData.Close(); worldMatrixData.Dispose(); } if (viewProjectionMatrixData != null) { viewProjectionMatrixData.Close(); viewProjectionMatrixData.Dispose(); } // Shaders. if (inputSignature != null) inputSignature.Dispose(); if (layout != null) layout.Dispose(); if (pixelShader != null) pixelShader.Dispose(); if (vertexShader != null) vertexShader.Dispose(); // Model. if (indexBuffer != null) indexBuffer.Dispose(); if (vertexBuffer != null) vertexBuffer.Dispose(); if (indexData != null) { indexData.Close(); indexData.Dispose(); } if (vertexData != null) { vertexData.Close(); vertexData.Dispose(); } // Device etc. if (renderTarget != null) renderTarget.Dispose(); if (swapChain != null) swapChain.Dispose(); if (context != null) context.Dispose(); if (device != null) device.Dispose(); if (form != null) form.Dispose(); // Happy smiley faces in yo face brah! =) } // Converts degrees to radians. static float ToRad(float value) { return (float)(Math.PI / 180) * value; } } } ColorShader.fx cbuffer WorldMatrixBuffer : register(cb0) { matrix world; }; cbuffer ViewProjectionMatrixBuffer : register(cb1) { matrix viewProjection; }; struct VS_IN { float3 position : POSITION; }; struct PS_IN { float4 position : SV_POSITION; }; PS_IN VShader(VS_IN input) { PS_IN output; output.position = float4(input.position, 1.0); output.position = mul(output.position, world); output.position = mul(output.position, viewProjection); return output; } float4 PShader(PS_IN input) : SV_Target { return float4(1.0, 1.0, 0.0, 1.0); } Still not getting my view and projection matrices to update or behave properly. If i comment the "output.position = mul(output.position, viewProjection);" line i get alternating dark blue and yellow as the model moves back and forth. If i uncomment the Matrix.Transpose lines i get the same effect except the yellow phases are shorter. As always, really appreciate the help here! //Cadde EDIT: Forgot to attach the solution.
  8. Well it turns out that i did something wrong when setting the constant buffers after all. I thought there wasn't an Effect class in SlimDX.Direct3D11 but lo and behold there was one. So i started using that and now everything behaves as it should. Still don't need to use Matrix.Transpose though... Which is weird since i am using the LH coordinate system and haven't done anything in the shader to make the switch. I will probably find out later as i go along... Another question as well though. I kinda feel that i am not in (as) complete control with effects rather than VertexShader and PixelShader. I much prefer to do things as low level / non "wrappery" as possible without it becoming a groundwork nightmare. Is there any difference in performance between using the Effect class and using VertexShader/PixelShader classes? And what happened really? I mean, the matrices i sent to the shader where fine yet the shader misbehaved greatly and made all kinds of wonky vertex transformations. It looked like i was looking through a fisheye lens. After i started using effects and used Effect.GetVariableByName("").AsMatrix.SetMatrix() it behaved normally. Sorry, don't have the code i used prior but i am thinking i was updating the wrong registers or whatever. I am new at this so ya, terminology is not right. But i would love to have a working example on how it should be done. cbuffer worldBuffer : register(b0) { matrix worldMatrix; } cbuffer viewBuffer : register(b1) { matrix viewMatrix; } cbuffer projectionBuffer : register(b2) { matrix projectionMatrix; } Like, how would i go at sending matrices to each of these? The reason i split them up like that is because the projection will only be set on initialization and viewport resize, view only once per frame and world once per model / mesh.
  9. I have been trying many different languages revolving around DirectX and even had a stab at OpenGL but i finally settled on C# + SlimDX because it's been the most comfortable solution for me. So, i am making a custom engine for a game i intend to make. It's not going to be a fully fledged engine but more like a support framework. ---- Anyways, the question / problem i am facing right now is that i am (supposedly?) running DirectX 11 and made a simple triangle to play with so i could continue making a camera class. I set up my world, view and projection matrices and a basic color shader. I started getting very strange issues however as i went along. First i got the RH vs LH wrong but that got sorted (I think) and then things got really wonky. If i Matrix.Transpose my world, view and projection matrices before sending them to the shader my screen turns completely <color of triangle>! That is, whatever color of the triangle i assign my view is filled with it. Having tried to "solve" any matrix issues i might have had in my camera class etc for about 4 hours straight i re-built a lot of the cbuffer updating procedures thinking something went wrong there. Out of a "fluke" i commented out the Matrix.Transpose lines and VOILA. Everything worked as it should! So... I know i am supposed to use Matrix.Transpose with DX11 but when i do it breaks. When i don't it works as intended. How can this be? Thanks in advance for any clues or information on the subject. //Cadde
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!