diff --git a/src/components/plots/SphereBlocks.tsx b/src/components/plots/SphereBlocks.tsx index b2cc16e6..7149f3ec 100644 --- a/src/components/plots/SphereBlocks.tsx +++ b/src/components/plots/SphereBlocks.tsx @@ -77,7 +77,6 @@ const SphereBlocks = ({textures} : {textures: THREE.Data3DTexture[] | THREE.Data const newLatBounds = [Math.max(latExtent[0]-newLatStep, -90), Math.min(latExtent[1]+newLatStep, 90)] return [newLonBounds, newLatBounds] },[latExtent, lonExtent, lonResolution, latResolution]) - const shaderMaterial = useMemo(()=>{ const shader = new THREE.ShaderMaterial({ glslVersion: THREE.GLSL3, diff --git a/src/components/plots/plotarea/PlotPoints.tsx b/src/components/plots/plotarea/PlotPoints.tsx index aadbb0bd..0b58ffb7 100644 --- a/src/components/plots/plotarea/PlotPoints.tsx +++ b/src/components/plots/plotarea/PlotPoints.tsx @@ -31,7 +31,6 @@ function PlotPoints({ points, tsID, pointSetters, scalers }: { points: THREE.Vec const geometry = useMemo(() => new THREE.SphereGeometry(pointSize), [pointSize]) const material = useMemo(()=> new THREE.MeshBasicMaterial({color: new THREE.Color().setRGB(r/300, g/300, b/300).convertSRGBToLinear()}),[pointColor, useCustomPointColor, timeSeries]) // It was converting to sRGB colorspace while the line shader uses linear - useEffect(() => { if (ref.current){ const dummy = new THREE.Object3D() diff --git a/src/components/textures/shaders/sphereBlocksVert.glsl b/src/components/textures/shaders/sphereBlocksVert.glsl index c4c75b48..7b1711fc 100644 --- a/src/components/textures/shaders/sphereBlocksVert.glsl +++ b/src/components/textures/shaders/sphereBlocksVert.glsl @@ -14,11 +14,20 @@ uniform float fillValue; #define PI 3.1415926535 -vec3 givePosition(vec2 uv) { +vec2 giveLonLat(vec2 uv) { // Reverse the normalization using the bounds - float longitude = ((1.0 - uv.x) * (lonBounds.y - lonBounds.x) + lonBounds.x); + float longitude = uv.x * (lonBounds.y - lonBounds.x) + lonBounds.x; float latitude = uv.y * (latBounds.y - latBounds.x) + latBounds.x; + longitude = -longitude; + + return vec2(longitude, latitude); +} + +vec3 givePosition(vec2 lonlat) { + float longitude = lonlat.x; + float latitude = lonlat.y; + // Convert to Cartesian coordinates float x = cos(latitude) * cos(longitude); float y = sin(latitude); @@ -65,11 +74,14 @@ void main() { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); } else { vec2 centeredUV = (instanceUV - vec2(0.5, 0.5)) * vec2(2.0, 2.0); - vec3 spherePosition = givePosition(instanceUV); - float latitudeFactor = cos(centeredUV.y * 3.14159 * 0.5); // Maps -1..1 to proper latitude + vec2 lonlat = giveLonLat(instanceUV); + vec3 spherePosition = givePosition(lonlat); + float latitudeFactor = cos(lonlat.y); // Maps -1..1 to proper latitude + float widthFactor = abs(lonBounds.y-lonBounds.x)/PI; float heightFactor = (dispStrength - displaceZero) * displacement; vec3 scaledPosition = position; - scaledPosition.x *= latitudeFactor; + scaledPosition.x *= latitudeFactor * widthFactor; + scaledPosition.z *= widthFactor; scaledPosition.y += 0.025; scaledPosition.y *= heightFactor;