From 4c04593ee49bb0b022025718844f3ce2b21f67bf Mon Sep 17 00:00:00 2001 From: Cody Bennett Date: Tue, 1 Aug 2023 08:07:43 -0500 Subject: [PATCH] fix: r154 shader chunk compat (#276) --- src/effects/AnaglyphEffect.js | 3 ++- src/effects/OutlineEffect.js | 4 ++-- src/effects/ParallaxBarrierEffect.js | 3 ++- src/lines/LineMaterial.js | 4 ++-- src/loaders/LDrawLoader.js | 3 ++- src/objects/GroundProjectedEnv.ts | 13 +++++++++++-- src/objects/Reflector.js | 3 ++- src/objects/Refractor.js | 3 ++- src/objects/Sky.ts | 4 ++-- src/objects/Water.js | 3 ++- src/objects/Water2.js | 3 ++- src/utils/GeometryCompressionUtils.js | 3 ++- 12 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/effects/AnaglyphEffect.js b/src/effects/AnaglyphEffect.js index 097bcfc7..fdbdc8c3 100644 --- a/src/effects/AnaglyphEffect.js +++ b/src/effects/AnaglyphEffect.js @@ -10,6 +10,7 @@ import { ShaderMaterial, StereoCamera, WebGLRenderTarget, + REVISION, } from 'three' class AnaglyphEffect { @@ -95,7 +96,7 @@ class AnaglyphEffect { ' max( colorL.a, colorR.a ) );', ' #include ', - ' #include ', + ` #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>`, '}', ].join('\n'), diff --git a/src/effects/OutlineEffect.js b/src/effects/OutlineEffect.js index ee4222ee..2999048c 100644 --- a/src/effects/OutlineEffect.js +++ b/src/effects/OutlineEffect.js @@ -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 @@ -157,7 +157,7 @@ class OutlineEffect { ' gl_FragColor = vec4( outlineColor, outlineAlpha );', ' #include ', - ' #include ', + ` #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>`, ' #include ', ' #include ', diff --git a/src/effects/ParallaxBarrierEffect.js b/src/effects/ParallaxBarrierEffect.js index 9c90aecf..00ae33f4 100644 --- a/src/effects/ParallaxBarrierEffect.js +++ b/src/effects/ParallaxBarrierEffect.js @@ -9,6 +9,7 @@ import { ShaderMaterial, StereoCamera, WebGLRenderTarget, + REVISION, } from 'three' class ParallaxBarrierEffect { @@ -61,7 +62,7 @@ class ParallaxBarrierEffect { ' }', ' #include ', - ' #include ', + ` #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>`, '}', ].join('\n'), diff --git a/src/lines/LineMaterial.js b/src/lines/LineMaterial.js index 137dd4d2..6799330a 100644 --- a/src/lines/LineMaterial.js +++ b/src/lines/LineMaterial.js @@ -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) { @@ -417,7 +417,7 @@ class LineMaterial extends ShaderMaterial { gl_FragColor = vec4( diffuseColor.rgb, alpha ); #include - #include + #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}> #include #include diff --git a/src/loaders/LDrawLoader.js b/src/loaders/LDrawLoader.js index 3debe46c..8f79ac7f 100644 --- a/src/loaders/LDrawLoader.js +++ b/src/loaders/LDrawLoader.js @@ -15,6 +15,7 @@ import { UniformsUtils, Vector3, Ray, + REVISION, } from 'three' // Special surface finish tag types. @@ -128,7 +129,7 @@ class LDrawConditionalLineMaterial extends ShaderMaterial { outgoingLight = diffuseColor.rgb; // simple shader gl_FragColor = vec4(outgoingLight, diffuseColor.a); #include - #include + #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}> #include #include } diff --git a/src/objects/GroundProjectedEnv.ts b/src/objects/GroundProjectedEnv.ts index 72780cab..9012ec79 100644 --- a/src/objects/GroundProjectedEnv.ts +++ b/src/objects/GroundProjectedEnv.ts @@ -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 @@ -105,7 +114,7 @@ export class GroundProjectedEnv extends Mesh { #endif gl_FragColor = vec4( outcolor, 1.0 ); #include - #include + #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}> } ` diff --git a/src/objects/Reflector.js b/src/objects/Reflector.js index b63f5887..5450d16f 100644 --- a/src/objects/Reflector.js +++ b/src/objects/Reflector.js @@ -11,6 +11,7 @@ import { WebGLRenderTarget, HalfFloatType, NoToneMapping, + REVISION, } from 'three' class Reflector extends Mesh { @@ -73,7 +74,7 @@ class Reflector extends Mesh { gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 ); #include - #include + #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}> }`, } diff --git a/src/objects/Refractor.js b/src/objects/Refractor.js index 429f3eb1..908efb3a 100644 --- a/src/objects/Refractor.js +++ b/src/objects/Refractor.js @@ -12,6 +12,7 @@ import { WebGLRenderTarget, NoToneMapping, HalfFloatType, + REVISION, } from 'three' class Refractor extends Mesh { @@ -68,7 +69,7 @@ class Refractor extends Mesh { gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 ); #include - #include + #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}> }`, } diff --git a/src/objects/Sky.ts b/src/objects/Sky.ts index af40a899..0f69acc4 100644 --- a/src/objects/Sky.ts +++ b/src/objects/Sky.ts @@ -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: { @@ -166,7 +166,7 @@ const SkyShader = { gl_FragColor = vec4( retColor, 1.0 ); #include - #include + #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}> } `, diff --git a/src/objects/Water.js b/src/objects/Water.js index 41e6343f..540647af 100644 --- a/src/objects/Water.js +++ b/src/objects/Water.js @@ -11,6 +11,7 @@ import { Vector3, Vector4, WebGLRenderTarget, + REVISION, } from 'three' /** @@ -178,7 +179,7 @@ class Water extends Mesh { gl_FragColor = vec4( outgoingLight, alpha ); #include - #include + #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}> #include }`, } diff --git a/src/objects/Water2.js b/src/objects/Water2.js index 246d4578..eb17cb06 100644 --- a/src/objects/Water2.js +++ b/src/objects/Water2.js @@ -9,6 +9,7 @@ import { UniformsUtils, Vector2, Vector4, + REVISION, } from 'three' import { Reflector } from './Reflector' import { Refractor } from './Refractor' @@ -155,7 +156,7 @@ class Water2 extends Mesh { gl_FragColor = vec4( color, 1.0 ) * mix( refractColor, reflectColor, reflectance ); #include - #include + #include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}> #include }`, diff --git a/src/utils/GeometryCompressionUtils.js b/src/utils/GeometryCompressionUtils.js index bd714a1a..dec6b46e 100644 --- a/src/utils/GeometryCompressionUtils.js +++ b/src/utils/GeometryCompressionUtils.js @@ -14,6 +14,7 @@ import { ShaderLib, UniformsUtils, Vector3, + REVISION, } from 'three' var GeometryCompressionUtils = { @@ -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,