Jump to content

  • Log In with Google      Sign In   
  • Create Account

[D3D11] My quad won't draw.. not sure why


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
4 replies to this topic

#1 jdub   Members   -  Reputation: 420

Like
0Likes
Like

Posted 18 February 2013 - 09:34 PM

I am trying to draw a simple textured, 2D bitmap on the screen.  Looking at it through PIX, the quad makes it through the vertex and pixel shader stages but doesn't end up drawn on the final window.  I thought it might be that I hadn't hooked in a render target, but I have.  I modified the code for the pixel shader to just draw the quad with one solid color because I thought that maybe it had something to do with my texture loading/passing to the shader.  Now, I'm not really sure what else could be going on here.

 

Here's the shader code:

 

/////////////////////////////////////////////////
// GLOBALS
/////////////////////////////////////////////////
SamplerState SampleType;
Texture2D Texture;

cbuffer WorldBuffer
{
	matrix World;	
};

cbuffer ProjectionBuffer
{
	matrix Projection;
};

cbuffer ViewBuffer
{
	matrix View;
};

cbuffer LightConstantBuffer
{
	float3 LightDir;
	float4 LightColor;
	float padding;
};

struct VS_INPUT
{
	float4 Position : POSITION;
	float2 TexCoord : TEXCOORD0;
	float3 Normal : NORMAL; //world space normal
};

struct PS_INPUT
{
	float4 Position : SV_POSITION;
	float2 TexCoord : TEXCOORD0;
	float3 Normal : NORMAL; //view-space normal
};

PS_INPUT VShader(VS_INPUT input) 
{
	PS_INPUT output = (PS_INPUT)0;
	
	input.Position.w = 1.0f;

	output.Position = input.Position;
	output.TexCoord = input.TexCoord;	
	
	return output;
}

float4 PShader(PS_INPUT input) : SV_TARGET
{
	return float4(1.0f,1.0f,.5f,1.0f);
} 


Here's my initiallization code for directX:

public D3DPipeline(RenderForm renderForm)
        {
            SwapChainDescription swapChainDescription = new SwapChainDescription()
            {
                BufferCount = 1,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = renderForm.Handle,
                IsWindowed = true,
                ModeDescription = new ModeDescription(1600, 900, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard
            };

            SlimDX.Direct3D11.Device device;
            Result result = SlimDX.Direct3D11.Device.CreateWithSwapChain(
                DriverType.Hardware,
                DeviceCreationFlags.Debug,
                new FeatureLevel[] { FeatureLevel.Level_11_0 },
                swapChainDescription,
                out device,
                out this.swapChain);

            this.Device = device;

            if (!result.IsSuccess)
            {
                throw new Exception();
            }

            if (!this.Device.Factory.SetWindowAssociation(renderForm.Handle, WindowAssociationFlags.None).IsSuccess)
            {
                throw new Exception();
            }

            this.Context = Device.ImmediateContext;
            this.viewport = new Viewport(0.0f, 0.0f, 1600, 900, 0.0f, 1.0f);

            Resource11 renderTargetTexture = Resource11.FromSwapChain<Texture2D>(this.swapChain, 0);
            this.renderTargetView = new RenderTargetView(this.Device, renderTargetTexture);
            this.Context.OutputMerger.SetTargets(this.renderTargetView);

            this.Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            SamplerDescription sampleDescr = new SamplerDescription();
            sampleDescr.Filter = Filter.MinMagMipLinear;
            sampleDescr.AddressU = TextureAddressMode.Wrap;
            sampleDescr.AddressV = TextureAddressMode.Wrap;
            sampleDescr.AddressW = TextureAddressMode.Wrap;
            sampleDescr.MipLodBias = 0.0f;
            sampleDescr.MaximumAnisotropy = 1;
            sampleDescr.ComparisonFunction = Comparison.Always;
            sampleDescr.BorderColor = Color.White;
            sampleDescr.MinimumLod = 0;
            sampleDescr.MaximumLod = float.MaxValue;

            this.samplerState = SamplerState.FromDescription(this.Device, sampleDescr);

            this.Context.PixelShader.SetSampler(this.samplerState, 0);

            this.Context.Rasterizer.SetViewports(new Viewport{ 
                Height = renderForm.Height,
                Width = renderForm.Width,
                MaxZ = 1.0f,
                MinZ = 0.0f,
                X = 0.0f,
                Y = 0.0f
            });

            Vector3 viewPos = new Vector3(0.0f, 5.0f, 0.0f);
            Vector3 viewTarget = new Vector3(2.0f, 5.0f, 2.0f);
            Vector3 viewUp = new Vector3(0.0f, 1.0f, 0.0f);

            this.view = Matrix.LookAtLH(viewPos, viewTarget, viewUp);
            this.setView(view);

            this.projection = Matrix.PerspectiveFovLH(0.523598776f, 1600 / 900, 1.0f, 1000.0f);
            this.setProjection(projection);
            
            //set the rasterizer
            RasterizerStateDescription newStateDescr = new RasterizerStateDescription();
            newStateDescr.CullMode = CullMode.None;
            newStateDescr.FillMode = FillMode.Solid;
            
            RasterizerState newState = RasterizerState.FromDescription(this.Device, newStateDescr);
            this.Context.Rasterizer.State = newState;
        }

public void InitShaders(ShaderBytecode vShaderBytecode, ShaderBytecode pShaderBytecode)
        {
            this.vShader = new VertexShader(this.Device, vShaderBytecode);
            this.pShader = new PixelShader(this.Device, pShaderBytecode);

            this.Context.PixelShader.Set(pShader);
            this.Context.VertexShader.Set(vShader);

            InputElement[] inputElements = 
            { 
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0), 
                new InputElement("TEXCOORD", 0, Format.R32G32_Float,0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 0) 
            };

            this.Context.InputAssembler.InputLayout = new InputLayout(this.Device, ShaderSignature.GetInputSignature(vShaderBytecode), inputElements);
        } 

