Jump to content
  • Advertisement
Sign in to follow this  

Losing triangles between VertexShader and OutputMerger

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

I have successfully created a window and cleared the screen, but I am having trouble taking the next step and drawing a triangle. When I run in the Visual Studio 2012 graphics debugger and view the rendering pipeline, it appears that the triangle is fine in the Input Assembler and Vertex Shader, but by the OutputMerger window it is gone.


I am running with Native symbols and the DirectX SDK, but I'm not getting any errors or warnings. I flattened out my code into one contiguous segment, posted below. The effect fx file is included as well.


Any ideas what may be going wrong?


edit: I forgot to mention that I resize the window to make it re-render many times, and triangles never appear. It is not a matter of culling triangles.


Device device;
SwapChain swapChain;
RenderTargetView renderTargetView;
Effect effect;
//This is the window's Hwnd
Control control = Control.FromHandle(Hwnd);

//BEGIN: Init
SlimDX.DXGI.SwapChainDescription swapDesc = new SlimDX.DXGI.SwapChainDescription
    BufferCount = 1,
    Flags = SlimDX.DXGI.SwapChainFlags.AllowModeSwitch,
    IsWindowed = true,
    ModeDescription = new SlimDX.DXGI.ModeDescription(0, 0,
            new SlimDX.Rational(60, 1), SlimDX.DXGI.Format.R8G8B8A8_UNorm),
    OutputHandle = Hwnd,
    SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
    SwapEffect = SlimDX.DXGI.SwapEffect.Discard,
    Usage = SlimDX.DXGI.Usage.RenderTargetOutput

SlimDX.Result res = Device.CreateWithSwapChain(DriverType.Hardware, 
                                                out device, 
                                                out swapChain);
using (var resource = Resource.FromSwapChain<SlimDX.Direct3D11.Texture2D>(swapChain, 0))
    renderTargetView = new RenderTargetView(device, resource);
var viewport = new SlimDX.Direct3D11.Viewport(0, 0, 
                            control.ClientRectangle.Width, control.ClientRectangle.Height);

file_stream = System.Reflection.Assembly.
byte[] buffer;
buffer = new byte[file_stream.Length];
file_stream.Read(buffer, 0, buffer.Length);

SlimDX.DataStream ds = new SlimDX.DataStream(buffer.Length, true, true);
ds.Write(buffer, 0, buffer.Length);
ds.Position = 0;
ShaderBytecode bc = new ShaderBytecode(ds);
bc = ShaderBytecode.Compile(buffer, "fx_5_0");

effect = new SlimDX.Direct3D11.Effect(device, bc);

//BEGIN: All the following is called on render

//color is set elsewhere to random values. Trippy, but just for debugging
SlimDX.Color4 slimColor = new SlimDX.Color4(color.ToArgb());
device.ImmediateContext.ClearRenderTargetView(renderTargetView, slimColor);

List<Vector3> vert;
//Set to random for debugging purposes. Random values are between 0-1
vert.Add(new Vector3((float)_rand.NextDouble(), 
vert.Add(new Vector3((float)_rand.NextDouble(), 
vert.Add(new Vector3((float)_rand.NextDouble(), 
//simplified for now to Matrix.Identity
Vector4 foregroundColor;//this is set elsewhere

EffectTechnique tech = effect.GetTechniqueByName("RenderUber");
EffectPass pass = tech.GetPassByIndex(0);
_renderer.Signature = effect.GetTechniqueByName("RenderUber").GetPassByIndex									(0).Description.Signature;

DataStream stream = new DataStream(vert.Count * Marshal.SizeOf(Vector3), true, true);
stream.Position = 0;
var vertexBuffer = new SlimDX.Direct3D11.Buffer(device, 
                                                _vertices.Count * Marshal.SizeOf(Vector3), 

var elements = new[] { new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0)};
var sig = effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature;
var layout = new InputLayout(device, sig, elements);

context.InputAssembler.InputLayout = layout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Marshal.SizeOf(Vector3), 0));
context.Draw(vertexCount, 0); //vertexCount is 3 here

_swapChain.Present(0, SlimDX.DXGI.PresentFlags.None);

// File: EffectSimple.fx
// save with encoding: Western European (Windows)- Codepage 1252

//Global variables-------------------------------------------------------------

float4x4 WorldViewProj;
float4 ForeColor;

//Input Output Structures------------------------------------------------------
struct VS_INPUT
	float3 Position   : POSITION;   // vertex position 

struct VS_OUTPUT
	float4 Position   : SV_POSITION;   // vertex position 

struct PS_OUTPUT
	float4 RGBColor : SV_TARGET0;  // Pixel color	

//Vertex Shaders---------------------------------------------------------------

	VS_OUTPUT Output;
	Output.Position = mul(float4(In.Position,1), WorldViewProj);
	return Output;

//Pixel Shaders----------------------------------------------------------------

	PS_OUTPUT Output;
	Output.RGBColor = ForeColor;
	return Output;


technique11 RenderUber
	pass P
		SetVertexShader( CompileShader( vs_4_0, RenderSceneVS() ) );
		SetPixelShader ( CompileShader( ps_4_0, RenderScene2D() ) );
Edited by rtclawson

Share this post

Link to post
Share on other sites

Are you sure culling isn't an issue? It seems very likely to me that since you're randomizing your vertices, that they will often be facing away from the camera and as such will get backface culled. I don't see you setting a rasterizer state anywhere, so I have to assume you're using the defaults, which do indeed cull backfaces.

Share this post

Link to post
Share on other sites

Unfortunately, culling was not the issue. This is what I used to make sure that culling was not the problem.


RasterizerStateDescription description = new RasterizerStateDescription


CullMode = CullMode.None,

FillMode = SlimDX.Direct3D11.FillMode.Solid,


RasterizerState rs = RasterizerState.FromDescription(_device, description);

_device.ImmediateContext.Rasterizer.State = rs;


Any other ideas?

Share this post

Link to post
Share on other sites

I found the issue. The code I posted I had pulled from various parts of my framework. As it turns out, in my framework, I was creating a new RenderTargetView every frame. Sheesh...

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.

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!