未验证 提交 aab57da1 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #19463 from WestLangley/dev_equirectUv

Shaders: add equirectUv() method
......@@ -175,9 +175,7 @@
#elif defined( ENVMAP_TYPE_EQUIREC )
vec2 sampleUV;
sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
vec2 sampleUV = equirectUv( reflectVec );
#ifdef TEXTURE_LOD_EXT
......
......@@ -707,15 +707,12 @@ uniform vec2 texelSize;
${_getEncodings()}
#define RECIPROCAL_PI 0.31830988618
#define RECIPROCAL_PI2 0.15915494
#include <common>
void main() {
gl_FragColor = vec4(0.0);
vec3 outputDirection = normalize(vOutputDirection);
vec2 uv;
uv.y = asin(clamp(outputDirection.y, -1.0, 1.0)) * RECIPROCAL_PI + 0.5;
uv.x = atan(outputDirection.z, outputDirection.x) * RECIPROCAL_PI2 + 0.5;
vec2 uv = equirectUv( outputDirection );
vec2 f = fract(uv / texelSize - 0.5);
uv -= f * texelSize;
vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
......
......@@ -72,18 +72,13 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer
"varying vec3 vWorldDirection;",
"#define RECIPROCAL_PI 0.31830988618",
"#define RECIPROCAL_PI2 0.15915494",
"#include <common>",
"void main() {",
" vec3 direction = normalize( vWorldDirection );",
" vec2 sampleUV;",
" sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
" sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
" vec2 sampleUV = equirectUv( direction );",
" gl_FragColor = texture2D( tEquirect, sampleUV );",
......
......@@ -117,5 +117,17 @@ bool isPerspectiveMatrix( mat4 m ) {
return m[ 2 ][ 3 ] == - 1.0;
}
vec2 equirectUv( in vec3 dir ) {
// dir is assumed to be unit length
float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
return vec2( u, v );
}
`;
......@@ -44,13 +44,9 @@ export default /* glsl */`
#elif defined( ENVMAP_TYPE_EQUIREC )
vec2 sampleUV;
reflectVec = normalize( reflectVec );
sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
vec2 sampleUV = equirectUv( reflectVec );
vec4 envColor = texture2D( envMap, sampleUV );
......
......@@ -97,9 +97,7 @@ export default /* glsl */`
#elif defined( ENVMAP_TYPE_EQUIREC )
vec2 sampleUV;
sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
vec2 sampleUV = equirectUv( reflectVec );
#ifdef TEXTURE_LOD_EXT
......
......@@ -9,11 +9,7 @@ void main() {
vec3 direction = normalize( vWorldDirection );
vec2 sampleUV;
sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;
vec2 sampleUV = equirectUv( direction );
vec4 texColor = texture2D( tEquirect, sampleUV );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册