diff --git a/src/globe/globe-fs.js b/src/globe/globe-fs.js deleted file mode 100644 index afd894d..0000000 --- a/src/globe/globe-fs.js +++ /dev/null @@ -1,59 +0,0 @@ -export default ` -#define PI 3.34159265359 -#define RECIPROCAL_PI 0.31830988618 -#define saturate(a) clamp( a, 0.0, 1.0 ) - -precision highp float; - -varying vec3 vNormal; -varying vec2 vUv; -varying vec3 vPos; - -uniform sampler2D tInput; -uniform vec3 uCameraPosition; - - -vec3 F_Schlick_Frostbite (in vec3 f0 , in float f90 , in float u ) -{ - return f0 + ( f90 - f0 ) * pow (1. - u, 5.); -} - -void main(void) { - - vec3 N = vNormal; - vec3 outColor = vec3(0.); - vec3 diffuseColor = texture2D(tInput, vUv).rgb;//pow( texture2D(tInput, vUv).rgb, vec3(2.2) ); - - vec3 V = normalize(uCameraPosition - vPos); - vec3 L = normalize( vec3(20.,20.,20.) ); - vec3 Ldir = normalize( L - vPos ) ; - vec3 radiance = vec3(0.); - float NdotL = max(0., dot(N,L) ); - vec3 lColor = vec3(1.); - - - float attenuation = 1.;//calcLightAttenuation(length(L - worldPos), directLight.distance, directLight.decay); - - float roughness = clamp( 1., 0.04, 1.0 ); - vec3 H = normalize(L); - float LdotH = saturate ( dot (L , H )); - float NdotH = saturate ( dot (N , H )); - float energyBias = mix(0., 0.5, roughness ); - float energyFactor = mix(1.0, 1.0 / 1.51, roughness ); - float f90 = energyBias + 2.0 * LdotH * LdotH * roughness ; - vec3 f0 = vec3(1.0, 1.0, 1.0); - float lightScatter = F_Schlick_Frostbite ( f0 , f90 , NdotL ).r; - vec3 irradiance = NdotL * lColor; - outColor = diffuseColor * irradiance * lightScatter * energyFactor * attenuation; - - - vec3 ambient = vec3(192./255., 181./255., 215./255.); - // outColor.r = max(ambient.r, outColor.r); - // outColor.g = max(ambient.g, outColor.g); - // outColor.b = max(ambient.b, outColor.b); - outColor = diffuseColor * vec3(NdotL) + diffuseColor * ambient * (1.-NdotL); - - - gl_FragColor = vec4( outColor, 1. ); -} -` diff --git a/src/globe/beam/ArrayBuffer.js b/src/modules/globe/beam/ArrayBuffer.js similarity index 100% rename from src/globe/beam/ArrayBuffer.js rename to src/modules/globe/beam/ArrayBuffer.js diff --git a/src/globe/beam/Camera.js b/src/modules/globe/beam/Camera.js similarity index 100% rename from src/globe/beam/Camera.js rename to src/modules/globe/beam/Camera.js diff --git a/src/globe/beam/Container.js b/src/modules/globe/beam/Container.js similarity index 100% rename from src/globe/beam/Container.js rename to src/modules/globe/beam/Container.js diff --git a/src/globe/beam/GeometryBuffer.js b/src/modules/globe/beam/GeometryBuffer.js similarity index 100% rename from src/globe/beam/GeometryBuffer.js rename to src/modules/globe/beam/GeometryBuffer.js diff --git a/src/globe/beam/Material.js b/src/modules/globe/beam/Material.js similarity index 88% rename from src/globe/beam/Material.js rename to src/modules/globe/beam/Material.js index 4274614..ce27eb7 100755 --- a/src/globe/beam/Material.js +++ b/src/modules/globe/beam/Material.js @@ -1,6 +1,6 @@ import Program from './Program'; -import vertexShader from './shaders/default-vs.glsl'; -import fragmentShader from './shaders/mesh-fs.glsl'; +import vertexShader from './shaders/default-vs.glsl?raw'; +import fragmentShader from './shaders/mesh-fs.glsl?raw'; class Material extends Program { @@ -22,7 +22,7 @@ class Material extends Program { }, options.defines); super(gl, options); - + if (!gl) { return; } @@ -42,7 +42,7 @@ class Material extends Program { } } }); - + this.map = options.map; } diff --git a/src/globe/beam/Mesh.js b/src/modules/globe/beam/Mesh.js similarity index 100% rename from src/globe/beam/Mesh.js rename to src/modules/globe/beam/Mesh.js diff --git a/src/globe/beam/Object3d.js b/src/modules/globe/beam/Object3d.js similarity index 100% rename from src/globe/beam/Object3d.js rename to src/modules/globe/beam/Object3d.js diff --git a/src/globe/beam/PlaneGeometryBuffer.js b/src/modules/globe/beam/PlaneGeometryBuffer.js similarity index 100% rename from src/globe/beam/PlaneGeometryBuffer.js rename to src/modules/globe/beam/PlaneGeometryBuffer.js diff --git a/src/globe/beam/Program.js b/src/modules/globe/beam/Program.js similarity index 95% rename from src/globe/beam/Program.js rename to src/modules/globe/beam/Program.js index 559d653..3b89ed3 100755 --- a/src/globe/beam/Program.js +++ b/src/modules/globe/beam/Program.js @@ -1,6 +1,6 @@ import UNIFORM_TYPE from './uniformTypes'; -import defaultVertexShader from './shaders/default-vs.glsl'; -import defaultFragmentShader from './shaders/default-fs.glsl'; +import defaultVertexShader from './shaders/default-vs.glsl?raw'; +import defaultFragmentShader from './shaders/default-fs.glsl?raw'; import uuid from './utils/uuid'; const TEXTURE_2D = 35678 @@ -51,7 +51,7 @@ class Program { }, options); this.options = options; - + this._vertexShaderSource = options.vertexShader; this._fragmentShaderSource = options.fragmentShader; @@ -62,7 +62,7 @@ class Program { gl.attachShader(this._program, this.vertexShader); gl.attachShader(this._program, this.fragmentShader); - + this.type = options.type; this.attributes = {}; this.defines = options.defines; @@ -94,7 +94,7 @@ class Program { if (!this.gl) { return; } - + if (this.isCompiling) { return; } @@ -150,7 +150,7 @@ let isMMatrix = false; var numUniforms = this.gl.getProgramParameter( this._program, this.gl.ACTIVE_UNIFORMS ); for (let i = 0; i < numUniforms; ++i) { - + var uniform = this.gl.getActiveUniform( this._program, i ); if( uniform === null ){ @@ -186,13 +186,13 @@ let isMMatrix = false; value: null, size: uniform.size } - + //set texture unit if (uniform.type === TEXTURE_2D || uniform.type === TEXTURE_CUBE_MAP) { this.uniforms[ name ].unit = this._textureUnit; this._textureUnit++; } - + } } @@ -203,10 +203,10 @@ let isEnd = false; //merge user defined uniforms for (let u in this._savedUniforms) { - - if (this.uniforms[u] !== void 0){ - if (this._savedUniforms[u].value !== void 0 + + if (this.uniforms[u] !== void 0){ + if (this._savedUniforms[u].value !== void 0 && this._savedUniforms[u].value !== null) { @@ -221,8 +221,8 @@ let isEnd = false; for (let u in this._userDefinedUniforms) { - if (this.uniforms[u] !== void 0 - && this._userDefinedUniforms[u] !== void 0 + if (this.uniforms[u] !== void 0 + && this._userDefinedUniforms[u] !== void 0 && this._userDefinedUniforms[u] !== null) { this.uniforms[u].value = this._userDefinedUniforms[u]; } @@ -232,13 +232,13 @@ let isEnd = false; var numAttributes = this.gl.getProgramParameter( this._program, this.gl.ACTIVE_ATTRIBUTES ); for (let i = 0; i < numAttributes; ++i) { - + var attribute = this.gl.getActiveAttrib( this._program, i ); - + if( attribute === null ){ this.gl.getError(); continue; - } + } this.attributes[ attribute.name ] = { location: this.gl.getAttribLocation( this._program, attribute.name ), @@ -250,7 +250,7 @@ let isEnd = false; //this way we make sure that any enabled attribute has some data not to trigger an error //see http://www.mjbshaw.com/2013/03/webgl-fixing-invalidoperation.html // this.gl.enableVertexAttribArray( this.attributes[attribute.name].location ); - + } @@ -264,7 +264,7 @@ let isEnd = false; if (!this.gl) { return; } - + this.gl.useProgram(this._program); } @@ -274,7 +274,7 @@ let isEnd = false; if (!this.gl) { return; } - + for (var attr in this.attributes) { if (attributes[attr] !== void 0) { attributes[attr].bind(); @@ -289,7 +289,7 @@ let isEnd = false; if (!this.gl) { return; } - + this.gl.useProgram(this._program); @@ -307,7 +307,7 @@ let isEnd = false; // } if (this.blend) { - + // this.gl.disable(this.gl.DEPTH_TEST); // this.gl[ this.depthTest ? 'enable' : 'disable' ](this.gl.DEPTH_TEST); @@ -315,7 +315,7 @@ let isEnd = false; this.gl.depthFunc( this.gl.LESS ); } - + this.gl.blendEquation(this.blendEquation); this.gl.blendFuncSeparate(this.blendSrcRGB, this.blendDstRGB, this.blendSrcAlpha, this.blendDstAlpha); // this.gl.blendFunc(this.blendSrc,this.blendDst); @@ -351,7 +351,7 @@ let isEnd = false; } break; default: - + //texture2D if (this.uniforms[ uniformName ].type === TEXTURE_2D || this.uniforms[ uniformName ].type === TEXTURE_CUBE_MAP ){ @@ -370,7 +370,7 @@ let isEnd = false; else { let type = UNIFORM_TYPE[this.uniforms[ keys[i] ].type]; - + //add 'v' to the uniformType if the unifor is an array: ex "3f" => "3fv" if (this.uniforms[ uniformName ].isArray) { type += 'v'; @@ -380,17 +380,17 @@ let isEnd = false; if (type == '2f') { this.gl['uniform' + type ](this.uniforms[ uniformName ].location, this.uniforms[ uniformName ].value[0], this.uniforms[ uniformName ].value[1]); - + // drawnUniforms2f.push(uniformName); } - else if (type == '3f') { + else if (type == '3f') { this.gl['uniform' + type ](this.uniforms[ uniformName ].location, this.uniforms[ uniformName ].value[0], this.uniforms[ uniformName ].value[1], this.uniforms[ uniformName ].value[2]); - + // drawnUniforms3f.push(uniformName); } else if (type == '4f') { this.gl['uniform' + type ](this.uniforms[ uniformName ].location, this.uniforms[ uniformName ].value[0], this.uniforms[ uniformName ].value[1], this.uniforms[ uniformName ].value[2], this.uniforms[ uniformName ].value[3]); - + // drawnUniforms4f.push(uniformName); } else { @@ -415,7 +415,7 @@ let isEnd = false; else { this.gl.drawArrays(this.wireframe ? this.gl.LINE_STRIP : this.type, 0, geometry.length); } - + } diff --git a/src/globe/beam/Renderer.js b/src/modules/globe/beam/Renderer.js similarity index 100% rename from src/globe/beam/Renderer.js rename to src/modules/globe/beam/Renderer.js diff --git a/src/globe/beam/SphereGeometryBuffer.js b/src/modules/globe/beam/SphereGeometryBuffer.js similarity index 100% rename from src/globe/beam/SphereGeometryBuffer.js rename to src/modules/globe/beam/SphereGeometryBuffer.js diff --git a/src/globe/beam/Texture.js b/src/modules/globe/beam/Texture.js similarity index 100% rename from src/globe/beam/Texture.js rename to src/modules/globe/beam/Texture.js diff --git a/src/globe/beam/glMatrix/common.js b/src/modules/globe/beam/glMatrix/common.js similarity index 100% rename from src/globe/beam/glMatrix/common.js rename to src/modules/globe/beam/glMatrix/common.js diff --git a/src/globe/beam/glMatrix/mat2.js b/src/modules/globe/beam/glMatrix/mat2.js similarity index 100% rename from src/globe/beam/glMatrix/mat2.js rename to src/modules/globe/beam/glMatrix/mat2.js diff --git a/src/globe/beam/glMatrix/mat2d.js b/src/modules/globe/beam/glMatrix/mat2d.js similarity index 100% rename from src/globe/beam/glMatrix/mat2d.js rename to src/modules/globe/beam/glMatrix/mat2d.js diff --git a/src/globe/beam/glMatrix/mat3.js b/src/modules/globe/beam/glMatrix/mat3.js similarity index 100% rename from src/globe/beam/glMatrix/mat3.js rename to src/modules/globe/beam/glMatrix/mat3.js diff --git a/src/globe/beam/glMatrix/mat4.js b/src/modules/globe/beam/glMatrix/mat4.js similarity index 100% rename from src/globe/beam/glMatrix/mat4.js rename to src/modules/globe/beam/glMatrix/mat4.js diff --git a/src/globe/beam/glMatrix/quat.js b/src/modules/globe/beam/glMatrix/quat.js similarity index 100% rename from src/globe/beam/glMatrix/quat.js rename to src/modules/globe/beam/glMatrix/quat.js diff --git a/src/globe/beam/glMatrix/vec2.js b/src/modules/globe/beam/glMatrix/vec2.js similarity index 100% rename from src/globe/beam/glMatrix/vec2.js rename to src/modules/globe/beam/glMatrix/vec2.js diff --git a/src/globe/beam/glMatrix/vec3.js b/src/modules/globe/beam/glMatrix/vec3.js similarity index 100% rename from src/globe/beam/glMatrix/vec3.js rename to src/modules/globe/beam/glMatrix/vec3.js diff --git a/src/globe/beam/glMatrix/vec4.js b/src/modules/globe/beam/glMatrix/vec4.js similarity index 100% rename from src/globe/beam/glMatrix/vec4.js rename to src/modules/globe/beam/glMatrix/vec4.js diff --git a/src/globe/beam/index.js b/src/modules/globe/beam/index.js similarity index 100% rename from src/globe/beam/index.js rename to src/modules/globe/beam/index.js diff --git a/src/globe/beam/shaders/default-fs.glsl b/src/modules/globe/beam/shaders/default-fs.glsl similarity index 100% rename from src/globe/beam/shaders/default-fs.glsl rename to src/modules/globe/beam/shaders/default-fs.glsl diff --git a/src/globe/beam/shaders/default-vs.glsl b/src/modules/globe/beam/shaders/default-vs.glsl similarity index 100% rename from src/globe/beam/shaders/default-vs.glsl rename to src/modules/globe/beam/shaders/default-vs.glsl diff --git a/src/globe/beam/shaders/mesh-fs.glsl b/src/modules/globe/beam/shaders/mesh-fs.glsl similarity index 100% rename from src/globe/beam/shaders/mesh-fs.glsl rename to src/modules/globe/beam/shaders/mesh-fs.glsl diff --git a/src/globe/beam/uniformTypes.js b/src/modules/globe/beam/uniformTypes.js similarity index 100% rename from src/globe/beam/uniformTypes.js rename to src/modules/globe/beam/uniformTypes.js diff --git a/src/globe/beam/utils/getFilter.js b/src/modules/globe/beam/utils/getFilter.js similarity index 100% rename from src/globe/beam/utils/getFilter.js rename to src/modules/globe/beam/utils/getFilter.js diff --git a/src/globe/beam/utils/isPowerOf2.js b/src/modules/globe/beam/utils/isPowerOf2.js similarity index 100% rename from src/globe/beam/utils/isPowerOf2.js rename to src/modules/globe/beam/utils/isPowerOf2.js diff --git a/src/globe/beam/utils/uuid.js b/src/modules/globe/beam/utils/uuid.js similarity index 100% rename from src/globe/beam/utils/uuid.js rename to src/modules/globe/beam/utils/uuid.js diff --git a/src/globe/beam/utils/warn.js b/src/modules/globe/beam/utils/warn.js similarity index 100% rename from src/globe/beam/utils/warn.js rename to src/modules/globe/beam/utils/warn.js diff --git a/src/modules/globe/globe-fs.glsl b/src/modules/globe/globe-fs.glsl new file mode 100644 index 0000000..484c307 --- /dev/null +++ b/src/modules/globe/globe-fs.glsl @@ -0,0 +1,53 @@ +#define PI 3.34159265359 +#define RECIPROCAL_PI 0.31830988618 +#define saturate(a) clamp(a, 0.0, 1.0) + +precision highp float; + +varying vec3 vNormal; +varying vec2 vUv; +varying vec3 vPos; + +uniform sampler2D tInput; +uniform vec3 uCameraPosition; + + +vec3 F_Schlick_Frostbite (in vec3 f0, in float f90, in float u) { + return f0 + (f90 - f0) * pow (1. - u, 5.); +} + + +void main (void) { + vec3 N = vNormal; + vec3 outColor = vec3(0.); + vec3 diffuseColor = texture2D(tInput, vUv).rgb; //pow(texture2D(tInput, vUv).rgb, vec3(2.2)); + + vec3 V = normalize(uCameraPosition - vPos); + vec3 L = normalize(vec3(20., 20., 20.)); + vec3 Ldir = normalize(L - vPos); + vec3 radiance = vec3(0.); + float NdotL = max(0., dot(N, L)); + vec3 lColor = vec3(1.); + + float attenuation = 1.; // calcLightAttenuation(length(L - worldPos), directLight.distance, directLight.decay); + + float roughness = clamp(1., 0.04, 1.0); + vec3 H = normalize(L); + float LdotH = saturate(dot(L, H)); + float NdotH = saturate(dot(N, H)); + float energyBias = mix(0., 0.5, roughness); + float energyFactor = mix(1.0, 1.0 / 1.51, roughness); + float f90 = energyBias + 2.0 * LdotH * LdotH * roughness; + vec3 f0 = vec3(1.0, 1.0, 1.0); + float lightScatter = F_Schlick_Frostbite (f0, f90, NdotL).r; + vec3 irradiance = NdotL * lColor; + outColor = diffuseColor * irradiance * lightScatter * energyFactor * attenuation; + + vec3 ambient = vec3(192./255., 181./255., 215./255.); + // outColor.r = max(ambient.r, outColor.r); + // outColor.g = max(ambient.g, outColor.g); + // outColor.b = max(ambient.b, outColor.b); + outColor = diffuseColor * vec3(NdotL) + diffuseColor * ambient * (1. - NdotL); + + gl_FragColor = vec4(outColor, 1.); +} \ No newline at end of file diff --git a/src/globe/globe-vs.js b/src/modules/globe/globe-vs.glsl similarity index 62% rename from src/globe/globe-vs.js rename to src/modules/globe/globe-vs.glsl index 3bf1047..3e27897 100644 --- a/src/globe/globe-vs.js +++ b/src/modules/globe/globe-vs.glsl @@ -1,4 +1,3 @@ -export default ` precision highp float; attribute vec3 normal; @@ -15,12 +14,11 @@ varying vec2 vUv; varying vec3 vNormal; varying vec3 vPos; -void main(void) { - vUv = uv; - vNormal = (uNormalMatrix * vec4(normal, 1.)).rgb; - vPos = (uMMatrix * vec4(position, 1.)).rgb; - gl_Position = uPMatrix * uMVMatrix * vec4( position, 1.0 ); +void main(void) { + vUv = uv; + vNormal = (uNormalMatrix * vec4(normal, 1.)).rgb; + vPos = (uMMatrix * vec4(position, 1.)).rgb; + gl_Position = uPMatrix * uMVMatrix * vec4(position, 1.0); gl_Position[1] += uCameraOffsetY * gl_Position.w; -} -` \ No newline at end of file +} \ No newline at end of file diff --git a/src/globe/index.js b/src/modules/globe/index.js similarity index 98% rename from src/globe/index.js rename to src/modules/globe/index.js index 3bfba70..238b920 100644 --- a/src/globe/index.js +++ b/src/modules/globe/index.js @@ -4,8 +4,8 @@ import { vec2, vec3, mat4 } from './beam' import { Container, Mesh, Material, Texture, SphereGeometryBuffer, PlaneGeometryBuffer } from './beam' // GLSL shaders as strings -import GlobeVS from './globe-vs' -import GlobeFS from './globe-fs' +import GlobeVS from './globe-vs.glsl?raw' +import GlobeFS from './globe-fs.glsl?raw' const FOV = 1 // Camera Field of view; we use 1 to prevent strong perspective effect on the globe @@ -135,7 +135,7 @@ class WebglGlobe { fragmentShader: GlobeFS, }) this.globeMesh.geometry = new SphereGeometryBuffer(this.renderer.gl, { - radius: this.referenceHeight/2, + radius: this.referenceHeight / 2, widthSegments: 100, heightSegments: 100 }) this.scene.add(this.globeMesh) @@ -172,8 +172,8 @@ class WebglGlobe { // Wrap marker in link let el = document.createElement('a') el.style.pointerEvents = 'auto' - el.setAttribute('href', '/location/' + markers[i].countrySlug + '/' + markers[i].slug) - el.setAttribute('sapper-noscroll', '') + el.setAttribute('href', `/${markers[i].countrySlug}/${markers[i].slug}`) + el.setAttribute('sveltekit-noscroll', '') if (markers[i].className) el.classList.add(markers[i].className) // Add label