0
\$\begingroup\$

Environment:

  • Windows 7 x64
  • Visual Studo 2012
  • DirextX11
  • HLSL Shader Model 5
  • Ogre 1.9

Okay, so I'm trying to sample a texture in my pixel shader but I'm coming across some strange problems. Here's the pixel shader:

struct PS_INPUT {
    float4 pos : SV_POSITION;
    float2 uv  : TEXCOORD0;
};

Texture2D tex0;
SamplerState s0;

float4 pixel_shader(PS_INPUT input) : SV_TARGET {
    float3 texSample = tex0.Sample(s0, input.uv);

    float4 color = float4(1,1,1,1);

    color.xyz = texSample;

    return color;
}

If you want / need it here's the ogre .material definition:

material simpleMat
{
    technique
    {
        pass simpleMat
        {
            vertex_program_ref vertex_shader {}
            fragment_program_ref pixel_shader {}
        }

        texture_unit 0
        {
            texture diffuse.png 2d
            tex_address_mode wrap
        }
    }
}

This produces mostly black on my object, but I get 2 random white pixels. But here's the strangest part. When I debug the pixel shader in visual studio texSample nearly always equals zero. So I decided to try something crazy, I debugged the program, got the value of input.uv and then modified the shader to use these values explicitly. When I do this texSample actually contains the correct color value. So yeah... any help is much appreciated!

Rojuinex

EDIT

Here is a snapshot that shows the issue in detail:

http://www.pasteall.org/pic/show.php?id=74835

EDIT 8/4/2014

Upon further investigation I have discovered that the further the object is from the camera, the darker the texture becomes. If the camera is right up against the object, the texture has the right color values, but as it moves away the sampler returns darker and darker values until they are black.

\$\endgroup\$
3
  • \$\begingroup\$ In PS_INPUT, are those actually floats? They should be float4 and float2 respectively. \$\endgroup\$ Aug 1, 2014 at 5:29
  • \$\begingroup\$ Yeah, that was a post typo. I've fixed it. I try to only post the parts of the source code that are relevant as to try and make the post fit a page. \$\endgroup\$
    – Rojuinex
    Aug 1, 2014 at 5:39
  • \$\begingroup\$ I usually find if this happens, I'm trying to sample from a mipmap level which hasn't been generated. \$\endgroup\$
    – GuyRT
    Aug 5, 2014 at 14:02

1 Answer 1

0
\$\begingroup\$

GuyRT is right. For some reason Ogre 1.9 + RenderSystemDX11 has problems generating the texture mipmap levels. I'm not sure the cause of this, but it is easily fixed by using Microsoft DirectX Texture Tool to generate the mip levels in the .dds

\$\endgroup\$

You must log in to answer this question.

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