圆顶图像投影

问题描述 投票:0回答:1

我正在尝试创建GLSL片段着色器,该图像将图像投影到圆顶。输入将是sampler2D纹理,高程和方位角。

结果应类似于以下gif。

海拔在0到90度之间(在此gif中在-90到90之间)

0至360度之间的方位角<<

现在我的代码如下:

#ifdef GL_ES precision mediump float; #endif uniform float u_time; uniform vec2 u_resolution; uniform sampler2D u_texture_0; uniform sampler2D u_texture_1; // INPUT const float azimuth=0.;// clockwise 360 degree const float altitude=90.;// 0-90 dregree -> 90 = center const float scale=1.; // CALC const float PI=3.14159265359; const float azimuthRad=azimuth*PI/180.; const float altitudeNormalization=sin((1.-(altitude/90.))); float box(in vec2 _st,in vec2 _size){ _size=vec2(.5)-_size*.5; vec2 uv=smoothstep(_size,_size+vec2(.001),_st); uv*=smoothstep(_size,_size+vec2(.001),vec2(1.)-_st); return uv.x*uv.y; } mat2 rotate(float angle){ return mat2(cos(angle),-sin(angle),sin(angle),cos(angle)); } void main(){ vec2 st=gl_FragCoord.xy/u_resolution; vec4 color = texture2D(u_texture_1,st); // set background grid vec2 vPos=st; float aperture=180.; float apertureHalf=.5*aperture*(PI/180.); float maxFactor=sin(apertureHalf); // to unit sphere -> -1 - 1 vPos=vec2(2.*vPos-1.); float l=length(vPos); if(l<=1.){ float x=maxFactor*vPos.x; float y=maxFactor*vPos.y; float n=length(vec2(x,y)); float z=sqrt(1.-n*n); float r=atan(n,z)/PI; float phi=atan(y,x); float u=r*cos(phi)+.5; float v=r*sin(phi)+.5; vec2 uv=vec2(u,v); // translate vec2 translate=vec2(sin(azimuthRad),cos(azimuthRad)); uv+=translate*altitudeNormalization; // rotate uv-=.5; uv=rotate(PI-azimuthRad)*uv; uv+=.5; // scale float size=.5*scale; float box=box(uv,vec2(.5*size)); uv.x*=-1.; uv.y*=-1.; if(box>=.1){ vec3 b=vec3(box); // gl_FragColor=vec4(b,1.); //uv *= box; color += texture2D(u_texture_0,uv); } gl_FragColor= color; } }

您可以看到有两件事是错误的,纹理仅部分显示(我知道我确实将其切掉了,这肯定是错误的),并且变形也是错误的。任何帮助都将被取消。

我正在尝试创建GLSL片段着色器,该图像将图像投影到圆顶。输入将是sampler2D纹理,高程和方位角。结果应类似于以下gif。 ...
glsl fragment-shader
1个回答
0
投票

float size=.5*scale; float box=box(uv,vec2(.5*size));

© www.soinside.com 2019 - 2024. All rights reserved.