gomidas

C# SharpDX how to render outline ?

3 posts in this topic

I am trying to render outline for my mesh. I basicly re-render the mesh without texture and put color. My problem is I want to show the outline topmost. When I clear depthview after rendering outline mesh my outline stays background of target mesh but also background of other meshes. I want to show outline top of other meshes but behind of my target mesh ? Is that possible ? If I clear depthview for mesh and outline at this time my mesh will be top of other meshes which I do not want.

0

Share this post


Link to post
Share on other sites

The way i've done outline rendering before is to do an additional pass of the scene geometry. Enable front face culling, and in this particular pass's vertex shader you'd offset the vertice positions in the direction of the normal (making this secondary mesh layer larger).

Than in the pixel shader you can keep it simple, and just return black or something. This should give you the outline you're looking for. You'll have to do additional checks, and calculations if you want the mesh the mouse is hovering above to be the only one that is outlined, like inverse ray projecting (picking).

Here is the URL i've used before to implement it. It should be pretty easy to translate this from XNA to D3D.  

http://rbwhitaker.wikidot.com/toon-shader

You can also do a sobel operation as a post-processing step to achieve an outline around your meshes. Though imho, it looks to clean for toon renders, but for selection outlining it might be perfect for you

0

Share this post


Link to post
Share on other sites
35 minutes ago, markypooch said:

The way i've done outline rendering before is to do an additional pass of the scene geometry. Enable front face culling, and in this particular pass's vertex shader you'd offset the vertice positions in the direction of the normal (making this secondary mesh layer larger).

Than in the pixel shader you can keep it simple, and just return black or something. This should give you the outline you're looking for. You'll have to do additional checks, and calculations if you want the mesh the mouse is hovering above to be the only one that is outlined, like inverse ray projecting (picking).

Here is the URL i've used before to implement it. It should be pretty easy to translate this from XNA to D3D.  

http://rbwhitaker.wikidot.com/toon-shader

You can also do a sobel operation as a post-processing step to achieve an outline around your meshes. Though imho, it looks to clean for toon renders, but for selection outlining it might be perfect for you

