• Advertisement

Matthew Meeks

Member
  • Content count

    15
  • Joined

  • Last visited

Community Reputation

218 Neutral

About Matthew Meeks

  • Rank
    Member
  1. Constant Buffers Disappearing

    That's what I thought.  I must have changed something somewhere else and not realized it had fixed it.  Thanks for your help.
  2. Constant Buffers Disappearing

      Yeah, I had just changed that before posting and posted that before changing it back.  Anyways, I changed the name of the shader from VS_Shader to another name so that it wasn't the same as the other that didn't use them and now it works fine.  I didn't realize the name of the shader entry function would matter.
  3. Constant Buffers Disappearing

    Okay, but the first one does and it is unreferenced there as well.
  4. Constant Buffers Disappearing

    Yes to both of the first questions.  It shows as referenced for every draw call except for the specific ones with those vertex shaders set.  The buffers still show up as being set, just not referenced by the shaders.   I'm not exactly sure what you mean.  I didn't really mention anything about a pixel shader.  If it helps, I've tried adding the same constant buffers to the pixel shader and in the vertex, geometry, and pixel shader each shows unreferenced, yet in the calls directly before, using different shaders with the exact same code for declaring the constant buffers, everything is fine.
  5. I'm trying to make a particle system where I send a pointlist and expand quads from it.  I'd done this years ago but lost the code.  Everything seems to be fine except that the constant buffers (2 of them at 0 and 1) are somehow considered unreferenced for that draw call.  I've also noticed that the same happens when drawing sprites, though I had not noticed until now because I had no need of the constant buffers then.   I've tried taking out the geometry shader, using triangle lists, moving the order at which it is rendered, and setting the constant buffers to the vertex shader immediately before calling draw on the device context, and still no luck.  I'm using the Nsight plugin for Visual Studio to debug.  All the buffers contain the correct data, and every shader except the vertex shaders used for sprites and for the particles lists the constant buffers correctly.  I've checked the output with the Debug flag enabled and nothing appears between the time I prepare the particles to be rendered and after the call has been sent.   Only thing that I can think of is that it has something to do with the hlsl compiler not defining the buffers as referenced somehow.   Here's the code that renders (should render) the particles: internal override void Render() { //So I can tell where this begins in the output window System.Diagnostics.Debug.WriteLine("BEGIN PARTICLE"); //base.Render is an empty method at the moment base.Render(); if (buffer.Elements == 0) return; var o = Renderer.Context.InputAssembler.PrimitiveTopology; Renderer.Context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList; Renderer.SetPSRes(ResLibrary.GetTex2D(Texture), 0); Renderer.Set(vs); Renderer.Set(fs); //storing the current geometry shader so that it can be set back after //probably will just remove this and set the geometry shader back to none var ogs = Renderer.Context.GeometryShader.Get(); Renderer.Set(gs); //Setting the constant buffers. These should already be set but just making sure. ShaderGlobals.SetWorld(Matrix.Identity); ShaderGlobals.UpdateCamera(Renderer.Scene.CurrentCamera.GetLocation(), Renderer.Scene.CurrentCamera.View, Renderer.Scene.CurrentCamera.Projection); Renderer.Set(buffer, 0, 0); Renderer.Draw(buffer.Elements, 0); Renderer.Context.GeometryShader.Set(ogs); Renderer.Context.InputAssembler.PrimitiveTopology = o; System.Diagnostics.Debug.WriteLine("END PARTICLE"); } Here are the vertex shaders that cause problems:   Particle Vertex Shader: cbuffer MatrixBuffer: register(b0) { matrix G_View; matrix G_Projection; float3 G_CamPos; float G_gt; }; cbuffer WorldBuffer: register(b1) { matrix G_World; float3x3 G_World3x3; }; struct VertexInputType { float4 position : POSITION; float4 color : COLOR; float2 texcoord0 : TEXCOORD0; }; struct PixelInputType { float4 position : SV_POSITION; float4 color : COLOR; float2 texcoord0 : TEXCOORD0; }; PixelInputType VS_Shader(VertexInputType input) { PixelInputType output; output.position = mul(input.position, G_World); output.position = mul(output.position, G_View); output.position = mul(output.position, G_Projection); output.position = input.position; output.texcoord0 = input.texcoord0; output.color = input.color; return output; } Sprite Vertex Shader: cbuffer MatrixBuffer: register(b0) { matrix G_View; matrix G_Projection; float3 G_CamPos; float G_gt; }; cbuffer WorldBuffer: register(b1) { matrix G_World; float3x3 G_World3x3; }; struct VertexInputType { float4 position : POSITION; float4 color : COLOR; float2 texcoord0 : TEXCOORD0; }; struct PixelInputType { float4 position : SV_POSITION; float4 color : COLOR; float2 texcoord0 : TEXCOORD0; }; PixelInputType VS_Shader(VertexInputType input) { PixelInputType output; input.position.w = 1.0f; output.position = input.position; output.texcoord0 = input.texcoord0; output.color = input.color; return output; } Any help at all is appreciated.  I've looked at this for several hours now trying to figure anything out and I'm out of ideas. Also if there's any more information I can give that might help let me know.
  6. DX11 Engine

    Graphics engine I'm creating with DirectX 11.
  7. Stencil Buffer

    Yes I am
  8. Stencil Buffer

    I'm having issues understanding how stencil buffers work.  I used them a few times in XNA but there appears to be many differences.  The comparison test always seems to pass and the objects are always drawn.   Here are my depth states: DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; DepthState = DepthStencilState.FromDescription(Device, dsStateDesc); //=== DepthStencilStateDescription dsaStateDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = true, FrontFace = new DepthStencilOperationDescription() { Comparison = Comparison.Greater, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Increment, DepthFailOperation = StencilOperation.Zero }, BackFace = new DepthStencilOperationDescription() { Comparison = Comparison.Always, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Increment, DepthFailOperation = StencilOperation.Zero }, StencilWriteMask = 0, StencilReadMask = 1, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; addDepthState = DepthStencilState.FromDescription(Device, dsaStateDesc); //=== DepthStencilStateDescription dscStateDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = true, FrontFace = new DepthStencilOperationDescription() { Comparison = Comparison.Equal, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep, DepthFailOperation = StencilOperation.Keep }, BackFace = new DepthStencilOperationDescription() { Comparison = Comparison.Equal, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep, DepthFailOperation = StencilOperation.Keep }, StencilReadMask = 1, StencilWriteMask = 1, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; compareDepthState = DepthStencilState.FromDescription(Device, dscStateDesc);   When I draw: Clear the depth/stencil buffer set the first depth state draw the world set the second depth state draw the cube to render the second view point on set the third depth state draw the world from the second view point   If this helps these are the XNA depth states I'm trying to mimic: DepthStencilState addIfPortal = new DepthStencilState() { StencilEnable = true, StencilFunction = CompareFunction.Always, StencilPass = StencilOperation.Increment }; DepthStencilState checkPortal = new DepthStencilState() { StencilEnable = true, StencilFunction = CompareFunction.Equal, ReferenceStencil = 1, StencilPass = StencilOperation.Keep };   I appreciate any help and thanks for your patience
  9. DX11 First Attempts

    My first attempts at programming with DX11 through SlimDX.
  10. DX11 DX11 Shadow Map

    Nevermind passed the wrong description.
  11. DX11 DX11 Shadow Map

    I have tried both with and without dividing by w with the same result.  I had placed the division of w to ensure that w was always one as it should have been.  I am not outputting to a depth-stencil buffer but rather a Texture2D render target.  Not sure if this is the preferred method but i choose this because I eventually want to do more with the shadow map (different levels of light from the same source for semitransparent objects).   EDIT: I will try binding a depth buffer and attempt that way.   Thanks for the help!
  12. inverse transformation of the world matrix

    You could try transpose. http://msdn.microsoft.com/en-us/library/windows/desktop/bb509701(v=vs.85).aspx This will give the inverse of any orthogonal matrix.
  13. inverse transformation of the world matrix

    Why not pass the inverse of the world matrix as a variable to your shader? And normally you would be multiplying the point by the world, view, and projection matrices to transform from object space to world space.  Is that what you mean to do?   EDIT: If you still intend to invert the matrix, it would get very slow to invert the matrix for every vertex, every frame.  The best way to go about this is to pass the preinverted matrix to the shader once.
  14. DX11 DX11 Shadow Map

    Yeah sorry wrote that with a migraine and tried to do it as fast as possible, it didn't work.  I've changed some things around and got closer to what I wanted, getting values in-between 0 and 1, except now the farther objects are 0 and the closer are 1.  My understanding is that farther objects return depths closer to 1. In the vs: float4 worldPosition = mul(Output.position, World); float4 viewPosition = mul(worldPosition, View); Output.position = mul(viewPosition, Projection);     In the ps:   return input.position.z / input.position.w;   Really simple yet I still can't figure out why.   And just in case the problem lies in the matrices: View: View = Matrix.LookAtLH(Position, cameraFinalTarget, up); Projection: Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)Width / (float)Height, 0.01f, 800f);   Thanks for the help and apologies for the vagueness of the original post.
  15. DX11 DX11 Shadow Map

    Back again with a new problem, I'm having issues rendering a shadow map and then using it in another shader.   I create a 256x256 texture here with R32_Float as the format:   Texture2D shadowBuffer = new Texture2D(device, new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R32_Float, Height = 256, Width = 256, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default }); var shadowView = new RenderTargetView(device, shadowBuffer, new RenderTargetViewDescription() { Format = Format.R32_Float, Dimension = RenderTargetViewDimension.Texture2D, MipSlice = 0, }); shadowSView = new ShaderResourceView(device, shadowBuffer, new ShaderResourceViewDescription() { Format = Format.R32_Float, Dimension = ShaderResourceViewDimension.Texture2D, MostDetailedMip = 0, MipLevels = 1, });     I then render depth values to this texture and use it in another shader.  My problem is that when the values are sampled from the texture, they are clamped to 0-1. Any help is appreciated.   EDIT: It has occured to me that the problem may lie in light matrices.  I create a orthographic projection and view matrix to act as a view from the sun:   private static void SetUpSun() { SunProj = Matrix.OrthoLH(512, 512, 256, 1024); } private static void UpdateSun() { Vector3 SunPos = new Vector3((float)Math.Sin(wt / 1f) * -512, (float)Math.Cos(wt / 1f) * -512, 0) + Camera.Position; SunView = Matrix.LookAtLH(SunPos, Camera.Position, Vector3.UnitY); }
  • Advertisement