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

Replace ui shader #30

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
2df50f9
feat: ui transform
cptbtptpbcptdtptp Jun 12, 2024
cf0643d
feat: update code
cptbtptpbcptdtptp Jun 17, 2024
22582e1
feat: merge code
cptbtptpbcptdtptp Jun 20, 2024
cdecbc5
feat: udpae code
cptbtptpbcptdtptp Jun 20, 2024
d3599b2
feat: update code
cptbtptpbcptdtptp Jun 20, 2024
9ed8451
feat: merge transform and uitransform
cptbtptpbcptdtptp Jun 26, 2024
ed65e2a
fix: merge code
cptbtptpbcptdtptp Aug 28, 2024
a04790f
fix: merge code
cptbtptpbcptdtptp Aug 28, 2024
ef86b49
feat: update code
cptbtptpbcptdtptp Aug 29, 2024
9a883be
Merge remote-tracking branch 'ck/feature/ui-init' into feature/ui-init
cptbtptpbcptdtptp Aug 30, 2024
0866129
feat: update ui input
cptbtptpbcptdtptp Sep 9, 2024
ff4bdb1
feat: update code
cptbtptpbcptdtptp Sep 19, 2024
75e4c83
feat: ui pointer event
cptbtptpbcptdtptp Sep 25, 2024
e87b7cd
feat: udpate code
cptbtptpbcptdtptp Oct 7, 2024
cc001f1
feat: merge code
cptbtptpbcptdtptp Oct 7, 2024
eea964a
feat: update code
cptbtptpbcptdtptp Oct 10, 2024
05f11da
feat: udpate code
cptbtptpbcptdtptp Oct 10, 2024
6c6be60
feat: udpate code
cptbtptpbcptdtptp Oct 10, 2024
c6cbdee
feat: update code
cptbtptpbcptdtptp Oct 10, 2024
8e70ce9
feat: update code
cptbtptpbcptdtptp Oct 10, 2024
c12b295
feat: update code
cptbtptpbcptdtptp Oct 11, 2024
9d90de5
feat: update code
cptbtptpbcptdtptp Oct 12, 2024
7abc773
feat: update code
cptbtptpbcptdtptp Oct 12, 2024
5c3c47d
feat: update code
cptbtptpbcptdtptp Oct 14, 2024
7f77234
feat: update code
cptbtptpbcptdtptp Oct 14, 2024
48f735c
feat: update code
cptbtptpbcptdtptp Oct 17, 2024
7aa2657
feat: update code
cptbtptpbcptdtptp Oct 20, 2024
0e36499
feat: update code
cptbtptpbcptdtptp Oct 21, 2024
f2158fc
feat: update code
cptbtptpbcptdtptp Oct 22, 2024
685e450
feat: update code
cptbtptpbcptdtptp Oct 22, 2024
45deb33
feat: update code
cptbtptpbcptdtptp Oct 22, 2024
fcb0994
feat: update code
cptbtptpbcptdtptp Oct 22, 2024
b30b2ee
feat: update code
cptbtptpbcptdtptp Oct 22, 2024
85a15fe
feat: merge code
cptbtptpbcptdtptp Oct 23, 2024
af4135d
feat: update code
cptbtptpbcptdtptp Oct 24, 2024
b61b9e7
feat: update code
cptbtptpbcptdtptp Oct 24, 2024
bb145d4
feat: update localbounds
cptbtptpbcptdtptp Oct 24, 2024
74de716
feat: update code
cptbtptpbcptdtptp Oct 27, 2024
49cc82a
feat: merge code
cptbtptpbcptdtptp Oct 27, 2024
c808352
feat: merge code
cptbtptpbcptdtptp Oct 27, 2024
c3c5568
feat: update code
cptbtptpbcptdtptp Oct 29, 2024
b154e57
feat: update ui code
cptbtptpbcptdtptp Nov 1, 2024
951b1a0
feat: udpate code
cptbtptpbcptdtptp Nov 4, 2024
4d930f2
feat: add button
cptbtptpbcptdtptp Nov 5, 2024
72be260
feat: add button
cptbtptpbcptdtptp Nov 5, 2024
c60fa0a
feat: update code
cptbtptpbcptdtptp Nov 5, 2024
f7ffd30
feat: update code
cptbtptpbcptdtptp Nov 5, 2024
7f25dc3
feat: update code
cptbtptpbcptdtptp Nov 6, 2024
c37bee4
feat: merge code
cptbtptpbcptdtptp Nov 6, 2024
a7249b3
feat: update code
cptbtptpbcptdtptp Nov 7, 2024
396656c
feat: update code
cptbtptpbcptdtptp Nov 7, 2024
5fea91f
feat: update code
cptbtptpbcptdtptp Nov 7, 2024
4e66663
feat: update code
cptbtptpbcptdtptp Nov 7, 2024
48d783d
feat: update code
cptbtptpbcptdtptp Nov 7, 2024
3b90739
feat: update code
cptbtptpbcptdtptp Nov 13, 2024
c0cf05a
feat: update code
cptbtptpbcptdtptp Nov 13, 2024
e68d510
feat: update code
cptbtptpbcptdtptp Nov 14, 2024
b385900
feat: update code
cptbtptpbcptdtptp Nov 18, 2024
7ba272c
feat: update code
cptbtptpbcptdtptp Nov 18, 2024
a09efd5
fix: lint error
cptbtptpbcptdtptp Nov 20, 2024
0a0155d
fix: lint error
cptbtptpbcptdtptp Nov 20, 2024
e12ff0b
fix: lint error
cptbtptpbcptdtptp Nov 20, 2024
3bd87bd
fix: lint error
cptbtptpbcptdtptp Nov 20, 2024
2860723
fix: lint error
cptbtptpbcptdtptp Nov 20, 2024
1eab47c
fix: lint error
cptbtptpbcptdtptp Nov 20, 2024
a7b232e
Merge remote-tracking branch 'ck/feature/ui-init' into feature/ui-init
cptbtptpbcptdtptp Dec 4, 2024
7bc504a
fix: udpate ui transform init
cptbtptpbcptdtptp Dec 5, 2024
dea19ce
Merge remote-tracking branch 'ck/feature/ui-init' into feature/ui-init
cptbtptpbcptdtptp Dec 6, 2024
8b8dab9
Merge branch 'feature/ui-init' of https://github.com/singlecoder/engi…
cptbtptpbcptdtptp Dec 12, 2024
0b3218d
feat: update code
cptbtptpbcptdtptp Dec 12, 2024
eb28c10
feat: update code
cptbtptpbcptdtptp Dec 13, 2024
7407f3e
feat: update code
cptbtptpbcptdtptp Dec 16, 2024
59782d3
feat: udpate code
cptbtptpbcptdtptp Dec 16, 2024
9f71641
feat: udpate code
cptbtptpbcptdtptp Dec 16, 2024
4d6b453
feat: update code
cptbtptpbcptdtptp Dec 16, 2024
d552ee8
feat: update code
cptbtptpbcptdtptp Dec 17, 2024
ae510a2
feat: merge code
cptbtptpbcptdtptp Dec 17, 2024
432c465
Merge remote-tracking branch 'ck/feature/ui-init' into feature/ui-init
cptbtptpbcptdtptp Dec 17, 2024
8ece555
feat: update code
cptbtptpbcptdtptp Dec 18, 2024
1eb88b5
feat: merge code
cptbtptpbcptdtptp Dec 18, 2024
1caa84d
feat: udpate code
cptbtptpbcptdtptp Dec 18, 2024
8527942
feat: update code
cptbtptpbcptdtptp Dec 19, 2024
4d3ae40
feat: update code
cptbtptpbcptdtptp Dec 23, 2024
7fb40e8
fix: merge code
cptbtptpbcptdtptp Dec 23, 2024
29446a9
feat: merge code
cptbtptpbcptdtptp Dec 24, 2024
6570a06
feat: merge code
cptbtptpbcptdtptp Dec 24, 2024
25e165d
feat: udpate code
cptbtptpbcptdtptp Dec 24, 2024
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
19 changes: 0 additions & 19 deletions packages/core/src/BasicResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class BasicResources {
readonly spriteDefaultMaterial: Material;
readonly textDefaultMaterial: Material;
readonly spriteMaskDefaultMaterial: Material;
readonly uiDefaultMaterial: Material;

constructor(engine: Engine) {
// prettier-ignore
Expand Down Expand Up @@ -166,7 +165,6 @@ export class BasicResources {
this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
this.uiDefaultMaterial = this._createUIMaterial(engine);
}

private _createBlitMesh(engine: Engine, vertices: Float32Array): ModelMesh {
Expand Down Expand Up @@ -267,23 +265,6 @@ export class BasicResources {
material.isGCIgnored = true;
return material;
}

private _createUIMaterial(engine: Engine): Material {
const material = new Material(engine, Shader.find("ui"));
const renderState = material.renderState;
const target = renderState.blendState.targetBlendState;
target.enabled = true;
target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
target.sourceAlphaBlendFactor = BlendFactor.One;
target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
renderState.depthState.writeEnabled = false;
renderState.rasterState.cullMode = CullMode.Off;
renderState.renderQueueType = RenderQueueType.Transparent;
material.isGCIgnored = true;
return material;
}
}

enum TextureType {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/RenderPipeline/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { BasicRenderPipeline, RenderQueueFlags } from "./BasicRenderPipeline";
export { BatchUtils } from "./BatchUtils";
export { Blitter } from "./Blitter";
export { PipelineStage } from "./enums/PipelineStage";
export { RenderQueue } from "./RenderQueue";
export { PipelineStage } from "./enums/PipelineStage";
3 changes: 0 additions & 3 deletions packages/core/src/shader/ShaderPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import spriteFs from "../shaderlib/extra/sprite.fs.glsl";
import spriteVs from "../shaderlib/extra/sprite.vs.glsl";
import textFs from "../shaderlib/extra/text.fs.glsl";
import textVs from "../shaderlib/extra/text.vs.glsl";
import uiDefaultFs from "../shaderlib/extra/uiDefault.fs.glsl";
import uiDefaultVs from "../shaderlib/extra/uiDefault.vs.glsl";
import unlitFs from "../shaderlib/extra/unlit.fs.glsl";
import unlitVs from "../shaderlib/extra/unlit.vs.glsl";
import { Shader } from "./Shader";
Expand Down Expand Up @@ -71,7 +69,6 @@ export class ShaderPool {
Shader.create("particle-shader", [new ShaderPass("Forward", particleVs, particleFs, forwardPassTags)]);
Shader.create("SpriteMask", [new ShaderPass("Forward", spriteMaskVs, spriteMaskFs, forwardPassTags)]);
Shader.create("Sprite", [new ShaderPass("Forward", spriteVs, spriteFs, forwardPassTags)]);
Shader.create("ui", [new ShaderPass("Forward", uiDefaultVs, uiDefaultFs, forwardPassTags)]);
Shader.create("Text", [new ShaderPass("Forward", textVs, textFs, forwardPassTags)]);
Shader.create("background-texture", [
new ShaderPass("Forward", backgroundTextureVs, backgroundTextureFs, forwardPassTags)
Expand Down
6 changes: 2 additions & 4 deletions packages/ui/src/component/advanced/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ export class Image extends UIRenderer implements ISpriteRenderer {
super(entity);

this.drawMode = SpriteDrawMode.Simple;
// @ts-ignore
this.setMaterial(this._engine._basicResources.uiDefaultMaterial);
this.setMaterial(this._engine._getUIDefaultMaterial());
this._onSpriteChange = this._onSpriteChange.bind(this);
//@ts-ignore
this._color._onValueChanged = this._onColorChange.bind(this);
Expand Down Expand Up @@ -223,8 +222,7 @@ export class Image extends UIRenderer implements ISpriteRenderer {
}
// @todo: This question needs to be raised rather than hidden.
if (material.destroyed) {
// @ts-ignore
material = this._engine._basicResources.uiDefaultMaterial;
material = this._engine._getUIDefaultMaterial();
}

if (this._color.a * this._alpha <= 0) {
Expand Down
54 changes: 53 additions & 1 deletion packages/ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { Entity } from "@galacean/engine";
import {
BlendFactor,
BlendOperation,
CullMode,
Engine,
Entity,
Material,
PipelineStage,
RenderQueueType,
Shader,
ShaderPass
} from "@galacean/engine";
import uiDefaultFs from "./shader/uiDefault.fs.glsl";
import uiDefaultVs from "./shader/uiDefault.vs.glsl";

export { UICanvas } from "./component/UICanvas";
export { UIGroup } from "./component/UIGroup";
export { UIRenderer } from "./component/UIRenderer";
Expand All @@ -14,6 +28,37 @@ export { CanvasRenderMode } from "./enums/CanvasRenderMode";
export { ResolutionAdaptationStrategy } from "./enums/ResolutionAdaptationStrategy";
export { UIPointerEventEmitter } from "./input/UIPointerEventEmitter";

export class EngineExtension {
_uiDefaultMaterial: Material;
_getUIDefaultMaterial(): Material {
if (!this._uiDefaultMaterial) {
const shader =
Shader.find("ui") ??
Shader.create("ui", [
new ShaderPass("Forward", uiDefaultVs, uiDefaultFs, {
pipelineStage: PipelineStage.Forward
})
]);
// @ts-ignore
const material = new Material(this, shader);
const renderState = material.renderState;
const target = renderState.blendState.targetBlendState;
target.enabled = true;
target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
target.sourceAlphaBlendFactor = BlendFactor.One;
target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
renderState.depthState.writeEnabled = false;
renderState.rasterState.cullMode = CullMode.Off;
renderState.renderQueueType = RenderQueueType.Transparent;
material.isGCIgnored = true;
this._uiDefaultMaterial = material;
}
return this._uiDefaultMaterial;
}
}

export class EntityExtension {
_uiHierarchyVersion = 0;
_updateUIHierarchyVersion(version: number): void {
Expand All @@ -26,6 +71,12 @@ export class EntityExtension {
}

declare module "@galacean/engine" {
interface Engine {
// @internal
_uiDefaultMaterial: Material;
// @internal
_getUIDefaultMaterial(): Material;
}
interface Entity {
// @internal
_uiHierarchyVersion: number;
Expand All @@ -46,4 +97,5 @@ function ApplyMixins(derivedCtor: any, baseCtors: any[]): void {
});
}

ApplyMixins(Engine, [EngineExtension]);
ApplyMixins(Entity, [EntityExtension]);
9 changes: 9 additions & 0 deletions packages/ui/src/shader/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module "*.glsl" {
const value: string;
export default value;
}

declare module "*.gs" {
const value: string;
export default value;
}
Loading