Quantcast
Channel: How to map texture image onto a part of a sphere, or how to cut out (intersect) a rectangle of a sphere's surface? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Ilmari Heikkinen for How to map texture image onto a part of a sphere, or how to cut out (intersect) a rectangle of a sphere's surface?

$
0
0

The easiest way to scale down the projection is to tweak the UV coords in the fragment shader:

// how large the projection should beuniform vec2 uScale;...// this is the color for pixels outside the mapped texturevec4 texColor = vec4(0.0, 0.0, 0.0, 1.0);vec2 scale = vec2(1.0/uScale.s, 1.0/uScale.t);vec2 mappedUv = vUv*scale + vec2(0.5,0.5)*(vec2(1.0,1.0)-scale);// if the mapped uv is inside the texture area, read from textureif (mappedUv.s >= 0.0 && mappedUv.s <= 1.0 &&     mappedUv.t >= 0.0 && mappedUv.t <= 1.0) {  texColor = texture2D(map, mappedUv);}

For THREE.SphereGeometry UVs the full field of view in radians is 2pi for x and pi for y. The scale factor for a reduced field is vec2(fovX/2pi, fovY/pi).

You can also do the UV scaling in the vertex shader. Other ways are to copypaste https://github.com/mrdoob/three.js/blob/master/src/extras/geometries/SphereGeometry.js and change the generated UVs to match your scaling factors (uv*1/scale + 0.5*(1-1/scale))

Lemme know if this helps.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>