Skip to content

Commit

Permalink
fix: r154 shader chunk compat (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett authored Aug 1, 2023
1 parent 7aa3117 commit 4c04593
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/effects/AnaglyphEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ShaderMaterial,
StereoCamera,
WebGLRenderTarget,
REVISION,
} from 'three'

class AnaglyphEffect {
Expand Down Expand Up @@ -95,7 +96,7 @@ class AnaglyphEffect {
' max( colorL.a, colorR.a ) );',

' #include <tonemapping_fragment>',
' #include <encodings_fragment>',
` #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>`,

'}',
].join('\n'),
Expand Down
4 changes: 2 additions & 2 deletions src/effects/OutlineEffect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackSide, Color, ShaderMaterial, UniformsLib, UniformsUtils } from 'three'
import { BackSide, Color, ShaderMaterial, UniformsLib, UniformsUtils, REVISION } from 'three'

/**
* Reference: https://en.wikipedia.org/wiki/Cel_shading
Expand Down Expand Up @@ -157,7 +157,7 @@ class OutlineEffect {
' gl_FragColor = vec4( outlineColor, outlineAlpha );',

' #include <tonemapping_fragment>',
' #include <encodings_fragment>',
` #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>`,
' #include <fog_fragment>',
' #include <premultiplied_alpha_fragment>',

Expand Down
3 changes: 2 additions & 1 deletion src/effects/ParallaxBarrierEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ShaderMaterial,
StereoCamera,
WebGLRenderTarget,
REVISION,
} from 'three'

class ParallaxBarrierEffect {
Expand Down Expand Up @@ -61,7 +62,7 @@ class ParallaxBarrierEffect {
' }',

' #include <tonemapping_fragment>',
' #include <encodings_fragment>',
` #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>`,

'}',
].join('\n'),
Expand Down
4 changes: 2 additions & 2 deletions src/lines/LineMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* }
*/

import { ShaderMaterial, UniformsLib, UniformsUtils, Vector2 } from 'three'
import { ShaderMaterial, UniformsLib, UniformsUtils, Vector2, REVISION } from 'three'

class LineMaterial extends ShaderMaterial {
constructor(parameters) {
Expand Down Expand Up @@ -417,7 +417,7 @@ class LineMaterial extends ShaderMaterial {
gl_FragColor = vec4( diffuseColor.rgb, alpha );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
Expand Down
3 changes: 2 additions & 1 deletion src/loaders/LDrawLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UniformsUtils,
Vector3,
Ray,
REVISION,
} from 'three'

// Special surface finish tag types.
Expand Down Expand Up @@ -128,7 +129,7 @@ class LDrawConditionalLineMaterial extends ShaderMaterial {
outgoingLight = diffuseColor.rgb; // simple shader
gl_FragColor = vec4(outgoingLight, diffuseColor.a);
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
}
Expand Down
13 changes: 11 additions & 2 deletions src/objects/GroundProjectedEnv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Mesh, IcosahedronGeometry, ShaderMaterial, DoubleSide, Texture, CubeTexture, BufferGeometry } from 'three'
import {
Mesh,
IcosahedronGeometry,
ShaderMaterial,
DoubleSide,
Texture,
CubeTexture,
BufferGeometry,
REVISION,
} from 'three'

export interface GroundProjectedEnvParameters {
height?: number
Expand Down Expand Up @@ -105,7 +114,7 @@ export class GroundProjectedEnv extends Mesh<BufferGeometry, ShaderMaterial> {
#endif
gl_FragColor = vec4( outcolor, 1.0 );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}
`

Expand Down
3 changes: 2 additions & 1 deletion src/objects/Reflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
WebGLRenderTarget,
HalfFloatType,
NoToneMapping,
REVISION,
} from 'three'

class Reflector extends Mesh {
Expand Down Expand Up @@ -73,7 +74,7 @@ class Reflector extends Mesh {
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
}
Expand Down
3 changes: 2 additions & 1 deletion src/objects/Refractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
WebGLRenderTarget,
NoToneMapping,
HalfFloatType,
REVISION,
} from 'three'

class Refractor extends Mesh {
Expand Down Expand Up @@ -68,7 +69,7 @@ class Refractor extends Mesh {
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
}
Expand Down
4 changes: 2 additions & 2 deletions src/objects/Sky.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackSide, BoxGeometry, Mesh, ShaderMaterial, UniformsUtils, Vector3 } from 'three'
import { BackSide, BoxGeometry, Mesh, ShaderMaterial, UniformsUtils, Vector3, REVISION } from 'three'

const SkyShader = {
uniforms: {
Expand Down Expand Up @@ -166,7 +166,7 @@ const SkyShader = {
gl_FragColor = vec4( retColor, 1.0 );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}
`,
Expand Down
3 changes: 2 additions & 1 deletion src/objects/Water.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Vector3,
Vector4,
WebGLRenderTarget,
REVISION,
} from 'three'

/**
Expand Down Expand Up @@ -178,7 +179,7 @@ class Water extends Mesh {
gl_FragColor = vec4( outgoingLight, alpha );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
#include <fog_fragment>
}`,
}
Expand Down
3 changes: 2 additions & 1 deletion src/objects/Water2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
UniformsUtils,
Vector2,
Vector4,
REVISION,
} from 'three'
import { Reflector } from './Reflector'
import { Refractor } from './Refractor'
Expand Down Expand Up @@ -155,7 +156,7 @@ class Water2 extends Mesh {
gl_FragColor = vec4( color, 1.0 ) * mix( refractColor, reflectColor, reflectance );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
#include <fog_fragment>
}`,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/GeometryCompressionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ShaderLib,
UniformsUtils,
Vector3,
REVISION,
} from 'three'

var GeometryCompressionUtils = {
Expand Down Expand Up @@ -731,7 +732,7 @@ class PackedPhongMaterial extends MeshPhongMaterial {
'gl_FragColor = vec4( outgoingLight, diffuseColor.a );',

ShaderChunk.tonemapping_fragment,
ShaderChunk.encodings_fragment,
parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? ShaderChunk.colorspace_fragment : ShaderChunk.encodings_fragment,
ShaderChunk.fog_fragment,
ShaderChunk.premultiplied_alpha_fragment,
ShaderChunk.dithering_fragment,
Expand Down

0 comments on commit 4c04593

Please sign in to comment.