So i recently moved from XNA to SharpDX Toolkit and started with some basics. The 2d part was easy since nearly nothing has changed but im really struggeling with the 3d part. For example i wanted to render a heightmap based on riemers terrain tutorial however came along the following issue:

I have a little map (or terrain) class that contains the index and vertex arrays as buffer like so:

private SharpDX.Toolkit.Graphics.Buffer<VertexPositionNormalTexture> _mesh;
private SharpDX.Toolkit.Graphics.Buffer _indexBuffer;
private readonly static VertexInputLayout InputLayout = VertexInputLayout.New<VertexPositionNormalTexture>(0); // copied from the basic geometry

this get filled in propertly and render fine with VertexPositionColor. rendered the common XNA way:

//set effect parameters and resources
foreach (EffectPass pass in _effect.CurrentTechnique.Passes) {


    Globals.DefaultGraphicsDevice.SetVertexBuffer(0, _mesh);

    // Setup the Vertex Buffer Input layout

    // Setup the index Buffer
    Globals.DefaultGraphicsDevice.SetIndexBuffer(_indexBuffer, true);

    // Finally Draw this mesh
    Globals.DefaultGraphicsDevice.DrawIndexed(PrimitiveType.TriangleList, _indexBuffer.ElementCount);

Now with my own half converted half remade shader i get

a) a black terrain or

b) HRESULT: [0x80070057] (wrong parameter)

and i cant figure out why (most likely since i never done much with 3d shaders)

the shader:

struct VertexShaderInput {
    float4 Position     : SV_Position;
    float3 Normal       : NORMAL;
    float2 TextureCoords: TEXCOORD0;

struct VertexShaderOutput {
    float4 Position     : SV_Position;
    //float4 VPosition      : SV_Position; //im not used to SV_Position and SV_Target so this could be the main problem
    float LightingFactor: TEXCOORD0;
    float2 TextureCoords: TEXCOORD1;

struct PixelShaderOutput {
    float4 Color        : SV_Target;

//------- Constants --------
float4x4 xView;
float4x4 xProjection;
float4x4 xWorld;
float3 xLightDirection;
float xAmbient;

Texture2D xTexture;
sampler TextureSampler = sampler_state {
    texture = <xTexture>;
    magfilter = LINEAR;
    minfilter = LINEAR;
    mipfilter = LINEAR;
    AddressU = mirror;
    AddressV = mirror;

VertexShaderOutput TexturedVS(VertexShaderInput VSin) {
    VertexShaderOutput Output = (VertexShaderOutput)0;
    float4x4 preViewProjection = mul(xView, xProjection);
    float4x4 preWorldViewProjection = mul(xWorld, preViewProjection);

    Output.Position = mul(VSin.Position, preWorldViewProjection);
    Output.TextureCoords = VSin.TextureCoords;

    float3 Normal = normalize(mul(normalize(VSin.Normal), xWorld));
    Output.LightingFactor = dot(Normal, -xLightDirection);

    return Output;    

PixelShaderOutput TexturedPS(VertexShaderOutput PSIn) {
    PixelShaderOutput Output = (PixelShaderOutput)0;

    Output.Color = xTexture.Sample(TextureSampler, PSIn.TextureCoords);
    Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;

    return Output;

technique Textured {
    pass p0 {
        Profile = 9.1;
        AlphaBlendEnable = false;
        CullMode = None;
        PixelShader = TexturedPS;
        VertexShader = TexturedVS;

im thankfull for any help

(Disclaimer: i moved this from stackoverflow to here since i think it was missplaced and didn't got any attention)

  • \$\begingroup\$ This question appears to be off-topic because it is about debugging your code for you. \$\endgroup\$
    – user1430
    Jan 15, 2014 at 18:05
  • \$\begingroup\$ it was more something like "im new, do you see anything terrible wrong with it on the first view". also i solved this problem now but need to wait to accept my answer :) \$\endgroup\$
    – HellGate
    Jan 15, 2014 at 18:35
  • \$\begingroup\$ I know; it's still effectively the same issue though. There's a list of places in the help center that would be more appropriate to ask this kind of question (near the bottom). \$\endgroup\$
    – user1430
    Jan 15, 2014 at 18:58
  • \$\begingroup\$ ok i'll try to be more accurate and more specific with my next questions not just like "something does not work please help" \$\endgroup\$
    – HellGate
    Jan 16, 2014 at 9:05

1 Answer 1


I was so close to the result when i posted this question... all i had to do is fix the texture warping and scale the texture coordinates down since it was drawing way too detailed. the black map was caused by a 1px black border on the texture and the clamping of the texture sampler. now its working nearly as it should. only the AddressU = wrap; does not want to work right now.


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