8000 Support sRGB color space by zhuxudong · Pull Request #2593 · galacean/engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support sRGB color space #2593

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

Merged
merged 82 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
323b2f4
fix: the output by skybox should in gamma space
zhuxudong Mar 18, 2025
b2035a2
feat: support sRGB
zhuxudong Mar 19, 2025
ea85349
feat: add sRGB compatible function in common glsl
zhuxudong Mar 19, 2025
99cb337
feat: some built-in textures use sRGB directly in shader
zhuxudong Mar 19, 2025
39c254f
feat: add isSRGBColorSpace param in texture loader
zhuxudong Mar 20, 2025
c60e630
feat: set sRGB textures in glTF
zhuxudong Mar 20, 2025
2e290fe
feat: use sRGB in text/sprite/ui
zhuxudong Mar 20, 2025
2e80a4b
feat: add sRGB in editor decoder
zhuxudong Mar 20, 2025
9343ffb
feat: support sRGB in KTX2
zhuxudong Mar 20, 2025
b533585
fix: ci error
zhuxudong Mar 20, 2025
29f4dbf
chore: add sRGB plugin detect
zhuxudong Mar 21, 2025
2186ecc
feat: parse texture after material
zhuxudong Mar 21, 2025
d0f5448
fix: editor remap material need know textures[index]'s sRGB color space
zhuxudong Mar 25, 2025
9182cc8
fix: sRGB test
zhuxudong Mar 25, 2025
118684b
ci: add e2e test
zhuxudong Mar 25, 2025
37feebd
fix: dirt should be sRGB color space
zhuxudong Mar 25, 2025
2b889ee
ci: type error
zhuxudong Mar 25, 2025
5f4169e
feat: gamma correction
zhuxudong Mar 26, 2025
d42a359
feat: add render context macro
zhuxudong Mar 26, 2025
2eac0a8
fix: use linear color space in BTDF
zhuxudong Mar 26, 2025
bc189d3
fix: use linear clear color in FBO
zhuxudong Mar 26, 2025
e9a5e2e
fix: e2e case
zhuxudong Mar 26, 2025
80d7fdc
fix: copy sRGB texture
zhuxudong Mar 26, 2025
5ebc63f
fix: name error
zhuxudong Mar 26, 2025
e2417f4
fix: engine destroy error
zhuxudong Mar 26, 2025
f040d7f
fix: destroy error
zhuxudong Mar 26, 2025
9679f8c
fix: color math error
zhuxudong Mar 26, 2025
101a24c
Merge branch 'dev/1.5' into feat/sRGB
zhuxudong Mar 27, 2025
ff59518
fix: readPixels format error
zhuxudong Mar 27, 2025
79d7632
refactor: set default sRGB color space
zhuxudong Mar 31, 2025
df13e4e
refactor: use blit screen material to enhance code
zhuxudong Apr 2, 2025
1229057
refactor: enhance blitter logic
zhuxudong Apr 2, 2025
5cffc2f
refactor: use engine space
zhuxudong Apr 2, 2025
0a66dff
refactor: srgb shader function
zhuxudong Apr 2, 2025
45f4286
refactor: update e2e case
zhuxudong Apr 2, 2025
2cb5124
refactor: rename
zhuxudong Apr 2, 2025
ffac36c
refactor: rename
zhuxudong Apr 2, 2025
edcd108
refactor: format code
zhuxudong Apr 2, 2025
ae8d810
refactor: rename
zhuxudong Apr 2, 2025
3a2825c
refactor: opt code
GuoLei1990 Apr 2, 2025
a2b8cfc
refactor: opt code
GuoLei1990 Apr 2, 2025
3743392
refactor: opt code
GuoLei1990 Apr 2, 2025
0d67cc4
refactor: opt code
zhuxudong Apr 2, 2025
757aca3
fix: don't clear color in blitframebuffer
zhuxudong Apr 2, 2025
a4383f9
refactor: opt code
zhuxudong Apr 2, 2025
a38abef
refactor: code format
zhuxudong Apr 2, 2025
5e60ec9
refactor: code format
zhuxudong Apr 2, 2025
4fedb4b
fix: use sRGB color space to down/up sample
zhuxudong Apr 3, 2025
6ff0baa
refactor: use sRGB color space when camera.enableHDR === false
zhuxudong Apr 3, 2025
17b99fd
refactor: revert logic
zhuxudong Apr 3, 2025
442c7f2
refactor: opt code
GuoLei1990 Apr 3, 2025
6b5eb86
refactor: clamp 0 in Common.glsl
zhuxudong Apr 7, 2025
a6b19da
refactor: add comments
zhuxudong Apr 7, 2025
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
3 changes: 1 addition & 2 deletions e2e/case/animator-blendShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
rootEntity.addChild(defaultSceneRoot);
const animator = defaultSceneRoot.getComponent(Animator);
const skinMeshRenderer = defaultSceneRoot.getComponent(SkinnedMeshRenderer);

