1
\$\begingroup\$

I'm porting some OpenGL code to Direct X 11. I ended up with nothing being drawn on the screen. I reverted to a simple program, which I am writing about here.

I'm now trying to use the Graphics Tools in Visual Studio to diagnose a very simple "Hello Triangle" program. In my program, I am drawing simple geometry and using a basic shader. The shader just outputs a constant color.

float4 ps_main(VS_OUTPUT Input) : SV_TARGET
{
    return float4(0.2f, 0.2f, 0.2f, 1.0f);
}

However, the Output Merger shows nothing.

(LOOK CLOSELY) enter image description here

When I click on the output merger, I see a green alpha checkerboard.

enter image description here

What I would like to know ultimately, is what I'm doing wrong. (Why is the output merger basically blank?) Additionally, I'd like to learn some skill in reading outputs like this:

enter image description here

This is the contents of basic.hlsl

cbuffer cbTransform : register( b0 )
{
    matrix matWorldViewProj;
};

struct VS_INPUT
{
    float3 Position     : POSITION0;
    float2 TexCoord     : TEXCOORD0;
    float3 Normal       : NORMAL;
    float4 Color        : TEXCOORD1;
};

struct VS_OUTPUT
{
    float4 Position     : SV_POSITION;
    float2 TexCoord     : TEXCOORD0;    
    float3 Normal       : NORMAL;
    float4 Color        : COLOR0;
};

VS_OUTPUT vs_main( VS_INPUT Input )
{
    VS_OUTPUT Output;
    Output.Position = mul(float4(Input.Position,1), matWorldViewProj);
    Output.TexCoord = Input.TexCoord;
    Output.Normal = mul(Input.Normal, (float3x3)matWorldViewProj);
    Output.Color = Input.Color;
    return( Output );
}

float4 ps_main(VS_OUTPUT Input) : SV_TARGET
{
    return float4(0.2f, 0.2f, 0.2f, 1.0f);
}

Here's what matWorldViewProj looks like:

enter image description here

\$\endgroup\$
5
  • 1
    \$\begingroup\$ what's your vertex shader? looks like your vertices all disappear after the vertex shader. Have you not set SV_Position? What's your VS_OUTPUT and how do you fill it? \$\endgroup\$
    – Babis
    Commented Nov 27, 2014 at 8:10
  • \$\begingroup\$ Updated question with entire shader \$\endgroup\$
    – 101010
    Commented Nov 27, 2014 at 13:07
  • \$\begingroup\$ have you verified that your matWorldViewProj matrix is ok? I'd start from there. \$\endgroup\$
    – Babis
    Commented Nov 27, 2014 at 13:27
  • \$\begingroup\$ Updated with a picture of matWorldViewProj \$\endgroup\$
    – 101010
    Commented Nov 27, 2014 at 14:43
  • \$\begingroup\$ Updated with adjustments recommended by Babis \$\endgroup\$
    – 101010
    Commented Nov 27, 2014 at 15:04

1 Answer 1

0
\$\begingroup\$

Fix your matWorldViewProj. w values are NaN, so the transformation will fail miserably. The w column should be (0,0,0,1).

Also, you should be getting complaints at the following line:

Output.Position = mul(Input.Position, matWorldViewProj);

as you multiply a 4x4 matrix with a float3. Change it to:

Output.Position = mul(float4(Input.Position,1), matWorldViewProj);

and fix the w values in C++ code.

\$\endgroup\$
3
  • \$\begingroup\$ Still didn't work. I adjusted the HLSL code though. Thanks. The matWorldViewProj matrix is actually just set to the identity matrix in the C code all this time. When I fixed the HLSL code, the full identity matrix is coming across now. I updated the question with the new picture. \$\endgroup\$
    – 101010
    Commented Nov 27, 2014 at 14:58
  • \$\begingroup\$ So far so good, now I think the culprit might be the render target view. Is there any chance to see the C++ file? More importantly, if you run the program with debugging and you break just after the render, do you get any D3D related error message in the output window? \$\endgroup\$
    – Babis
    Commented Nov 27, 2014 at 15:18
  • \$\begingroup\$ No D3D related error messages. (I know what you mean -- I have the debugging layer turned on and I've used the messages thus far as I fumbled my way through the D3D API) Is there a way to private email one another for the code? \$\endgroup\$
    – 101010
    Commented Nov 27, 2014 at 15:27

Not the answer you're looking for? Browse other questions tagged .