Sign in to follow this  
StanIAm

Sample VPLs in Compute Shader

Recommended Posts

Hey guys I have a little blackout right now and I don't know why my code doesn't work. I try to optimize some GI stuff with Reflective Shadow Mapping with Computeshader and lowres filtering. In the first stage a computeshader samples the RSM and create a structured buffer with virtual point lights with the color,position and normal of the VPL. This is done by using 32 * 32 samples with 32 * 32 threads. But it seems in the result, that only the first row on the top of the image is captured and the other not....well this is the problem.

 

Here is the VPL code:


SamplerState samplerType : register( s0 );
Texture2D RSMColor : register( t4 );
Texture2D RSMNormal : register( t5 );
Texture2D RSMPosition : register( t6 );

struct VPL {
   float4 color;
   float4 normal;
   float4 position;
};

RWStructuredBuffer<VPL> VPLBuffer : register(u0);


#define NUM_X 32
#define NUM_Y 32


[numthreads(NUM_X,NUM_Y,1)]

void CSMain(uint3 threadID : SV_GroupThreadID)
{
    VPL tmp;
    float2 texcoord;
    
    texcoord = float2(threadID.xy / 32.0f);
    tmp.color = RSMColor.SampleLevel(samplerType,texcoord,0);
    tmp.position = RSMPosition.SampleLevel(samplerType,texcoord,0);
    tmp.normal = RSMNormal.SampleLevel(samplerType,texcoord,0) ; 
    VPLBuffer[threadID.y * 32 + threadID.x] = tmp;
}

As you can see the VPLBuffer is filled with the VPL which is sampled using the threadID. The index is made of the two ids and the rowsize. My first idea was, that maybe I can't write to the VPLBuffer in a random order ( for example index 0 then index 10.....) but I'am not sure.

Thank you

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this