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
// GLSL Octahedral Texture Mapping with Edge Mirroring and Bilinear Interpolation (by Benjamin 'BeRo' Rosseaux) | |
ivec2 wrapOctahedralTexelCoordinates(const in ivec2 texel, const in ivec2 texSize) { | |
ivec2 wrapped = ((texel % texSize) + texSize) % texSize; | |
return ((((abs(texel.x / texSize.x) + int(texel.x < 0)) ^ (abs(texel.y / texSize.y) + int(texel.y < 0))) & 1) != 0) ? (texSize - (wrapped + ivec2(1))) : wrapped; | |
} | |
vec4 textureOctahedralMap(const in sampler2D tex, vec3 direction) { | |
direction = normalize(direction); // just for to make sure that it is normalized | |
vec2 uv = direction.xy / (abs(direction.x) + abs(direction.y) + abs(direction.z)); |