Created
April 19, 2019 09:17
-
-
Save robertleeplummerjr/82ef334688bf88d6087c15d576520c2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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