From 823a9dade6e36760a827aae6ac841b8c582a7935 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 18 Feb 2019 09:00:39 +0100 Subject: Use same population indexing in collide and stream Increases consistency and should help to avoid confusion --- src/shader/code/collide.glsl | 2 +- src/shader/code/stream.glsl | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl index 3510c4e..23e98f9 100644 --- a/src/shader/code/collide.glsl +++ b/src/shader/code/collide.glsl @@ -44,7 +44,7 @@ float norm(vec2 v) { /// Array indexing uint indexOfDirection(int i, int j) { - return 3*(j+1) + (i+1); + return 3*(i+1) + (j+1); } uint indexOfLatticeCell(uint x, uint y) { diff --git a/src/shader/code/stream.glsl b/src/shader/code/stream.glsl index 9b77c85..1a2abe3 100644 --- a/src/shader/code/stream.glsl +++ b/src/shader/code/stream.glsl @@ -13,14 +13,24 @@ uniform uint nY; const uint q = 9; +// Array indexing + +uint indexOfDirection(int i, int j) { + return 3*(i+1) + (j+1); +} + +uint indexOfLatticeCell(uint x, uint y) { + return q*nX*y + q*x; +} + /// Data access float get(uint x, uint y, int i, int j) { - return collideCells[q*nX*y + q*x + (i+1)*3 + j+1]; + return collideCells[indexOfLatticeCell(x,y) + indexOfDirection(i,j)]; } void set(uint x, uint y, int i, int j, float v) { - streamCells[q*nX*y + q*x + (i+1)*3 + j+1] = v; + streamCells[indexOfLatticeCell(x,y) + indexOfDirection(i,j)] = v; } /// Actual stream kernel -- cgit v1.2.3