
This page contains the C++ source for EnvironmentShader, one of the shader implementations built with the Sh metaprogramming language. The shader loads a six-face cubemap and uses it to shade geometry by reflecting the view direction off the surface normal, producing a mirror-like environment reflection.
The class follows the usual Sh shader pattern: an init() method that builds the vertex and fragment programs, an apply() method that binds them, and a vertex() method that pushes per-vertex attributes. The vertex program transforms normals and positions into eye space, while the fragment program samples the cubemap.
Six PNG images named left, right, top, bottom, back, and front are loaded from the envmaps/aniroom/ media directory and assembled into a ShTextureCube.
The fragment program computes reflect(normalize(normal), normalize(-posEye)) and uses the resulting direction to look up a color in the cubemap. The vertex program supplies the interpolated normal and eye-space position needed for that lookup.
It renders reflections of a surrounding cubemap environment onto a surface. The fragment program reflects the view direction about the surface normal and samples the cubemap with the result.
It loads six PNG faces — left, right, top, bottom, back, and front — from the envmaps/aniroom/ media directory and combines them into a cubemap texture.
The source uses ShTextureCube, ShTexture2D, ShImage, and the SH_BEGIN_VERTEX_PROGRAM / SH_BEGIN_FRAGMENT_PROGRAM blocks, along with shBindShader and pushSmAttrib / pushSmVertex.
Calling apply() binds the vertex and fragment programs, and vertex() pushes the normal, texture coordinates, and vertex position for each vertex.
The class is self-contained: it declares its programs in init(), binds them in apply(), and feeds attributes in vertex(), so it can be adapted by changing the cubemap source or the reflection expression.