Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to sample a image in the compute shader.

My code is

    [numthreads(1, N, 1)]
void VertBlurCS(int3 groupThreadID : SV_GroupThreadID,
                int3 dispatchThreadID : SV_DispatchThreadID)
{

    float4 test = gDiffuseMap.SampleLevel(samAnisotropic,0,0);
    gOutput[dispatchThreadID.xy] = test;
}

I'm getting one solid color.

What is wrong with my code?

share|improve this question
    
I think compute shaders are fundamentally broken / don't behave how we would expect ... gamedev.stackexchange.com/questions/116323/… – War Feb 9 '16 at 23:01
    
The input params are uint3 I believe what are the other variable types? – War Feb 9 '16 at 23:05
1  
@Wardy No, select isn't broken. Don't bring your overly verbose and floundering discussion into other questions. – Lars Viklund Feb 10 '16 at 12:21
    
What type is gDiffuseMap and is it properly bound according to a graphics debugger? Does the debug runtime for Direct3D give you any diagnostics? – Lars Viklund Feb 10 '16 at 12:23
1  
@Wardy I was referring to the hopefully well known section in The Pragmatic Programmer that bears that title. See this article on CodingHorror for a summary. Blaming upstream functionality more often than not just results in the blamer looking silly. – Lars Viklund Feb 10 '16 at 12:51

You are sampling from the same location on the texture for every output, therefore the output is a single colour.

See the documentation for SampleLevel

A fix would look something like this:

float2 uv = float2(dispatchThreadID.xy) / float2(textureWidthHeight); float4 test = gDiffuseMap.SampleLevel( samAnisotropic, uv, 0 );

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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