Here's the relevant rendering code:

            context.PixelShader.SetShaderResource(this.textureRsrcView, 0);

            context.InputAssembler.SetVertexBuffers(0, this.vBufferBinding);
            context.InputAssembler.SetIndexBuffer(this.iBuffer, SlimDX.DXGI.Format.R16_UInt, 0);
            context.DrawIndexed(6, 0, 0); 

Sorry guys.  I know it's a lot of code but I'm stumped here and could really appreciate some help.

 

THanks!

 


J.W.

Sponsor:

#2 qorthos   Members   -  Reputation: 165

Like
0Likes
Like

Posted 18 February 2013 - 09:41 PM

Try turning off backface culling in the rasterizer in case you're winding the vertices of your quad backwards.

 

            var rsd = new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                DepthBias = 0,
                DepthBiasClamp = 0.0f,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled = false,
                IsFrontCounterclockwise = false,
                IsMultisampleEnabled = true,
                IsScissorEnabled = false,
                SlopeScaledDepthBias = 0.0f
            };

            RasterizerState rs = RasterizerState.FromDescription(device, rsd);
            context.Rasterizer.State = rs;


#3 jdub   Members   -  Reputation: 420

Like
0Likes
Like

Posted 18 February 2013 - 10:24 PM

Don't I do that with this line?

 

RasterizerStateDescription newStateDescr = new RasterizerStateDescription();
            newStateDescr.CullMode = CullMode.None;
            newStateDescr.FillMode = FillMode.Solid;

J.W.

#4 qorthos   Members   -  Reputation: 165

Like
0Likes
Like

Posted 18 February 2013 - 10:35 PM

Don't I do that with this line?

 

RasterizerStateDescription newStateDescr = new RasterizerStateDescription();
            newStateDescr.CullMode = CullMode.None;
            newStateDescr.FillMode = FillMode.Solid;

 

Doh, I didn't see that in your code.



#5 hossainiir   Members   -  Reputation: 1030

Like
0Likes
Like

Posted 19 February 2013 - 12:08 AM

Try to set the z element of each quad vertex  to 0.1f or higher instead of 0.

I had same problem with ati graphic card and this solution worked for me.

smile.png


خلیج تا ابد فارس

Persian Gulf





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