Skip to content

Commit ba3a497

Browse files
authored
Merge pull request #521 from EarthyScience/jp/tweaks
fix sphere blocks
2 parents 1d0db38 + 8967247 commit ba3a497

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/components/plots/SphereBlocks.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const SphereBlocks = ({textures} : {textures: THREE.Data3DTexture[] | THREE.Data
7777
const newLatBounds = [Math.max(latExtent[0]-newLatStep, -90), Math.min(latExtent[1]+newLatStep, 90)]
7878
return [newLonBounds, newLatBounds]
7979
},[latExtent, lonExtent, lonResolution, latResolution])
80-
8180
const shaderMaterial = useMemo(()=>{
8281
const shader = new THREE.ShaderMaterial({
8382
glslVersion: THREE.GLSL3,

src/components/plots/plotarea/PlotPoints.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function PlotPoints({ points, tsID, pointSetters, scalers }: { points: THREE.Vec
3131
const geometry = useMemo(() => new THREE.SphereGeometry(pointSize), [pointSize])
3232
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
3333

34-
3534
useEffect(() => {
3635
if (ref.current){
3736
const dummy = new THREE.Object3D()

src/components/textures/shaders/sphereBlocksVert.glsl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ uniform float fillValue;
1414

1515
#define PI 3.1415926535
1616

17-
vec3 givePosition(vec2 uv) {
17+
vec2 giveLonLat(vec2 uv) {
1818
// Reverse the normalization using the bounds
19-
float longitude = ((1.0 - uv.x) * (lonBounds.y - lonBounds.x) + lonBounds.x);
19+
float longitude = uv.x * (lonBounds.y - lonBounds.x) + lonBounds.x;
2020
float latitude = uv.y * (latBounds.y - latBounds.x) + latBounds.x;
2121

22+
longitude = -longitude;
23+
24+
return vec2(longitude, latitude);
25+
}
26+
27+
vec3 givePosition(vec2 lonlat) {
28+
float longitude = lonlat.x;
29+
float latitude = lonlat.y;
30+
2231
// Convert to Cartesian coordinates
2332
float x = cos(latitude) * cos(longitude);
2433
float y = sin(latitude);
@@ -65,11 +74,14 @@ void main() {
6574
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
6675
} else {
6776
vec2 centeredUV = (instanceUV - vec2(0.5, 0.5)) * vec2(2.0, 2.0);
68-
vec3 spherePosition = givePosition(instanceUV);
69-
float latitudeFactor = cos(centeredUV.y * 3.14159 * 0.5); // Maps -1..1 to proper latitude
77+
vec2 lonlat = giveLonLat(instanceUV);
78+
vec3 spherePosition = givePosition(lonlat);
79+
float latitudeFactor = cos(lonlat.y); // Maps -1..1 to proper latitude
80+
float widthFactor = abs(lonBounds.y-lonBounds.x)/PI;
7081
float heightFactor = (dispStrength - displaceZero) * displacement;
7182
vec3 scaledPosition = position;
72-
scaledPosition.x *= latitudeFactor;
83+
scaledPosition.x *= latitudeFactor * widthFactor;
84+
scaledPosition.z *= widthFactor;
7385
scaledPosition.y += 0.025;
7486
scaledPosition.y *= heightFactor;
7587

0 commit comments

Comments
 (0)