Skip to content

Instantly share code, notes, and snippets.

@robertleeplummerjr
Created April 19, 2019 09:17
Show Gist options
  • Save robertleeplummerjr/82ef334688bf88d6087c15d576520c2b to your computer and use it in GitHub Desktop.
Save robertleeplummerjr/82ef334688bf88d6087c15d576520c2b to your computer and use it in GitHub Desktop.
float getMemoryOptimized32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {
ivec3 xyz = ivec3(x, y, z);
__GET_WRAPAROUND__;
int index = xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z);
int channel = integerMod(index, 4);
index = index / 4;
int w = texSize.x;
vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;
vec4 texel = texture2D(tex, st / vec2(texSize));
if (channel == 0) return texel.r;
if (channel == 1) return texel.g;
if (channel == 2) return texel.b;
if (channel == 3) return texel.a;
return 0.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment