Quantcast
Channel: Question and Answer » hlsl
Viewing all articles
Browse latest Browse all 69

Sample() returns (0, 0, 0) for normal map 90% of frames

$
0
0

I’m having some trouble reading the values from my Normal map in my lighting fragment shader.

The relevant part of the shader code is as follows:

Texture2D NormalGB : register(t0);
Texture2D DiffuseGB : register(t1);
Texture2D SpecularGB : register(t2);
Texture2D PositionGB : register(t3);

SamplerState NormalSampler : register(s0);

void GetGBValues(
    in int2 screenPosition,
    out float3 normal,
    out float3 diffuseAlbedo,
    out float3 specularAlbedo,
    out float specularPower,
    out float3 position)
{

    int3 screenPos3 = int3(screenPosition, 0);
    normal = normalize(NormalGB.Sample(NormalSampler, screenPosition).xyz); // HERE
    diffuseAlbedo = DiffuseGB.Load(screenPos3).xyz;
    float4 specularValues = SpecularGB.Load(screenPos3);
    specularAlbedo = specularValues.xyz;
    specularPower = specularValues.w * 50.0f;
    position = PositionGB.Load(screenPos3).xyz;
}

However, in 9 frames out of 10, normal is set to {0. 0, 0}. I’ve tried the code under the reference driver too, and get the same issue.

What’s really weird is that if I change the line marked // HERE to a simple .Load call, the code works perfectly (except the obvious fact that I get no interpolation of normals). The sampler that is bound at time of the draw call (according to the graphics debugger) is:

D3D11 Sampler State (obj:18)
AddressU D3D11_TEXTURE_ADDRESS_WRAP 
AddressV D3D11_TEXTURE_ADDRESS_WRAP 
AddressW D3D11_TEXTURE_ADDRESS_WRAP 
BorderColor (0.000f, 0.000f, 0.000f, 0.000f) 
ComparisonFunc D3D11_COMPARISON_NEVER 
Filter D3D11_FILTER_ANISOTROPIC 
MaxAnisotropy 4 
MaxLOD 340282346638528860000000000000000000000.000f 
MinLOD 0.000f 
MipLODBias 0.000f 

Device obj:3 

And finally, the normal-map (rendered to a texture by the previous pass):

enter image description here


Viewing all articles
Browse latest Browse all 69

Trending Articles