diff --git a/src/framework/handlers/cubemap.js b/src/framework/handlers/cubemap.js index 9978f484244..bfd6a15aa41 100644 --- a/src/framework/handlers/cubemap.js +++ b/src/framework/handlers/cubemap.js @@ -121,7 +121,6 @@ class CubemapHandler extends ResourceHandler { height: tex.height >> i, format: tex.format, levels: [tex._levels[i]], - fixCubemapSeams: true, addressU: ADDRESS_CLAMP_TO_EDGE, addressV: ADDRESS_CLAMP_TO_EDGE, // generate cubemaps on the top level only @@ -180,8 +179,7 @@ class CubemapHandler extends ResourceHandler { magFilter: assetData.hasOwnProperty('magFilter') ? assetData.magFilter : faceTextures[0].magFilter, anisotropy: assetData.hasOwnProperty('anisotropy') ? assetData.anisotropy : 1, addressU: ADDRESS_CLAMP_TO_EDGE, - addressV: ADDRESS_CLAMP_TO_EDGE, - fixCubemapSeams: !!assets[0] + addressV: ADDRESS_CLAMP_TO_EDGE }); resources[0] = faces; diff --git a/src/platform/graphics/texture.js b/src/platform/graphics/texture.js index 96bca13b7ac..807bf2f79f6 100644 --- a/src/platform/graphics/texture.js +++ b/src/platform/graphics/texture.js @@ -140,8 +140,6 @@ class Texture { * - {@link TEXTURETYPE_SWIZZLEGGGR} * * Defaults to {@link TEXTURETYPE_DEFAULT}. - * @param {boolean} [options.fixCubemapSeams] - Specifies whether this cubemap texture requires - * special seam fixing shader code to look right. Defaults to false. * @param {boolean} [options.flipY] - Specifies whether the texture should be flipped in the * Y-direction. Only affects textures with a source that is an image, canvas or video element. * Does not affect cubemaps, compressed textures or textures set from raw pixel data. Defaults @@ -215,7 +213,6 @@ class Texture { this._storage = options.storage ?? false; this._cubemap = options.cubemap ?? false; - this.fixCubemapSeams = options.fixCubemapSeams ?? false; this._flipY = options.flipY ?? false; this._premultiplyAlpha = options.premultiplyAlpha ?? false; diff --git a/src/scene/graphics/env-lighting.js b/src/scene/graphics/env-lighting.js index 4df3f483931..dd6d9956616 100644 --- a/src/scene/graphics/env-lighting.js +++ b/src/scene/graphics/env-lighting.js @@ -9,8 +9,6 @@ import { } from '../../platform/graphics/constants.js'; import { DebugGraphics } from '../../platform/graphics/debug-graphics.js'; -const fixCubemapSeams = true; - // calculate the number of mipmap levels given texture dimensions const calcLevels = (width, height = 0) => { return 1 + Math.floor(Math.log2(Math.max(width, height))); @@ -46,7 +44,6 @@ const createCubemap = (device, size, format, mipmaps) => { type: format === PIXELFORMAT_RGBA8 ? RGBA8_TYPE : TEXTURETYPE_DEFAULT, addressU: ADDRESS_CLAMP_TO_EDGE, addressV: ADDRESS_CLAMP_TO_EDGE, - fixCubemapSeams: fixCubemapSeams, mipmaps: !!mipmaps }); }; @@ -108,7 +105,6 @@ class EnvLighting { type: format === PIXELFORMAT_RGBA8 ? RGBA8_TYPE : TEXTURETYPE_DEFAULT, addressU: ADDRESS_CLAMP_TO_EDGE, addressV: ADDRESS_CLAMP_TO_EDGE, - fixCubemapSeams: false, mipmaps: true }); diff --git a/src/scene/graphics/reproject-texture.js b/src/scene/graphics/reproject-texture.js index 1c8fc4a1a4d..4680b6d99f1 100644 --- a/src/scene/graphics/reproject-texture.js +++ b/src/scene/graphics/reproject-texture.js @@ -483,7 +483,6 @@ function reprojectTexture(source, target, options = {}) { constantSource.setValue(source); const constantParams = device.scope.resolve("params"); - const constantParams2 = device.scope.resolve("params2"); const uvModParam = device.scope.resolve("uvMod"); if (seamPixels > 0) { @@ -500,11 +499,6 @@ function reprojectTexture(source, target, options = {}) { const params = [ 0, specularPower, - source.fixCubemapSeams ? 1.0 / source.width : 0.0, // source seam scale - target.fixCubemapSeams ? 1.0 / target.width : 0.0 // target seam scale - ]; - - const params2 = [ target.width * target.height * (target.cubemap ? 6 : 1), source.width * source.height * (source.cubemap ? 6 : 1) ]; @@ -530,7 +524,6 @@ function reprojectTexture(source, target, options = {}) { }); params[0] = f; constantParams.setValue(params); - constantParams2.setValue(params2); drawQuadWithShader(device, renderTarget, shader, options?.rect); diff --git a/src/scene/materials/lit-material-options-builder.js b/src/scene/materials/lit-material-options-builder.js index 78b8df0e722..c8ff4ea4f74 100644 --- a/src/scene/materials/lit-material-options-builder.js +++ b/src/scene/materials/lit-material-options-builder.js @@ -99,7 +99,6 @@ class LitMaterialOptionsBuilder { litOptions.fog = material.useFog ? scene.fog : 'none'; litOptions.gamma = material.useGammaTonemap ? scene.gammaCorrection : GAMMA_NONE; litOptions.toneMap = material.useGammaTonemap ? scene.toneMapping : -1; - litOptions.fixSeams = false; // source of reflections if (material.useSkybox && scene.envAtlas && scene.skybox) { diff --git a/src/scene/materials/standard-material-options-builder.js b/src/scene/materials/standard-material-options-builder.js index b4e35897a46..03ce42a8748 100644 --- a/src/scene/materials/standard-material-options-builder.js +++ b/src/scene/materials/standard-material-options-builder.js @@ -301,7 +301,6 @@ class StandardMaterialOptionsBuilder { options.litOptions.fog = stdMat.useFog ? scene.fog : 'none'; options.litOptions.gamma = stdMat.useGammaTonemap ? scene.gammaCorrection : GAMMA_NONE; options.litOptions.toneMap = stdMat.useGammaTonemap ? scene.toneMapping : -1; - options.litOptions.fixSeams = (stdMat.cubeMap ? stdMat.cubeMap.fixCubemapSeams : false); const isPhong = stdMat.shadingModel === SPECULAR_PHONG; diff --git a/src/scene/materials/standard-material.js b/src/scene/materials/standard-material.js index 28734399252..027a2bb1a0c 100644 --- a/src/scene/materials/standard-material.js +++ b/src/scene/materials/standard-material.js @@ -993,9 +993,7 @@ function _defineTex2D(name, channel = "rgb", vertexColor = true, uv = 0) { defaultValue: null, dirtyShaderFunc: (oldValue, newValue) => { return !!oldValue !== !!newValue || - oldValue && (oldValue.type !== newValue.type || - oldValue.fixCubemapSeams !== newValue.fixCubemapSeams || - oldValue.format !== newValue.format); + oldValue && (oldValue.type !== newValue.type || oldValue.format !== newValue.format); } }); diff --git a/src/scene/shader-lib/chunks/chunks.js b/src/scene/shader-lib/chunks/chunks.js index 9057c42889e..7270c0677f2 100644 --- a/src/scene/shader-lib/chunks/chunks.js +++ b/src/scene/shader-lib/chunks/chunks.js @@ -45,8 +45,6 @@ import extensionPS from './lit/frag/extension.js'; import extensionVS from './lit/vert/extension.js'; import falloffInvSquaredPS from './lit/frag/falloffInvSquared.js'; import falloffLinearPS from './lit/frag/falloffLinear.js'; -import fixCubemapSeamsNonePS from './common/frag/fixCubemapSeamsNone.js'; -import fixCubemapSeamsStretchPS from './common/frag/fixCubemapSeamsStretch.js'; import floatUnpackingPS from './lit/frag/float-unpacking.js'; import fogExpPS from './lit/frag/fogExp.js'; import fogExp2PS from './lit/frag/fogExp2.js'; @@ -255,8 +253,6 @@ const shaderChunks = { extensionVS, falloffInvSquaredPS, falloffLinearPS, - fixCubemapSeamsNonePS, - fixCubemapSeamsStretchPS, floatUnpackingPS, fogExpPS, fogExp2PS, diff --git a/src/scene/shader-lib/chunks/common/frag/fixCubemapSeamsNone.js b/src/scene/shader-lib/chunks/common/frag/fixCubemapSeamsNone.js deleted file mode 100644 index e3e735f4800..00000000000 --- a/src/scene/shader-lib/chunks/common/frag/fixCubemapSeamsNone.js +++ /dev/null @@ -1,21 +0,0 @@ -export default /* glsl */` -vec3 fixSeams(vec3 vec, float mipmapIndex) { - return vec; -} - -vec3 fixSeams(vec3 vec) { - return vec; -} - -vec3 fixSeamsStatic(vec3 vec, float invRecMipSize) { - return vec; -} - -vec3 calcSeam(vec3 vec) { - return vec3(0); -} - -vec3 applySeam(vec3 vec, vec3 seam, float scale) { - return vec; -} -`; diff --git a/src/scene/shader-lib/chunks/common/frag/fixCubemapSeamsStretch.js b/src/scene/shader-lib/chunks/common/frag/fixCubemapSeamsStretch.js deleted file mode 100644 index c7ff02d0141..00000000000 --- a/src/scene/shader-lib/chunks/common/frag/fixCubemapSeamsStretch.js +++ /dev/null @@ -1,43 +0,0 @@ -export default /* glsl */` -vec3 fixSeams(vec3 vec, float mipmapIndex) { - vec3 avec = abs(vec); - float scale = 1.0 - exp2(mipmapIndex) / 128.0; - float M = max(max(avec.x, avec.y), avec.z); - if (avec.x != M) vec.x *= scale; - if (avec.y != M) vec.y *= scale; - if (avec.z != M) vec.z *= scale; - return vec; -} - -vec3 fixSeams(vec3 vec) { - vec3 avec = abs(vec); - float scale = 1.0 - 1.0 / 128.0; - float M = max(max(avec.x, avec.y), avec.z); - if (avec.x != M) vec.x *= scale; - if (avec.y != M) vec.y *= scale; - if (avec.z != M) vec.z *= scale; - return vec; -} - -vec3 fixSeamsStatic(vec3 vec, float invRecMipSize) { - vec3 avec = abs(vec); - float scale = invRecMipSize; - float M = max(max(avec.x, avec.y), avec.z); - if (avec.x != M) vec.x *= scale; - if (avec.y != M) vec.y *= scale; - if (avec.z != M) vec.z *= scale; - return vec; -} - -vec3 calcSeam(vec3 vec) { - vec3 avec = abs(vec); - float M = max(avec.x, max(avec.y, avec.z)); - return vec3(avec.x != M ? 1.0 : 0.0, - avec.y != M ? 1.0 : 0.0, - avec.z != M ? 1.0 : 0.0); -} - -vec3 applySeam(vec3 vec, vec3 seam, float scale) { - return vec * (seam * -scale + vec3(1.0)); -} -`; diff --git a/src/scene/shader-lib/chunks/common/frag/reproject.js b/src/scene/shader-lib/chunks/common/frag/reproject.js index a0963738cbe..d89548ac901 100644 --- a/src/scene/shader-lib/chunks/common/frag/reproject.js +++ b/src/scene/shader-lib/chunks/common/frag/reproject.js @@ -32,22 +32,14 @@ varying vec2 vUv0; // params: // x - target cubemap face 0..6 // y - specular power (when prefiltering) -// z - source cubemap seam scale (0 to disable) -// w - target cubemap size for seam calc (0 to disable) +// z - target image total pixels +// w - source cubemap size uniform vec4 params; -// params2: -// x - target image total pixels -// y - source cubemap size -uniform vec2 params2; - float targetFace() { return params.x; } float specularPower() { return params.y; } -float sourceCubeSeamScale() { return params.z; } -float targetCubeSeamScale() { return params.w; } - -float targetTotalPixels() { return params2.x; } -float sourceTotalPixels() { return params2.y; } +float targetTotalPixels() { return params.z; } +float sourceTotalPixels() { return params.w; } float PI = 3.141592653589793; @@ -122,7 +114,7 @@ vec2 octEncode(in vec3 v) { #ifdef CUBEMAP_SOURCE vec4 sampleCubemap(vec3 dir) { - return textureCube(sourceCube, modifySeams(dir, 1.0 - sourceCubeSeamScale())); + return textureCube(sourceCube, modifySeams(dir, 1.0)); } vec4 sampleCubemap(vec2 sph) { @@ -130,7 +122,7 @@ vec2 octEncode(in vec3 v) { } vec4 sampleCubemap(vec3 dir, float mipLevel) { - return textureCubeLodEXT(sourceCube, modifySeams(dir, 1.0 - exp2(mipLevel) * sourceCubeSeamScale()), mipLevel); + return textureCubeLodEXT(sourceCube, modifySeams(dir, 1.0), mipLevel); } vec4 sampleCubemap(vec2 sph, float mipLevel) { @@ -195,7 +187,7 @@ vec3 getDirectionCubemap() { vec = vec3(-st.x, -st.y, -1); } - return normalize(modifySeams(vec, 1.0 / (1.0 - targetCubeSeamScale()))); + return normalize(modifySeams(vec, 1.0)); } mat3 matrixFromVector(vec3 n) { // frisvad diff --git a/src/scene/shader-lib/chunks/lit/frag/reflectionCube.js b/src/scene/shader-lib/chunks/lit/frag/reflectionCube.js index a188064eebb..37e7f98ab43 100644 --- a/src/scene/shader-lib/chunks/lit/frag/reflectionCube.js +++ b/src/scene/shader-lib/chunks/lit/frag/reflectionCube.js @@ -3,7 +3,7 @@ uniform samplerCube texture_cubeMap; uniform float material_reflectivity; vec3 calcReflection(vec3 reflDir, float gloss) { - vec3 lookupVec = fixSeams(cubeMapProject(reflDir)); + vec3 lookupVec = cubeMapProject(reflDir); lookupVec.x *= -1.0; return $DECODE(textureCube(texture_cubeMap, lookupVec)); } diff --git a/src/scene/shader-lib/chunks/lit/frag/reflectionEnvHQ.js b/src/scene/shader-lib/chunks/lit/frag/reflectionEnvHQ.js index 1782a2660a5..10e513c289a 100644 --- a/src/scene/shader-lib/chunks/lit/frag/reflectionEnvHQ.js +++ b/src/scene/shader-lib/chunks/lit/frag/reflectionEnvHQ.js @@ -15,7 +15,7 @@ vec3 calcReflection(vec3 reflDir, float gloss) { float ilevel = floor(level); float flevel = level - ilevel; - vec3 sharp = $DECODE_CUBEMAP(textureCube(texture_cubeMap, fixSeams(dir))); + vec3 sharp = $DECODE_CUBEMAP(textureCube(texture_cubeMap, dir)); vec3 roughA = $DECODE(texture2D(texture_envAtlas, mapRoughnessUv(uv, ilevel))); vec3 roughB = $DECODE(texture2D(texture_envAtlas, mapRoughnessUv(uv, ilevel + 1.0))); diff --git a/src/scene/shader-lib/chunks/skybox/frag/skyboxHDR.js b/src/scene/shader-lib/chunks/skybox/frag/skyboxHDR.js index a08c59c46a6..288ed91a278 100644 --- a/src/scene/shader-lib/chunks/skybox/frag/skyboxHDR.js +++ b/src/scene/shader-lib/chunks/skybox/frag/skyboxHDR.js @@ -26,7 +26,7 @@ void main(void) { #endif dir.x *= -1.0; - vec3 linear = SKYBOX_DECODE_FNC(textureCube(texture_cubeMap, fixSeamsStatic(dir, SKYBOX_MIP))); + vec3 linear = SKYBOX_DECODE_FNC(textureCube(texture_cubeMap, dir)); gl_FragColor = vec4(gammaCorrectOutput(toneMap(processEnvironment(linear))), 1.0); } `; diff --git a/src/scene/shader-lib/programs/lit-shader-options.js b/src/scene/shader-lib/programs/lit-shader-options.js index 85b20ca67e2..c44e4014c40 100644 --- a/src/scene/shader-lib/programs/lit-shader-options.js +++ b/src/scene/shader-lib/programs/lit-shader-options.js @@ -266,14 +266,6 @@ class LitShaderOptions { */ toneMap = -1; - /** - * If cubemaps require seam fixing (see the `fixCubemapSeams` property of the options object - * passed to the {@link Texture} constructor). - * - * @type {boolean} - */ - fixSeams = false; - /** * One of "envAtlasHQ", "envAtlas", "cubeMap", "sphereMap". * diff --git a/src/scene/shader-lib/programs/lit-shader.js b/src/scene/shader-lib/programs/lit-shader.js index 028dc6a85d2..24d02b8e748 100644 --- a/src/scene/shader-lib/programs/lit-shader.js +++ b/src/scene/shader-lib/programs/lit-shader.js @@ -780,7 +780,6 @@ class LitShader { } if (options.reflectionSource === 'envAtlasHQ') { - func.append(options.fixSeams ? chunks.fixCubemapSeamsStretchPS : chunks.fixCubemapSeamsNonePS); func.append(chunks.envAtlasPS); func.append(chunks.reflectionEnvHQPS .replace(/\$DECODE_CUBEMAP/g, ChunkUtils.decodeFunc(options.reflectionCubemapEncoding)) @@ -790,7 +789,6 @@ class LitShader { func.append(chunks.envAtlasPS); func.append(chunks.reflectionEnvPS.replace(/\$DECODE/g, ChunkUtils.decodeFunc(options.reflectionEncoding))); } else if (options.reflectionSource === 'cubeMap') { - func.append(options.fixSeams ? chunks.fixCubemapSeamsStretchPS : chunks.fixCubemapSeamsNonePS); func.append(chunks.reflectionCubePS.replace(/\$DECODE/g, ChunkUtils.decodeFunc(options.reflectionEncoding))); } else if (options.reflectionSource === 'sphereMap') { func.append(chunks.reflectionSpherePS.replace(/\$DECODE/g, ChunkUtils.decodeFunc(options.reflectionEncoding))); diff --git a/src/scene/shader-lib/programs/skybox.js b/src/scene/shader-lib/programs/skybox.js index fbe7141b035..6b32c7f40db 100644 --- a/src/scene/shader-lib/programs/skybox.js +++ b/src/scene/shader-lib/programs/skybox.js @@ -6,8 +6,6 @@ import { ShaderUtils } from '../../../platform/graphics/shader-utils.js'; import { ShaderGenerator } from './shader-generator.js'; import { SKYTYPE_INFINITE } from '../../constants.js'; -const mip2size = [128, 64, /* 32 */ 16, 8, 4, 2]; - const fShader = ` #include "decodePS" #include "gamma" @@ -15,7 +13,6 @@ const fShader = ` #include "envMultiplyPS" #ifdef SKY_CUBEMAP - #include "cubemapSeams" #include "skyboxHDRPS" #else #include "sphericalPS" @@ -38,7 +35,6 @@ class ShaderGeneratorSkybox extends ShaderGenerator { if (options.skymesh !== SKYTYPE_INFINITE) defines.set('SKYMESH', ''); if (options.type === 'cubemap') { defines.set('SKY_CUBEMAP', ''); - defines.set('SKYBOX_MIP', (1 - 1 / mip2size[options.mip]).toString()); } // includes @@ -49,7 +45,6 @@ class ShaderGeneratorSkybox extends ShaderGenerator { includes.set('envMultiplyPS', shaderChunks.envMultiplyPS); if (options.type === 'cubemap') { - includes.set('cubemapSeams', options.mip ? shaderChunks.fixCubemapSeamsStretchPS : shaderChunks.fixCubemapSeamsNonePS); includes.set('skyboxHDRPS', shaderChunks.skyboxHDRPS); } else { includes.set('sphericalPS', shaderChunks.sphericalPS); diff --git a/src/scene/skybox/sky-mesh.js b/src/scene/skybox/sky-mesh.js index 3b1152671ea..1a5149fd3da 100644 --- a/src/scene/skybox/sky-mesh.js +++ b/src/scene/skybox/sky-mesh.js @@ -45,8 +45,7 @@ class SkyMesh { if (texture.cubemap) { options.type = 'cubemap'; - options.mip = texture.fixCubemapSeams ? scene.skyboxMip : 0; - options.fixSeams = texture.fixCubemapSeams; + options.mip = scene.skyboxMip; } else { options.type = 'envAtlas'; }