Simple question,
if I wanted to access a structured buffer ( 1D Array, count of screen_width*screen_height ) as a 2d buffer, what I'd do is the following:
int index = y * screen_width + x;
So in this case, it's a compute shader filling out the buffer, and the shader is given the local thread id ( id.xy ranges from 0 to the screen dimensions ): [ PS. Dispatch is called by Dispatch(screen_width/32, screen_height/32, 1)
[numthreads(32, 32, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
...
int i = DTid.y * Screen.x + DTid.x;
bOutput[i] = gb;
}
Now I hope I filled the buffer correctly, now the next thing is accessing the buffer in a pixel shader, using the texture coordinates ( screen space ), like so: [ PS. The texture coordinates .xy ranges from 0 to 1, it's a full screen quad ]
int index = (input.Tex.y*Screen.y) * Screen.x + (input.Tex.x*Screen.x);
So in this case wouldn't I just need to multiply the texture coordinates by the screen dimensions, and do the same as before?:
float4 PShader(VS_Output input) : SV_TARGET
{
....
int x = input.Tex.x*Screen.x;
int y = input.Tex.y*Screen.y;
int i = y * Screen.x + x;
return bGBuffer[i].positionWS;
So I know the reading and writing is working, got that tested, but the indexing is failing, and I'm currently receiving a fully black screen. ( I.e. nothing ).
Thanks for your time!
Anyone know what I've done wrong this time?
-MIGU0027