GLSL built-in function

textureCube()

Samples a cube map using a 3D direction.

Demo version: GLSL ES 1.00 / WebGL 1Demo stage: Fragment

Syntax

vec4 textureCube(samplerCube sampler, vec3 direction)

Parameters

sampler
Bound fixture texture
direction
Input declared in the signature; match its type and dimensions

Return value

A vec4 sampled from the cube face selected by the dominant direction component, at that direction's face coordinates.

Live example

Edit the code and the preview updates as you type.

What textureCube does

Samples a cube map using a 3D direction.

Read the preview

normalize(vec3(x,y,0.7)) points the middle of the preview toward the cube's +Z face. Set 0.7 to 2.0 so +Z dominates every visible direction and fills the canvas.

Core call

textureCube(u_cube,normalize(vec3(x,y,0.7))).rgb;

The input is a direction, not a 2D UV. The six fixture faces carry direction labels.

Experiment

Change the direction to normalize(vec3(x,y,-0.7)). The central face switches from +Z to -Z, identified by its different generated label and background color.

Specification

GLSL ES 1.00 built-in functions, chapter 8

Related functions