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.
PS_INPUT
, are those actually floats? They should befloat4
andfloat2
respectively. \$\endgroup\$