From 407836c44e757e6dce24fadf63fc1fe8e871cf6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Mon, 26 Sep 2022 20:02:02 +0200 Subject: [PATCH] [wip] Globe: Define lighting from a specific hour --- package.json | 11 ++- pnpm-lock.yaml | 128 ++++++++++++++++------------------ src/modules/globe/frag.glsl | 2 +- src/modules/globe/index.ts | 27 +++---- src/modules/globe/vertex.glsl | 12 ++-- 5 files changed, 83 insertions(+), 97 deletions(-) diff --git a/package.json b/package.json index ebb8b61..53570da 100644 --- a/package.json +++ b/package.json @@ -22,17 +22,16 @@ "motion": "^10.14.2", "ogl": "^0.0.99", "sanitize.css": "^13.0.0", - "suncalc": "^1.9.0", "swell-js": "^3.17.6", "tweakpane": "^3.1.0" }, "devDependencies": { "@sveltejs/adapter-auto": "^1.0.0-next.80", - "@sveltejs/adapter-node": "^1.0.0-next.95", + "@sveltejs/adapter-node": "^1.0.0-next.96", "@sveltejs/adapter-vercel": "^1.0.0-next.77", - "@sveltejs/kit": "^1.0.0-next.503", - "@typescript-eslint/eslint-plugin": "^5.38.0", - "@typescript-eslint/parser": "^5.38.0", + "@sveltejs/kit": "^1.0.0-next.504", + "@typescript-eslint/eslint-plugin": "^5.38.1", + "@typescript-eslint/parser": "^5.38.1", "base-64": "^1.0.0", "browserslist": "^4.21.4", "cssnano": "^5.1.13", @@ -45,7 +44,7 @@ "postcss-sort-media-queries": "^4.3.0", "sass": "^1.55.0", "svelte": "^3.50.1", - "svelte-check": "^2.9.0", + "svelte-check": "^2.9.1", "svelte-preprocess": "^4.10.7", "tslib": "^2.4.0", "typescript": "^4.8.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bfdbf37..107906e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3,11 +3,11 @@ lockfileVersion: 5.4 specifiers: '@studio-freight/lenis': ^0.2.6 '@sveltejs/adapter-auto': ^1.0.0-next.80 - '@sveltejs/adapter-node': ^1.0.0-next.95 + '@sveltejs/adapter-node': ^1.0.0-next.96 '@sveltejs/adapter-vercel': ^1.0.0-next.77 - '@sveltejs/kit': ^1.0.0-next.503 - '@typescript-eslint/eslint-plugin': ^5.38.0 - '@typescript-eslint/parser': ^5.38.0 + '@sveltejs/kit': ^1.0.0-next.504 + '@typescript-eslint/eslint-plugin': ^5.38.1 + '@typescript-eslint/parser': ^5.38.1 base-64: ^1.0.0 browserslist: ^4.21.4 cssnano: ^5.1.13 @@ -25,9 +25,8 @@ specifiers: postcss-sort-media-queries: ^4.3.0 sanitize.css: ^13.0.0 sass: ^1.55.0 - suncalc: ^1.9.0 svelte: ^3.50.1 - svelte-check: ^2.9.0 + svelte-check: ^2.9.1 svelte-preprocess: ^4.10.7 swell-js: ^3.17.6 tslib: ^2.4.0 @@ -43,17 +42,16 @@ dependencies: motion: 10.14.2 ogl: 0.0.99 sanitize.css: 13.0.0 - suncalc: 1.9.0 swell-js: 3.17.6 tweakpane: 3.1.0 devDependencies: '@sveltejs/adapter-auto': 1.0.0-next.80 - '@sveltejs/adapter-node': 1.0.0-next.95 + '@sveltejs/adapter-node': 1.0.0-next.96 '@sveltejs/adapter-vercel': 1.0.0-next.77 - '@sveltejs/kit': 1.0.0-next.503_svelte@3.50.1+vite@3.1.3 - '@typescript-eslint/eslint-plugin': 5.38.0_4gkcvl6qsi23tqqawfqgcwtp54 - '@typescript-eslint/parser': 5.38.0_7ilbxdl5iguzcjriqqcg2m5cku + '@sveltejs/kit': 1.0.0-next.504_svelte@3.50.1+vite@3.1.3 + '@typescript-eslint/eslint-plugin': 5.38.1_qatzzi2vqzjqg2tq57nszrvcfi + '@typescript-eslint/parser': 5.38.1_7ilbxdl5iguzcjriqqcg2m5cku base-64: 1.0.0 browserslist: 4.21.4 cssnano: 5.1.13_postcss@8.4.16 @@ -66,7 +64,7 @@ devDependencies: postcss-sort-media-queries: 4.3.0_postcss@8.4.16 sass: 1.55.0 svelte: 3.50.1 - svelte-check: 2.9.0_yvs2ufmgd7w5odpvp3nw2pbb7y + svelte-check: 2.9.1_yvs2ufmgd7w5odpvp3nw2pbb7y svelte-preprocess: 4.10.7_stzz5n57hyiugj4ntsptwutnlu tslib: 2.4.0 typescript: 4.8.3 @@ -514,8 +512,8 @@ packages: set-cookie-parser: 2.5.1 dev: true - /@sveltejs/adapter-node/1.0.0-next.95: - resolution: {integrity: sha512-RrAsFjb8qG9Q0yWusGLBB5OhejR6RfRG3X7b/V65fcIB4t3IP7hkwgNOyuXQd5jQ24lbt+Tyx3fguEfQvhMrhw==} + /@sveltejs/adapter-node/1.0.0-next.96: + resolution: {integrity: sha512-tIHaRolUYy2PiHl4RUWaOsYxEjK5lN9501qzCzFbYr/uoLnZcnPGSXNJICwX0AX9AUkV6cvkZey6bLbUQcwH0Q==} dependencies: '@rollup/plugin-commonjs': 22.0.2_rollup@2.79.1 '@rollup/plugin-json': 4.1.0_rollup@2.79.1 @@ -533,8 +531,8 @@ packages: - supports-color dev: true - /@sveltejs/kit/1.0.0-next.503_svelte@3.50.1+vite@3.1.3: - resolution: {integrity: sha512-QSEHe40qMOYjXirxS57dIa9NU4FntlYh+KYslBzasjMCfSiUkHGaWMJRz8uU+R4BWnThD9SdCo7F/NwDxu5LRQ==} + /@sveltejs/kit/1.0.0-next.504_svelte@3.50.1+vite@3.1.3: + resolution: {integrity: sha512-KrhlSHT3aCVnhRgUoN6aGIjIw3nWEdNwfoZcE1x65F5D7Ju/K9D8dQwyal9v0aBAZyN9nFuXxsYGaMLE9sppfw==} engines: {node: '>=16.14'} hasBin: true requiresBuild: true @@ -606,8 +604,8 @@ packages: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true - /@types/node/18.7.20: - resolution: {integrity: sha512-adzY4vLLr5Uivmx8+zfSJ5fbdgKxX8UMtjtl+17n0B1q1Nz8JEmE151vefMdpD+1gyh+77weN4qEhej/O7budQ==} + /@types/node/18.7.22: + resolution: {integrity: sha512-TsmoXYd4zrkkKjJB0URF/mTIKPl+kVcbqClB2F/ykU7vil1BfWZVndOnpEIozPv4fURD28gyPFeIkW2G+KXOvw==} dev: true /@types/pug/2.0.6: @@ -617,17 +615,17 @@ packages: /@types/resolve/1.17.1: resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} dependencies: - '@types/node': 18.7.20 + '@types/node': 18.7.22 dev: true /@types/sass/1.43.1: resolution: {integrity: sha512-BPdoIt1lfJ6B7rw35ncdwBZrAssjcwzI5LByIrYs+tpXlj/CAkuVdRsgZDdP4lq5EjyWzwxZCqAoFyHKFwp32g==} dependencies: - '@types/node': 18.7.20 + '@types/node': 18.7.22 dev: true - /@typescript-eslint/eslint-plugin/5.38.0_4gkcvl6qsi23tqqawfqgcwtp54: - resolution: {integrity: sha512-GgHi/GNuUbTOeoJiEANi0oI6fF3gBQc3bGFYj40nnAPCbhrtEDf2rjBmefFadweBmO1Du1YovHeDP2h5JLhtTQ==} + /@typescript-eslint/eslint-plugin/5.38.1_qatzzi2vqzjqg2tq57nszrvcfi: + resolution: {integrity: sha512-ky7EFzPhqz3XlhS7vPOoMDaQnQMn+9o5ICR9CPr/6bw8HrFkzhMSxuA3gRfiJVvs7geYrSeawGJjZoZQKCOglQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: '@typescript-eslint/parser': ^5.0.0 @@ -637,10 +635,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.38.0_7ilbxdl5iguzcjriqqcg2m5cku - '@typescript-eslint/scope-manager': 5.38.0 - '@typescript-eslint/type-utils': 5.38.0_7ilbxdl5iguzcjriqqcg2m5cku - '@typescript-eslint/utils': 5.38.0_7ilbxdl5iguzcjriqqcg2m5cku + '@typescript-eslint/parser': 5.38.1_7ilbxdl5iguzcjriqqcg2m5cku + '@typescript-eslint/scope-manager': 5.38.1 + '@typescript-eslint/type-utils': 5.38.1_7ilbxdl5iguzcjriqqcg2m5cku + '@typescript-eslint/utils': 5.38.1_7ilbxdl5iguzcjriqqcg2m5cku debug: 4.3.4 eslint: 8.24.0 ignore: 5.2.0 @@ -652,8 +650,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.38.0_7ilbxdl5iguzcjriqqcg2m5cku: - resolution: {integrity: sha512-/F63giJGLDr0ms1Cr8utDAxP2SPiglaD6V+pCOcG35P2jCqdfR7uuEhz1GIC3oy4hkUF8xA1XSXmd9hOh/a5EA==} + /@typescript-eslint/parser/5.38.1_7ilbxdl5iguzcjriqqcg2m5cku: + resolution: {integrity: sha512-LDqxZBVFFQnQRz9rUZJhLmox+Ep5kdUmLatLQnCRR6523YV+XhRjfYzStQ4MheFA8kMAfUlclHSbu+RKdRwQKw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 @@ -662,9 +660,9 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 5.38.0 - '@typescript-eslint/types': 5.38.0 - '@typescript-eslint/typescript-estree': 5.38.0_typescript@4.8.3 + '@typescript-eslint/scope-manager': 5.38.1 + '@typescript-eslint/types': 5.38.1 + '@typescript-eslint/typescript-estree': 5.38.1_typescript@4.8.3 debug: 4.3.4 eslint: 8.24.0 typescript: 4.8.3 @@ -672,16 +670,16 @@ packages: - supports-color dev: true - /@typescript-eslint/scope-manager/5.38.0: - resolution: {integrity: sha512-ByhHIuNyKD9giwkkLqzezZ9y5bALW8VNY6xXcP+VxoH4JBDKjU5WNnsiD4HJdglHECdV+lyaxhvQjTUbRboiTA==} + /@typescript-eslint/scope-manager/5.38.1: + resolution: {integrity: sha512-BfRDq5RidVU3RbqApKmS7RFMtkyWMM50qWnDAkKgQiezRtLKsoyRKIvz1Ok5ilRWeD9IuHvaidaLxvGx/2eqTQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.38.0 - '@typescript-eslint/visitor-keys': 5.38.0 + '@typescript-eslint/types': 5.38.1 + '@typescript-eslint/visitor-keys': 5.38.1 dev: true - /@typescript-eslint/type-utils/5.38.0_7ilbxdl5iguzcjriqqcg2m5cku: - resolution: {integrity: sha512-iZq5USgybUcj/lfnbuelJ0j3K9dbs1I3RICAJY9NZZpDgBYXmuUlYQGzftpQA9wC8cKgtS6DASTvF3HrXwwozA==} + /@typescript-eslint/type-utils/5.38.1_7ilbxdl5iguzcjriqqcg2m5cku: + resolution: {integrity: sha512-UU3j43TM66gYtzo15ivK2ZFoDFKKP0k03MItzLdq0zV92CeGCXRfXlfQX5ILdd4/DSpHkSjIgLLLh1NtkOJOAw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: '*' @@ -690,8 +688,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 5.38.0_typescript@4.8.3 - '@typescript-eslint/utils': 5.38.0_7ilbxdl5iguzcjriqqcg2m5cku + '@typescript-eslint/typescript-estree': 5.38.1_typescript@4.8.3 + '@typescript-eslint/utils': 5.38.1_7ilbxdl5iguzcjriqqcg2m5cku debug: 4.3.4 eslint: 8.24.0 tsutils: 3.21.0_typescript@4.8.3 @@ -700,13 +698,13 @@ packages: - supports-color dev: true - /@typescript-eslint/types/5.38.0: - resolution: {integrity: sha512-HHu4yMjJ7i3Cb+8NUuRCdOGu2VMkfmKyIJsOr9PfkBVYLYrtMCK/Ap50Rpov+iKpxDTfnqvDbuPLgBE5FwUNfA==} + /@typescript-eslint/types/5.38.1: + resolution: {integrity: sha512-QTW1iHq1Tffp9lNfbfPm4WJabbvpyaehQ0SrvVK2yfV79SytD9XDVxqiPvdrv2LK7DGSFo91TB2FgWanbJAZXg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.38.0_typescript@4.8.3: - resolution: {integrity: sha512-6P0RuphkR+UuV7Avv7MU3hFoWaGcrgOdi8eTe1NwhMp2/GjUJoODBTRWzlHpZh6lFOaPmSvgxGlROa0Sg5Zbyg==} + /@typescript-eslint/typescript-estree/5.38.1_typescript@4.8.3: + resolution: {integrity: sha512-99b5e/Enoe8fKMLdSuwrfH/C0EIbpUWmeEKHmQlGZb8msY33qn1KlkFww0z26o5Omx7EVjzVDCWEfrfCDHfE7g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: typescript: '*' @@ -714,8 +712,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 5.38.0 - '@typescript-eslint/visitor-keys': 5.38.0 + '@typescript-eslint/types': 5.38.1 + '@typescript-eslint/visitor-keys': 5.38.1 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 @@ -726,16 +724,16 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.38.0_7ilbxdl5iguzcjriqqcg2m5cku: - resolution: {integrity: sha512-6sdeYaBgk9Fh7N2unEXGz+D+som2QCQGPAf1SxrkEr+Z32gMreQ0rparXTNGRRfYUWk/JzbGdcM8NSSd6oqnTA==} + /@typescript-eslint/utils/5.38.1_7ilbxdl5iguzcjriqqcg2m5cku: + resolution: {integrity: sha512-oIuUiVxPBsndrN81oP8tXnFa/+EcZ03qLqPDfSZ5xIJVm7A9V0rlkQwwBOAGtrdN70ZKDlKv+l1BeT4eSFxwXA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: '@types/json-schema': 7.0.11 - '@typescript-eslint/scope-manager': 5.38.0 - '@typescript-eslint/types': 5.38.0 - '@typescript-eslint/typescript-estree': 5.38.0_typescript@4.8.3 + '@typescript-eslint/scope-manager': 5.38.1 + '@typescript-eslint/types': 5.38.1 + '@typescript-eslint/typescript-estree': 5.38.1_typescript@4.8.3 eslint: 8.24.0 eslint-scope: 5.1.1 eslint-utils: 3.0.0_eslint@8.24.0 @@ -744,11 +742,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys/5.38.0: - resolution: {integrity: sha512-MxnrdIyArnTi+XyFLR+kt/uNAcdOnmT+879os7qDRI+EYySR4crXJq9BXPfRzzLGq0wgxkwidrCJ9WCAoacm1w==} + /@typescript-eslint/visitor-keys/5.38.1: + resolution: {integrity: sha512-bSHr1rRxXt54+j2n4k54p4fj8AHJ49VDWtjpImOpzQj4qjAiOpPni+V1Tyajh19Api1i844F757cur8wH3YvOA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.38.0 + '@typescript-eslint/types': 5.38.1 eslint-visitor-keys: 3.3.0 dev: true @@ -861,7 +859,7 @@ packages: postcss: ^8.1.0 dependencies: browserslist: 4.21.4 - caniuse-lite: 1.0.30001411 + caniuse-lite: 1.0.30001412 fraction.js: 4.2.0 normalize-range: 0.1.2 picocolors: 1.0.0 @@ -911,8 +909,8 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001411 - electron-to-chromium: 1.4.261 + caniuse-lite: 1.0.30001412 + electron-to-chromium: 1.4.262 node-releases: 2.0.6 update-browserslist-db: 1.0.9_browserslist@4.21.4 dev: true @@ -942,13 +940,13 @@ packages: resolution: {integrity: sha512-bsTwuIg/BZZK/vreVTYYbSWoe2F+71P7K5QGEX+pT250DZbfU1MQ5prOKpPR+LL6uWKK3KMwMCAS74QB3Um1uw==} dependencies: browserslist: 4.21.4 - caniuse-lite: 1.0.30001411 + caniuse-lite: 1.0.30001412 lodash.memoize: 4.1.2 lodash.uniq: 4.5.0 dev: true - /caniuse-lite/1.0.30001411: - resolution: {integrity: sha512-HPnJKESKuhKpHvMY1/ux7J3nG7xG8jRuL4lbyCjDRm0doTNV91tcRk60xrP7Ym9DtJH/yuqntDWBJCqpXB4b7g==} + /caniuse-lite/1.0.30001412: + resolution: {integrity: sha512-+TeEIee1gS5bYOiuf+PS/kp2mrXic37Hl66VY6EAfxasIk5fELTktK2oOezYed12H8w7jt3s512PpulQidPjwA==} dev: true /chalk/4.1.2: @@ -1258,8 +1256,8 @@ packages: domhandler: 4.3.1 dev: true - /electron-to-chromium/1.4.261: - resolution: {integrity: sha512-fVXliNUGJ7XUVJSAasPseBbVgJIeyw5M1xIkgXdTSRjlmCqBbiSTsEdLOCJS31Fc8B7CaloQ/BFAg8By3ODLdg==} + /electron-to-chromium/1.4.262: + resolution: {integrity: sha512-Ckn5haqmGh/xS8IbcgK3dnwAVnhDyo/WQnklWn6yaMucYTq7NNxwlGE8ElzEOnonzRLzUCo2Ot3vUb2GYUF2Hw==} dev: true /embla-carousel/7.0.3: @@ -3286,10 +3284,6 @@ packages: postcss-selector-parser: 6.0.10 dev: true - /suncalc/1.9.0: - resolution: {integrity: sha512-vMJ8Byp1uIPoj+wb9c1AdK4jpkSKVAywgHX0lqY7zt6+EWRRC3Z+0Ucfjy/0yxTVO1hwwchZe4uoFNqrIC24+A==} - dev: false - /supports-color/7.2.0: resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} engines: {node: '>=8'} @@ -3302,8 +3296,8 @@ packages: engines: {node: '>= 0.4'} dev: true - /svelte-check/2.9.0_yvs2ufmgd7w5odpvp3nw2pbb7y: - resolution: {integrity: sha512-9AVrtP7WbfDgCdqTZNPdj5CCCy1OrYMxFVWAWzNw7fl93c9klFJFtqzVXa6fovfQ050CcpUyJE2dPFL9TFAREw==} + /svelte-check/2.9.1_yvs2ufmgd7w5odpvp3nw2pbb7y: + resolution: {integrity: sha512-+BFPsj6irZ+t2pVSVo//2Ic1mI3A52xCwbkSTVhTqYZqgawcyZd9pYZoEac3fIWbEeTyCb5X82ORKI/gjn+P7A==} hasBin: true peerDependencies: svelte: ^3.24.0 diff --git a/src/modules/globe/frag.glsl b/src/modules/globe/frag.glsl index 613d54d..1b59fa1 100644 --- a/src/modules/globe/frag.glsl +++ b/src/modules/globe/frag.glsl @@ -17,4 +17,4 @@ void main() { vec3 color = mix(nightColor, dayColor, mixAmount); gl_FragColor = vec4(color, 1.0); -} +} \ No newline at end of file diff --git a/src/modules/globe/index.ts b/src/modules/globe/index.ts index ca4b3ee..db813c2 100644 --- a/src/modules/globe/index.ts +++ b/src/modules/globe/index.ts @@ -1,7 +1,6 @@ // @ts-nocheck import { Renderer, Camera, Vec3, Orbit, Sphere, Transform, Program, Mesh, Texture } from 'ogl' -import SunCalc from 'suncalc' -import { map } from '$utils/functions/index' +import { map } from '$utils/functions' // Shaders import VERTEX_SHADER from '$modules/globe/vertex.glsl?raw' import FRAGMENT_SHADER from '$modules/globe/frag.glsl?raw' @@ -32,13 +31,7 @@ export class Globe { } ] const location = locations[1] - const localDate = new Date(now.toLocaleString('en-US', { timeZone: location.tz })) - - this.sunPosition = SunCalc.getPosition(localDate, location.lat, location.lng) - - var times = SunCalc.getTimes(new Date(), location.lat, location.lng); - var sunrisePos = SunCalc.getPosition(times.sunrise, location.lat, location.lng); - this.sunriseAzimuth = sunrisePos.azimuth * 180 / Math.PI; + const localDate = new Date(new Date().toLocaleString('en-US', { timeZone: location.tz })) // Parameters this.params = { @@ -128,7 +121,14 @@ export class Globe { imgDark.onload = () => (mapDark.image = imgDark) imgDark.src = this.options.mapFileDark - const azimuthValue = map(this.sunriseAzimuth, -180, 180, -Math.PI, Math.PI); + // Create light + const dayTime = map(5, 0, 24, 0, 1, true) + const lightD = degToRad(360 / dayTime) + const sunPosition = new Vec3( + Math.cos(lightD), + Math.sin(lightD) * Math.sin(0), + Math.sin(lightD) * Math.cos(0) + ) // Create program const program = new Program(this.gl, { @@ -138,16 +138,11 @@ export class Globe { u_dt: { value: 0 }, map: { value: mapWorld }, // Map Texture mapDark: { value: mapDark }, // Map Dark Texture - altitude: { value: 0 }, - azimuth: { value: 0 }, + sunPosition: { value: sunPosition }, }, cullFace: null, }) - // Create light - program.uniforms.altitude.value = this.sunPosition.altitude - program.uniforms.azimuth.value = this.sunPosition.azimuth - // Create globe mesh this.globe = new Mesh(this.gl, { geometry: this.geometry, diff --git a/src/modules/globe/vertex.glsl b/src/modules/globe/vertex.glsl index 5ad9481..fa2e9ab 100644 --- a/src/modules/globe/vertex.glsl +++ b/src/modules/globe/vertex.glsl @@ -6,19 +6,17 @@ attribute vec3 normal; uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix; uniform mat3 normalMatrix; -uniform float azimuth; -uniform float altitude; +uniform vec3 sunPosition; varying vec2 vUv; varying vec3 vSunDir; void main() { vUv = uv; - // float px = sin(rotation) * 1.0; - // float pz = cos(rotation) * 1.0; - float px = sin(0.0) * 1.0; - float pz = cos(0.0) * 1.0; - vec3 uLightPos = vec3(px, 0.0, pz); + float px = sunPosition.x; + float py = sunPosition.y; + float pz = sunPosition.z; + vec3 uLightPos = vec3(px, py, pz); vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);