I render it by clearing  context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0); And also I did it larger but I did those already problem is when I have a mesh backwards front mesh's outline stays backward other mesh here is the result and issue : https://www.youtube.com/watch?v=4bcdfndc3sQ&feature=youtu.be

 

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • By EMB
      Hi all,
      EDIT: Thanks @Kylotan for moving to the lounge. :-)
      Assuming folks here would have more familiarity than on SO.  I recently purchased an AMD/ASUS/RX570 bundle and I'm running Chrome Beta.  It works but my frame rate is slow, <5pfs.  FF works fine.  I formerly found some things to try, but completely different system/problem.

      Google chokes on anything I put in related to rx570 and considering I was lucky to get one, I wonder if anyone here has seen similar issues and been able to track down some settings or knew what to try to get chrome over it's foolishness?  A link/resources?
       
      I updated drivers.
       
      Looking forward to getting into webgl.
    • By ErnieDingo
      Before you read, apologies for the wall of text!  
      I'm looking to leverage efficiencies in DirectX 11 calls, to improve performance and throughput of my game.  I have a number of bad decisions I am going to remedy, but before I do, I am just wanting to get input into I should put effort into doing these.
      I've been running for a while with a high frame rate in my game, but as I add assets, its obviously dipping (its a bit of an n squared issue).  I'm fully aware of the current architecture, and I'm looking to take care of some severe vertex buffer thrashing i'm doing at the moment. 
      Keep in mind, the game engine has evolved over the past year so some decisions made at that time in hindsight are considered bad, but were logical at the time.
      The scenarios:
      Current: my game world is broken up by quad tree.  I'm rendering the terrain geometry and water geometry separately and in different vertex buffers.   Currently I am using Raw Draw Calls which means that I am very wasteful on computational power.  
      Goal: Use Index buffers to reduce vertices by 80%, compress my index buffers and vertex buffers into one index buffer and vertex buffer.  I can't reduce the number of draw calls as its per leaf.
      Current: Static assets such as trees etc are bound to each leaf of my quad tree, as I traverse the tree to see whats in view/out of view, I trim the leaf which in turn trims all the static assets.  This means there is an instance buffer for each node AND for each mesh.  
      Goal: Compress the instance Buffers into one instance buffer per mesh (Ie, even if 10 meshes are in 1 vertex buffer, I need 10 instance buffers), for all meshes, compress the meshes into 1 index buffer and 1 vertex buffer.  I can not reduce the number of draw calls.
      Current: My unlimited sea function reuses the same tile mesh and just remaps with a constant buffer.  This means, if there are 10 tiles, there are 10 draw calls and 10 constant buffer updates.
      Goal: Simple, Use an instance buffer and remove the constant buffer updates (I was lazy and wanted to do this quick :)).  Reduces it to 1 draw call, 1 instance buffer bind and 1 vertex buffer bind.
      Current: Each shader, i'm rebinding the same constant buffers, these buffers only change at the start of a new scene (shadow AND rendered).  
      Goal: Create a map of buffers to be bound once per context, use consistent registers.   Combine wasteful buffer structures into 1 buffer.  Reduce number of constant changes.  More negligible for deferred contexts but still worth it.
      All these changes are not difficult as I have layered my graphics engine in such a way that it doesn't disturb the lower levels.  Ie. Instance management is not bound to mesh directly, mesh management allows for compression easily.    All static buffers are set immutable in my game, so vertex, index and most index buffers are immutable.
      So the questions: 
      - Are some or all changes worth it?  Or am I going to just suffer from draw calls?  
      - I am assuming at the moment that Setting vertex buffers, index buffers, instance buffers are part of the command buffer?  Is this correct, i'm looking to reduce the number of calls pushed through it.
      - I assume in a deferred context world, that constant buffers when set are not persistent across contexts when I execute command lists.
      - Lastly, should I look into Draw Indexed instanced indirect to accumulate draw calls?  And would I get any benefit from the GPU side doing this?
       
       
       
    • By BVAaron
      Hey guys!
      l'm a passionate and published writer looking to get my hands dirty in the game dev world, collab with some cool people, and make awesome games. Story arcs, character development, dialogue creation, text editing... you name it, l'm game.
      l'm perfectly happy doing hobby projects, but if people are getting something like rev-share, i will expect compensation as well
      EXPERlENCE:
      15+ years of writing experience. l've written & edited everything from fiction to journalism to content marketing and more. But mostly fiction.
      Many of my stories have been published. You can check out my style and see if l'd be a good fit here.
      OTHER SKlLLS:
      l've done a small bit of voice-acting and would love the chance to get more into it. l've been told on occasion that i have a "good voice for reading." GENRE STRENGTHS:
      Drama, horror, mystery, suspense (big Stephen King/SOMA/Prey fan) GAME GENRE:
      While l have my favorites, l'll be happy working with any genre. Looking forward to hearing from you guys!
      -Snarky
    • By darknight78
      I have a small team together to work on an open world adventure game but we are lacking specifically anyone to do with 3D modelling. The basic concept of the game is you play as a demigod who has seen mankind grow from the bottom, up. The Gods are unhappy with the humans because there is a worldwide war that is destroying Earth. They tell the humans they are angry, and they destroy the universe but keep the demigod alive to watch everything disappear. He wakes up in a world filled with fantasy, kind of like the elder scrolls. Here, he must protect the innocent people and fulfill his duty in a prophecy.
      If you have any interest in joining the team, even if you are not a 3D designer, please email me at 78darknight87@gmail.com.
      Thanks
       
    • By Zototh
      I am using slimDX and am having a problem with a shader. I have an instance Shader that works perfect but I needed one for drawing fonts manually. The idea is to create the plane and simple instance it with separate position color and texture coordinates for each char.  I know this post is terribly long but any help would be appreciated. I tried to provide everything needed but if you need more I will be glad to post it.
      This is the shader. the only difference between it and the working one is the instance texture coordinates. I was able to render 4,000 spheres with 30,000 faces with the original and still maintain a 100+ framerate. I don't know if that is a lot but it looked like it to me.
      cbuffer cbVSPerFrame:register(b0) { row_major matrix world; row_major matrix viewProj; }; Texture2D g_Tex; SamplerState g_Sampler; struct VSInstance { float4 Pos : POSITION; float3 Normal : NORMAL; float2 Texcoord : TEXCOORD0; float4 model_matrix0 : TEXCOORD1; float4 model_matrix1 : TEXCOORD2; float4 model_matrix2 : TEXCOORD3; float4 model_matrix3 : TEXCOORD4; // this is the only addition float2 instanceCoord:TEXCOORD5; float4 Color:COLOR; }; struct PSInput { float4 Pos : SV_Position; float3 Normal : NORMAL; float4 Color:COLOR; float2 Texcoord : TEXCOORD0; }; PSInput Instancing(VSInstance In) { PSInput Out; // construct the model matrix row_major float4x4 modelMatrix = { In.model_matrix0, In.model_matrix1, In.model_matrix2, In.model_matrix3 }; Out.Normal = mul(In.Normal, (row_major float3x3)modelMatrix); float4 WorldPos = mul(In.Pos, modelMatrix); Out.Pos = mul(WorldPos, viewProj); Out.Texcoord = In.instanceCoord; Out.Color = In.Color; return Out; } float4 PS(PSInput In) : SV_Target { return g_Tex.Sample(g_Sampler, In.Texcoord); } technique11 HWInstancing { pass P0 { SetGeometryShader(0); SetVertexShader(CompileShader(vs_4_0, Instancing())); SetPixelShader(CompileShader(ps_4_0, PS())); } } this is the input elements for the 2 buffers
      private static readonly InputElement[] TextInstance = { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("TEXCOORD", 1, Format.R32G32B32A32_Float, 0, 1, InputClassification.PerInstanceData, 1 ), new InputElement("TEXCOORD", 2, Format.R32G32B32A32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ), new InputElement("TEXCOORD", 3, Format.R32G32B32A32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ), new InputElement("TEXCOORD", 4, Format.R32G32B32A32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ), new InputElement("TEXCOORD", 5, Format.R32G32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ) }; the struct for holding instance data. 
      [StructLayout(LayoutKind.Sequential)] public struct InstancedText { public Matrix InstancePosition; public Vector2 InstanceCoords; public Color4 Color; }; instanceData buffer creation. Instance Positions is a simple List<InstancedText> above
      DataStream ds = new DataStream(InstancePositions.ToArray(), true, true); BufferDescription vbDesc = new BufferDescription(); vbDesc.BindFlags = BindFlags.VertexBuffer; vbDesc.CpuAccessFlags = CpuAccessFlags.None; vbDesc.OptionFlags = ResourceOptionFlags.None; vbDesc.Usage = ResourceUsage.Default; vbDesc.SizeInBytes = InstancePositions.Count * Marshal.SizeOf<InstancedText>(); vbDesc.StructureByteStride = Marshal.SizeOf<InstancedText>(); ds.Position = 0; instanceData = new Buffer(renderer.Device, vbDesc);  
      and finally the render code.
      the mesh is a model class that contains the plane's data. PositionNormalTexture is just a struct for those elements.
      renderer.Context.InputAssembler.InputLayout = new InputLayout(renderer.Device, effect.GetTechniqueByName("HWInstancing").GetPassByIndex(0).Description.Signature, TextInstance); renderer.Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; renderer.Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(mesh.VertexBuffer, Marshal.SizeOf<PositionNormalTexture>(), 0)); renderer.Context.InputAssembler.SetIndexBuffer(mesh.IndexBuffer, SlimDX.DXGI.Format.R32_UInt, 0); renderer.Context.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(instanceData, Marshal.SizeOf<InstancedText>(), 0)); effect.GetVariableByName("g_Tex").AsResource().SetResource(textures[fonts[name].Name]); EffectTechnique currentTechnique = effect.GetTechniqueByName("HWInstancing"); for (int pass = 0; pass < currentTechnique.Description.PassCount; ++pass) { EffectPass Pass = currentTechnique.GetPassByIndex(pass); System.Diagnostics.Debug.Assert(Pass.IsValid, "Invalid EffectPass"); Pass.Apply(renderer.Context); renderer.Context.DrawIndexedInstanced(mesh.IndexCount, InstancePositions.Count, 0, 0, 0); }; I have been over everything I can think of to find the problem but I can't seem to locate it.
      my best guess is the instance data buffer is wrong somehow since VS graphics debugger shows no output from vertex shader stage
       but I just can't see where.
  • Popular Now