Jump to content

  • Log In with Google      Sign In   
  • Create Account


Losing triangles between VertexShader and OutputMerger


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 rtclawson   Members   -  Reputation: 168

Like
0Likes
Like

Posted 25 January 2013 - 12:25 PM

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, 
                                                DeviceCreationFlags.Debug, 
                                                swapDesc, 
                                                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);
device.ImmediateContext.Rasterizer.SetViewports(viewport);
device.ImmediateContext.OutputMerger.SetTargets(renderTargetView);
//END

//GET EFFECT
file_stream = System.Reflection.Assembly.
                       GetExecutingAssembly().GetManifestResourceStream(FX_FILE))
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);
//END CREATE EFFECT


//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(), 
                           (float)_rand.NextDouble(), 
                           (float)_rand.NextDouble()));
vert.Add(new Vector3((float)_rand.NextDouble(), 
                           (float)_rand.NextDouble(), 
                           (float)_rand.NextDouble()));
vert.Add(new Vector3((float)_rand.NextDouble(), 
                           (float)_rand.NextDouble(), 
                           (float)_rand.NextDouble()));
        
//simplified for now to Matrix.Identity
effect.GetVariableByName("WorldViewProj").AsMatrix().SetMatrix(Matrix.Identity);
Vector4 foregroundColor;//this is set elsewhere
effect.GetVariableByName("ForeColor").AsVector().Set(foregroundColor);

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

DataStream stream = new DataStream(vert.Count * Marshal.SizeOf(Vector3), true, true);
stream.WriteRange(vert.ToArray());
stream.Position = 0;
var vertexBuffer = new SlimDX.Direct3D11.Buffer(device, 
                                                stream,
                                                _vertices.Count * Marshal.SizeOf(Vector3), 
                                                ResourceUsage.Default, 
                                                BindFlags.VertexBuffer, 
                                                CpuAccessFlags.None,
                                                ResourceOptionFlags.None,
                                                0);


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 RenderSceneVS( VS_INPUT In)
{
	VS_OUTPUT Output;
	Output.Position = mul(float4(In.Position,1), WorldViewProj);
	return Output;
}

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

PS_OUTPUT RenderScene2D( VS_OUTPUT In )
{
	PS_OUTPUT Output;
	Output.RGBColor = ForeColor;
	return Output;
}

//Techniques-------------------------------------------------------------------

technique11 RenderUber
{
	pass P
	{
		SetVertexShader( CompileShader( vs_4_0, RenderSceneVS() ) );
		SetPixelShader ( CompileShader( ps_4_0, RenderScene2D() ) );
	}
}

Edited by rtclawson, 25 January 2013 - 12:35 PM.


Sponsor:

#2 Mike.Popoloski   Crossbones+   -  Reputation: 2887

Like
1Likes
Like

Posted 25 January 2013 - 04:01 PM

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.


Mike Popoloski | Journal | SlimDX

#3 rtclawson   Members   -  Reputation: 168

Like
0Likes
Like

Posted 28 January 2013 - 09:39 AM

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?



#4 rtclawson   Members   -  Reputation: 168

Like
0Likes
Like

Posted 29 January 2013 - 11:56 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS