Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Sep 23, 2023
1 parent 3703147 commit 69d8a72
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 293 deletions.
6 changes: 6 additions & 0 deletions src/_polyfill/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { REVISION } from 'three'

let _version: any = /* @__PURE__ */ REVISION.replace(/\D+/g, '')
_version = /* @__PURE__ */ parseInt(_version)

export const version = _version as number
6 changes: 2 additions & 4 deletions src/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ import {
Vector2,
Vector3,
VectorKeyframeTrack,
REVISION,
} from 'three'
import { toTrianglesDrawMode } from '../utils/BufferGeometryUtils'
import { version } from '../_polyfill/constants'

class GLTFLoader extends Loader {
constructor(manager) {
Expand Down Expand Up @@ -1634,16 +1634,14 @@ const WEBGL_TYPE_SIZES = {
MAT4: 16,
}

const _version = /* @__PURE__ */ REVISION.replace(/\D+/g, '')

const ATTRIBUTES = {
POSITION: 'position',
NORMAL: 'normal',
TANGENT: 'tangent',
// uv => uv1, 4 uv channels
// https://github.com/mrdoob/three.js/pull/25943
// https://github.com/mrdoob/three.js/pull/25788
...(_version >= 152
...(version >= 152
? {
TEXCOORD_0: 'uv',
TEXCOORD_1: 'uv1',
Expand Down
135 changes: 65 additions & 70 deletions src/objects/Reflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,74 @@ import {
WebGLRenderTarget,
HalfFloatType,
NoToneMapping,
REVISION,
} from 'three'
import { version } from '../_polyfill/constants'

class Reflector extends Mesh {
static ReflectorShader = {
uniforms: {
color: {
value: null,
},

tDiffuse: {
value: null,
},

textureMatrix: {
value: null,
},
},

vertexShader: /* glsl */ `
uniform mat4 textureMatrix;
varying vec4 vUv;
#include <common>
#include <logdepthbuf_pars_vertex>
void main() {
vUv = textureMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
#include <logdepthbuf_vertex>
}`,

fragmentShader: /* glsl */ `
uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec4 vUv;
#include <logdepthbuf_pars_fragment>
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
#include <logdepthbuf_fragment>
vec4 base = texture2DProj( tDiffuse, vUv );
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
}

constructor(geometry, options = {}) {
super(geometry)

Expand Down Expand Up @@ -191,73 +255,4 @@ class Reflector extends Mesh {
}
}

let _version = /* @__PURE__ */ REVISION.replace(/\D+/g, '')
_version = /* @__PURE__ */ parseInt(_version)

/* @__PURE__ */ Object.assign(Reflector, {
ReflectorShader: {
uniforms: {
color: {
value: null,
},

tDiffuse: {
value: null,
},

textureMatrix: {
value: null,
},
},

vertexShader: /* glsl */ `
uniform mat4 textureMatrix;
varying vec4 vUv;
#include <common>
#include <logdepthbuf_pars_vertex>
void main() {
vUv = textureMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
#include <logdepthbuf_vertex>
}`,

fragmentShader: /* glsl */ `
uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec4 vUv;
#include <logdepthbuf_pars_fragment>
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
#include <logdepthbuf_fragment>
vec4 base = texture2DProj( tDiffuse, vUv );
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <${_version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
},
})

export { Reflector }
123 changes: 59 additions & 64 deletions src/objects/Refractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,68 @@ import {
WebGLRenderTarget,
NoToneMapping,
HalfFloatType,
REVISION,
} from 'three'
import { version } from '../_polyfill/constants'

class Refractor extends Mesh {
static RefractorShader = {
uniforms: {
color: {
value: null,
},

tDiffuse: {
value: null,
},

textureMatrix: {
value: null,
},
},

vertexShader: /* glsl */ `
uniform mat4 textureMatrix;
varying vec4 vUv;
void main() {
vUv = textureMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,

fragmentShader: /* glsl */ `
uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec4 vUv;
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
vec4 base = texture2DProj( tDiffuse, vUv );
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
}

constructor(geometry, options = {}) {
super(geometry)

Expand Down Expand Up @@ -243,67 +301,4 @@ class Refractor extends Mesh {
}
}

let _version = /* @__PURE__ */ REVISION.replace(/\D+/g, '')
_version = /* @__PURE__ */ parseInt(_version)

/* @__PURE__ */ Object.assign(Refractor, {
RefractorShader: {
uniforms: {
color: {
value: null,
},

tDiffuse: {
value: null,
},

textureMatrix: {
value: null,
},
},

vertexShader: /* glsl */ `
uniform mat4 textureMatrix;
varying vec4 vUv;
void main() {
vUv = textureMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,

fragmentShader: /* glsl */ `
uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec4 vUv;
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
vec4 base = texture2DProj( tDiffuse, vUv );
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <${_version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
},
})

export { Refractor }
14 changes: 5 additions & 9 deletions src/objects/Sky.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { BackSide, BoxGeometry, Mesh, ShaderMaterial, UniformsUtils, Vector3, REVISION } from 'three'

let _version: any = /* @__PURE__ */ REVISION.replace(/\D+/g, '')
_version = /* @__PURE__ */ parseInt(_version)
import { BackSide, BoxGeometry, Mesh, ShaderMaterial, UniformsUtils, Vector3 } from 'three'
import { version } from '../_polyfill/constants'

const SkyShader = {
uniforms: {
Expand Down Expand Up @@ -169,7 +167,7 @@ const SkyShader = {
gl_FragColor = vec4( retColor, 1.0 );
#include <tonemapping_fragment>
#include <${_version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}
`,
Expand Down Expand Up @@ -202,10 +200,8 @@ class Sky extends Mesh {
super(new BoxGeometry(1, 1, 1), material)
}

static SkyShader: typeof SkyShader
static material: typeof material
static SkyShader = SkyShader
public static material = material
}

/* @__PURE__ */ Object.assign(Sky, { SkyShader, material })

export { Sky }
Loading

0 comments on commit 69d8a72

Please sign in to comment.