跳到主要内容
← Math

Math

Equirectangular texture

具体公式可以回去看 https://shader-learning.com/module-training/built-in-functions/task/equirectangular-texture

实时渲染 · 网格 GLSL

第 17 课:Equirectangular texture

我的解:具体公式可以回去看 https://shader-learning.com/module-training/built-in-functions/task/equirectangular-texture

我的解

uniform vec2 iResolution;
uniform sampler2D iChannel0;

const float PI = 3.14;

varying vec3 vPos;

void main() {
  vec2 uv = gl_FragCoord.xy / iResolution.xy;

  float theta_xz = atan(vPos.x, vPos.z);
  float u = (theta_xz+PI)/(2.0*PI);

  float theta_y = asin(vPos.y);
  float v = (theta_y+PI/2.0)/(PI);

  gl_FragColor = texture(iChannel0, vec2(u,v));
}

复盘笔记