Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove handling of WebGL1 seamless cubemap sampling #6356

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/framework/handlers/cubemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/platform/graphics/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 0 additions & 4 deletions src/scene/graphics/env-lighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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
});
};
Expand Down Expand Up @@ -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
});

Expand Down
7 changes: 0 additions & 7 deletions src/scene/graphics/reproject-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
];
Expand All @@ -530,7 +524,6 @@ function reprojectTexture(source, target, options = {}) {
});
params[0] = f;
constantParams.setValue(params);
constantParams2.setValue(params2);

drawQuadWithShader(device, renderTarget, shader, options?.rect);

Expand Down
1 change: 0 additions & 1 deletion src/scene/materials/lit-material-options-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/scene/materials/standard-material-options-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions src/scene/materials/standard-material.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
4 changes: 0 additions & 4 deletions src/scene/shader-lib/chunks/chunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -255,8 +253,6 @@ const shaderChunks = {
extensionVS,
falloffInvSquaredPS,
falloffLinearPS,
fixCubemapSeamsNonePS,
fixCubemapSeamsStretchPS,
floatUnpackingPS,
fogExpPS,
fogExp2PS,
Expand Down
21 changes: 0 additions & 21 deletions src/scene/shader-lib/chunks/common/frag/fixCubemapSeamsNone.js

This file was deleted.

43 changes: 0 additions & 43 deletions src/scene/shader-lib/chunks/common/frag/fixCubemapSeamsStretch.js

This file was deleted.

22 changes: 7 additions & 15 deletions src/scene/shader-lib/chunks/common/frag/reproject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -122,15 +114,15 @@ 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) {
return sampleCubemap(fromSpherical(sph));
}

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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/scene/shader-lib/chunks/lit/frag/reflectionCube.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/scene/shader-lib/chunks/lit/frag/reflectionEnvHQ.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down
2 changes: 1 addition & 1 deletion src/scene/shader-lib/chunks/skybox/frag/skyboxHDR.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
`;
8 changes: 0 additions & 8 deletions src/scene/shader-lib/programs/lit-shader-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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".
*
Expand Down
2 changes: 0 additions & 2 deletions src/scene/shader-lib/programs/lit-shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)));
Expand Down
5 changes: 0 additions & 5 deletions src/scene/shader-lib/programs/skybox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ 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"
#include "tonemapping"
#include "envMultiplyPS"

#ifdef SKY_CUBEMAP
#include "cubemapSeams"
#include "skyboxHDRPS"
#else
#include "sphericalPS"
Expand All @@ -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
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/scene/skybox/sky-mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down