skinMeshRenderer.blendShapeWeights[0] = 1.0;
animator.play("TheWave");
updateForE2E(engine);

updateForE2E(engine);

Check warning on line 45 in e2e/case/animator-blendShape.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/animator-blendShape.ts#L45

Added line #L45 was not covered by tests
initScreenshot(engine, camera);
});
});
3 changes: 1 addition & 2 deletions e2e/case/camera-opaque-texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const renderOpaqueFS = `

void main() {
vec4 baseColor = texture2D(camera_OpaqueTexture, v_uv);
baseColor = gammaToLinear(baseColor);

gl_FragColor = baseColor;

Expand All @@ -105,7 +104,7 @@ const renderOpaqueFS = `

#include <FogFragment>

gl_FragColor = linearToGamma(gl_FragColor);
gl_FragColor = outputSRGBCorrection(gl_FragColor);
}`;

Shader.create("RenderOpaqueTexture", renderOpaqueVS, renderOpaqueFS);
5 changes: 4 additions & 1 deletion e2e/case/material-blinn-phong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
},
{
type: AssetType.Texture2D,
url: "https://gw.alipayobjects.com/mdn/rms_7c464e/afts/img/A*H7nMRY2SuWcAAAAAAAAAAAAAARQnAQ"
url: "https://gw.alipayobjects.com/mdn/rms_7c464e/afts/img/A*H7nMRY2SuWcAAAAAAAAAAAAAARQnAQ",
params: {
isSRGBColorSpace: false
}

Check warning on line 50 in e2e/case/material-blinn-phong.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/material-blinn-phong.ts#L47-L50

Added lines #L47 - L50 were not covered by tests
},
{
type: AssetType.GLTF,
Expand Down
2 changes: 1 addition & 1 deletion e2e/case/material-shaderReplacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function initShader() {

void main() {
vec4 textureColor = texture2D(u_UVCheckTexture, v_uv);
gl_FragColor = textureColor;
gl_FragColor = outputSRGBCorrection(textureColor);
}
`;

Expand Down
6 changes: 2 additions & 4 deletions e2e/case/particleRenderer-dream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
ParticleRenderer,
Texture2D,
Vector3,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

// Create engine
WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: { webGLMode: WebGLMode.WebGL1 }
canvas: "canvas"

Check warning on line 27 in e2e/case/particleRenderer-dream.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/particleRenderer-dream.ts#L27

