1
\$\begingroup\$

Using sharpdx(directx 11) developing on UWP.

This is a link to a previous question of not being able to compile the shader files(written in hlsl) How to compile shader files in UWP Later I have found some method to avoid the original exception(unable to open or find shader files) but still the shaders seem not to be working.

My method to "avoid the original exception" is to change the file path to

System.IO.Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "ProjectName")

If the method works, I would surely post it as an answer to the previous question

The current problem is no display on the screen(all black), while I can check the stored data in the vertex buffer using graphic diagnostics tools built in visual studio. Vertex buffer works fine, it seems

Here is my code for the shaders, problem may be going from here because this is the first shader file I've written. Please have a look and discuss may things go wrong.

pixel shader file Pixel_PS.fx

struct VertexOut
{
    float4 PosH : SV_POSITION;
    float4 Color : COLOR;
};

float4 PS(VertexOut pin) : SV_Target
{
    return pin.Color;
}

vertes shader file Transf_VS.fx

cbuffer dataBuffer : register(b0)
{
    matrix ViewProjection;  
};

struct VertexIn
{
    float3 PosL : POSITION;
    float4 Color : COLOR;
};

struct VertexOut
{
    float4 PosH : SV_POSITION;
    float4 Color : COLOR;
};

VertexOut VS(VertexIn vin)
{
    VertexOut vout;
    // Transform to homogeneous clip space.
    vout.PosH = mul(float4(vin.PosL, 1.0f), ViewProjection);
    // Just pass vertex color into the pixel shader.
    vout.Color = vin.Color;
    return vout;
}

where I compiled them

byte[] vertexShaderByteCode = ShaderBytecode.CompileFromFile(this.path + "\\Transf_VS.fx", "VS", "vs_5_0");
                this.vertexShader = new D3D11.VertexShader(
                    device,
                    vertexShaderByteCode
                    );
                this.inputSignature = new ShaderSignature(vertexShaderByteCode);
                this.pixelShader = new D3D11.PixelShader(
                    device,
                    ShaderBytecode.CompileFromFile(this.path + "\\Pixel_PS.fx", "PS", "ps_5_0")
                    );

data structure definition

public struct ScatterVertex
    {
        SharpDX.Vector3 Position;
        SharpDX.Color4 Color;
    }

inputlayout initialization

this.inputLayout = new D3D11.InputLayout(
                    this.device,
                    inputSignature,
                    new SharpDX.Direct3D11.InputElement[]
                    {
                        new D3D11.InputElement(
                            "Position",
                            0,
                            SharpDX.DXGI.Format.R32G32B32_Float,
                            0
                            ),
                        new D3D11.InputElement(
                            "Color",
                            0,
                            SharpDX.DXGI.Format.R32G32B32A32_Float,//I'm not very sure whether or why I should use this option
                            0
                            )
                    }
                    );

Here's the projection matrix in the camera class, which is later sent to the constant buffer

private Matrix View { get { return Matrix.LookAtLH(this.Eye, this.Target, this.Up); } }
private Matrix Proj { get { return Matrix.PerspectiveFovLH(this.Fov, this.Aspect, this.Near, this.Far); } }
public Matrix WorldViewProject
        {
            get
            {
                Matrix wvp = (this.View * this.Proj);
                wvp.Transpose();
                return wvp;
            }
        }

If you need anything else to solve this, just let me know and I'll manage to get it. Thank you!

\$\endgroup\$
3
  • \$\begingroup\$ Unfortunately in graphics programming 'blank screen' can come about for any number of reasons. Where is the code where you update the ViewProjection value in your constant buffer? \$\endgroup\$ – Chuck Walbourn Nov 10 '16 at 6:09
  • \$\begingroup\$ It's a bit long, let me check it myself first \$\endgroup\$ – 王凯越 Kaiyue Wang Nov 10 '16 at 6:56
  • \$\begingroup\$ I've updated the answer \$\endgroup\$ – 王凯越 Kaiyue Wang Nov 10 '16 at 7:53
1
\$\begingroup\$

I made it!

It turns out the problem is not with the shader, but the Draw method. I missed setting the first parameter of draw in my code, which should be the primitives I am intending to draw.

Thanks to everyone in this discussion and that of the previous question, I will update the answer to the previous question in very short time.

\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.