2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

texture3d.frag 1.21 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
3
4
5
6
7
8
9
10
11
12
// TODO: implement coordinate transformation using a trafo matrix?

struct Texture3D {
    // The texture
    sampler3D _texture;

    // Texture size
    vec3 _size;
    vec3 _sizeRCP;
};

/**
schultezub's avatar
schultezub committed
13
 * Texture lookup function for 3D textures using voxel coordinates, i.e [(0,0) , textureSize].
schultezub's avatar
schultezub committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 * \param	tex			Texture3D struct with texture for lookup
 * \param	texCoords	Lookup coordinates in pixel coordinates
 * \return	The texel at the given coordinates.
 */
vec4 getElement3D(in Texture3D tex, in vec3 texCoords) {
    vec3 texCoordsNormalized = texCoords * tex._sizeRCP;
    //vec2 texCoordsTransformed = (texParams.matrix_ * vec4(texCoordsNormalized, 0.0, 1.0)).xy;
    return texture3D(tex._texture, texCoordsNormalized);
}

/**
 * Texture lookup function for 3D textures using normalized texture coordinates, i.e. [0,1].
 * \param	tex			Texture3D struct with texture for lookup
 * \param	texCoords	Lookup coordinates in normlized texture coordinates
 * \return	The texel at the given coordinates.
 */
vec4 getElement3DNormalized(in Texture3D tex, in vec3 texCoords) {
    //vec2 texCoordsTransformed = (texParams.matrix_ * vec4(texCoords, 0.0, 1.0)).xy;
    return texture3D(tex._texture, texCoords);
}