Added line #L27 was not covered by tests
}).then((engine) => {
Logger.enable();
engine.canvas.resizeByClientSize();
Expand Down
8 changes: 4 additions & 4 deletions e2e/case/project-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import { Logger, WebGLEngine, AssetType, Camera } from "@galacean/engine";
import { ShaderLab } from "@galacean/engine-shaderlab";
import { registerIncludes } from "@galacean/engine-toolkit";
import { registerIncludes } from "@galacean/engine-shader-shaderlab";

Check warning on line 7 in e2e/case/project-loader.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/project-loader.ts#L7

Added line #L7 was not covered by tests
import { initScreenshot, updateForE2E } from "./.mockForE2E";

// Create ShaderLab
Expand All @@ -17,13 +17,13 @@
engine.resourceManager
.load({
type: AssetType.Project,
url: "https://mdn.alipayobjects.com/oasis_be/afts/file/A*o15SSopTBh0AAAAAAAAAAAAADkp5AQ/project.json"
url: "https://mdn.alipayobjects.com/oasis_be/afts/file/A*CbucQ5pF7wEAAAAAAAAAAAAAekp5AQ/project.json"

Check warning on line 20 in e2e/case/project-loader.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/project-loader.ts#L20

Added line #L20 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a Project with a custom Shader

})
.then(() => {
updateForE2E(engine);

const cameraEntity = engine.sceneManager.activeScene.findEntityByName("Camera");
const camera = cameraEntity.getComponent(Camera);

updateForE2E(engine);

Check warning on line 26 in e2e/case/project-loader.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/project-loader.ts#L26

Added line #L26 was not covered by tests
initScreenshot(engine, camera);
});
});
5 changes: 4 additions & 1 deletion e2e/case/spriteMask-customStencil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
{
// Mask texture
url: "https://gw.alipayobjects.com/mdn/rms_7c464e/afts/img/A*qyhFT5Un5AgAAAAAAAAAAAAAARQnAQ",
type: AssetType.Texture2D
type: AssetType.Texture2D,
params: {
isSRGBColorSpace: false
}

Check warning on line 50 in e2e/case/spriteMask-customStencil.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/spriteMask-customStencil.ts#L47-L50

Added lines #L47 - L50 were not covered by tests
}
])
.then((textures: Texture2D[]) => {
Expand Down
46 changes: 46 additions & 0 deletions e2e/case/texture-sRGB-KTX2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @title sRGB + KTX2
* @category Texture
*/
import {
AssetType,
Camera,
MeshRenderer,
PrimitiveMesh,
Texture2D,
UnlitMaterial,
Vector3,
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

Check warning on line 15 in e2e/case/texture-sRGB-KTX2.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/texture-sRGB-KTX2.ts#L14-L15

Added lines #L14 - L15 were not covered by tests

WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
engine.canvas.resizeByClientSize(2);
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();

Check warning on line 20 in e2e/case/texture-sRGB-KTX2.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/texture-sRGB-KTX2.ts#L17-L20

Added lines #L17 - L20 were not covered by tests

// camera
const cameraEntity = rootEntity.createChild("camera_node");
cameraEntity.transform.position = new Vector3(0, 0, 2);
const camera = cameraEntity.addComponent(Camera);

Check warning on line 25 in e2e/case/texture-sRGB-KTX2.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/texture-sRGB-KTX2.ts#L23-L25

Added lines #L23 - L25 were not covered by tests

engine.resourceManager
.load<Texture2D>({
url: "https://mdn.alipayobjects.com/oasis_be/afts/img/A*XmHPTYGREAIAAAAAAAAAAAAAekp5AQ/original/original.ktx2",
type: AssetType.KTX2
})
.then((texture: Texture2D) => {
const material = new UnlitMaterial(engine);
material.baseTexture = texture;

Check warning on line 34 in e2e/case/texture-sRGB-KTX2.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/texture-sRGB-KTX2.ts#L27-L34

Added lines #L27 - L34 were not covered by tests

engine.run();
const entity = rootEntity.createChild("mesh");
entity.transform.setRotation(0, 90, 0);
const meshRenderer = entity.addComponent(MeshRenderer);
meshRenderer.mesh = PrimitiveMesh.createSubdivisionSurfaceSphere(engine);
meshRenderer.setMaterial(material);

Check warning on line 41 in e2e/case/texture-sRGB-KTX2.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/texture-sRGB-KTX2.ts#L36-L41

Added lines #L36 - L41 we 10000 re not covered by tests

updateForE2E(engine);
initScreenshot(engine, camera);
});
});

Check warning on line 46 in e2e/case/texture-sRGB-KTX2.ts

View check run for this annotation

Codecov / codecov/patch

e2e/case/texture-sRGB-KTX2.ts#L43-L46

Added lines #L43 - L46 were not covered by tests
7 changes: 7 additions & 0 deletions e2e/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@
threshold: 0.2
}
},
Texture: {
sRGB: {
category: "Texture",
caseFileName: "texture-sRGB-KTX2",
threshold: 0.2
}
},

Check warning on line 145 in e2e/config.ts

View check run for this annotation

Codecov / codecov/patch

e2e/config.ts#L139-L145

