UNPKG

pex-renderer

Version:

Physically Based Renderer for Pex

22 lines (19 loc) 976 B
/** * Samples equirectangular (lat/long) panorama environment map * @param {sampler2D} envMap - equirectangular (lat/long) panorama texture * @param {vec3} wcNormal - normal in the world coordinate space * @param {float} - flipEnvMap [disabled] -1.0 for left handed coorinate system oriented texture (usual case) * 1.0 for right handed coorinate system oriented texture * @return {vec2} equirectangular texture coordinate- * @description Based on http://http.developer.nvidia.com/GPUGems/gpugems_ch17.html and http://gl.ict.usc.edu/Data/HighResProbes/ */ module.exports = /* glsl */ ` vec2 envMapEquirect(vec3 wcNormal) { float flipEnvMap = -1.0; // I assume envMap texture has been flipped the WebGL way (pixel 0,0 is a the bottom) // therefore we flip wcNorma.y as acos(1) = 0 float phi = acos(-wcNormal.y); float theta = atan(wcNormal.x, flipEnvMap * wcNormal.z) + PI; return vec2(theta / TWO_PI, phi / PI); } `