Added lines #L139 - L145 were not covered by tests
Shadow: {
basic: {
category: "Shadow",
Expand Down
4 changes: 2 additions & 2 deletions e2e/fixtures/originImage/Advance_multi-camera-no-clear.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions e2e/fixtures/originImage/Advance_project-loader.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions e2e/fixtures/originImage/Animator_animator-blendShape.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions e2e/fixtures/originImage/Material_material-blendMode.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions e2e/fixtures/originImage/Texture_texture-sRGB-KTX2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@galacean/engine-toolkit": "^1.3.9",
"@galacean/engine-shaderlab": "workspace:*",
"@galacean/engine-shader-shaderlab": "workspace:*",
"@galacean/engine": "workspace:*",
"@galacean/engine-core": "workspace:*",
"@galacean/engine-loader": "workspace:*",
Expand Down
33 changes: 25 additions & 8 deletions packages/core/src/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
*/
mode: BackgroundMode = BackgroundMode.SolidColor;

/**
* Background solid color.
* @defaultValue `new Color(0.25, 0.25, 0.25, 1.0)`
* @remarks When `mode` is `BackgroundMode.SolidColor`, the property will take effects.
*/
solidColor: Color = new Color(0.25, 0.25, 0.25, 1.0);

/**
* Background sky.
* @remarks When `mode` is `BackgroundMode.Sky`, the property will take effects.
Expand All @@ -38,8 +31,27 @@
/** @internal */
_material: Material;

/** @internal */
_linearSolidColor = new Color();

private _solidColor = new Color(0.25, 0.25, 0.25, 1.0);
private _texture: Texture2D = null;

/**
* Background solid color.
* @defaultValue `new Color(0.25, 0.25, 0.25, 1.0)`
* @remarks When `mode` is `BackgroundMode.SolidColor`, the property will take effects.
*/
get solidColor(): Color {
return this._solidColor;
}

set solidColor(value: Color) {
if (value !== this._solidColor) {
this._solidColor.copyFrom(value);
}
}

Check warning on line 53 in packages/core/src/Background.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/Background.ts#L50-L53

Added lines #L50 - L53 were not covered by tests

/**
* Background texture.
* @remarks When `mode` is `BackgroundMode.Texture`, the property will take effects.
Expand Down Expand Up @@ -83,7 +95,6 @@
this._mesh = null;
this._material._addReferCount(-1);
this._material = null;
this.solidColor = null;
this.sky.destroy();
}

Expand All @@ -94,6 +105,12 @@
constructor(private _engine: Engine) {
this._initMesh(_engine);
this._initMaterial(_engine);

this._solidColor.toLinear(this._linearSolidColor);
// @ts-ignore
this.solidColor._onValueChanged = () => {
this.solidColor.toLinear(this._linearSolidColor);
};

Check warning on line 113 in packages/core/src/Background.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/Background.ts#L112-L113

Added lines #L112 - L113 were not covered by tests
}

/**
Expand Down
41 changes: 32 additions & 9 deletions packages/core/src/BasicResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class BasicResources {
readonly blitMesh: ModelMesh;
readonly flipYBlitMesh: ModelMesh;
readonly blitMaterial: Material;
readonly blitScreenMaterial: Material;

readonly whiteTexture2D: Texture2D;
readonly whiteTextureCube: TextureCube;
Expand Down Expand Up @@ -141,31 +142,52 @@ export class BasicResources {
blitMaterial.renderState.depthState.enabled = false;
blitMaterial.renderState.depthState.writeEnabled = false;

const blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
blitScreenMaterial._addReferCount(1);
blitScreenMaterial.renderState.depthState.enabled = false;
blitScreenMaterial.renderState.depthState.writeEnabled = false;

this.blitMaterial = blitMaterial;
this.blitScreenMaterial = blitScreenMaterial;

this.blitMesh = this._createBlitMesh(engine, vertices);
this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
this.blitMaterial = blitMaterial;

// Create white and magenta textures
const whitePixel = new Uint8Array([255, 255, 255, 255]);

this.whiteTexture2D = this._create1x1Texture(engine, TextureType.Texture2D, TextureFormat.R8G8B8A8, whitePixel);
this.whiteTextureCube = this._create1x1Texture(engine, TextureType.TextureCube, TextureFormat.R8G8B8A8, whitePixel);
this.whiteTexture2D = this._create1x1Texture(
engine,
TextureType.Texture2D,
TextureFormat.R8G8B8A8,
whitePixel,
true
);
this.whiteTextureCube = this._create1x1Texture(
engine,
TextureType.TextureCube,
TextureFormat.R8G8B8A8,
whitePixel,
true
);

const isWebGL2 = engine._hardwareRenderer.isWebGL2;
if (isWebGL2) {
this.whiteTexture2DArray = this._create1x1Texture(
engine,
TextureType.Texture2DArray,
TextureFormat.R8G8B8A8,
whitePixel
whitePixel,
true
);

const whitePixel32 = new Uint32Array([255, 255, 255, 255]);
this.uintWhiteTexture2D = this._create1x1Texture(
engine,
TextureType.Texture2D,
TextureFormat.R32G32B32A32_UInt,
whitePixel32
whitePixel32,
false
);
}

Expand Down Expand Up @@ -212,23 +234,24 @@ export class BasicResources {
engine: Engine,
type: TextureType,
format: TextureFormat,
pixel: Uint8Array | Uint32Array
pixel: Uint8Array | Uint32Array,
isSRGBColorSpace: boolean
): T {
let texture: Texture;

switch (type) {
case TextureType.Texture2D:
const texture2D = new Texture2D(engine, 1, 1, format, false);
const texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
texture2D.setPixelBuffer(pixel);
texture = texture2D;
break;
case TextureType.Texture2DArray:
const texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false);
const texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
texture2DArray.setPixelBuffer(0, pixel);
texture = texture2DArray;
break;
case TextureType.TextureCube:
const textureCube = new TextureCube(engine, 1, format, false);
const textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
for (let i = 0; i < 6; i++) {
textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ export class Camera extends Component {

// union scene and camera macro.
ShaderMacroCollection.unionCollection(
this.scene._globalShaderMacro,
this.scene.shaderData._macroCollection,
this.shaderData._macroCollection,
this._globalShaderMacro
);
Expand Down
Loading
0