Skip to content

Commit

Permalink
remove transparency check
Browse files Browse the repository at this point in the history
  • Loading branch information
plojo committed Jul 5, 2024
1 parent 4c35ed6 commit 40dd13e
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 112 deletions.
16 changes: 0 additions & 16 deletions Distribution/FudgeCore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2549,11 +2549,6 @@ declare namespace FudgeCore {
/** Support sorting of objects with transparency when rendering, render objects in the back first. When this component is used as a part of a {@link ParticleSystem}, try enabling this when disabling {@link ComponentParticleSystem.depthMask} */
sortForAlpha: boolean;
constructor(_material?: Material);
/**
* Returns true if the material has any areas (color or texture) with alpha < 1.
* ⚠️ CAUTION: Computionally expensive for textured materials, see {@link Texture.hasTransparency}
*/
get hasTransparency(): boolean;
serialize(): Serialization;
deserialize(_serialization: Serialization): Promise<Serializable>;
}
Expand Down Expand Up @@ -3564,11 +3559,6 @@ declare namespace FudgeCore {
* Makes this material reference the given {@link Coat} if it is compatible with the referenced {@link Shader}
*/
set coat(_coat: Coat);
/**
* Returns true if the material has any areas (color or texture) with alpha < 1.
* ⚠️ CAUTION: Computionally expensive for textured materials, see {@link Texture.hasTransparency}
*/
get hasTransparency(): boolean;
/**
* Creates a new {@link Coat} instance that is valid for the {@link Shader} referenced by this material
*/
Expand Down Expand Up @@ -8348,12 +8338,6 @@ declare namespace FudgeCore {
get mipmap(): MIPMAP;
set wrap(_wrap: WRAP);
get wrap(): WRAP;
/**
* Returns true if the texture has any texels with alpha < 1.
* ⚠️ CAUTION: Has to be recomputed whenever the texture/image data changes.
*/
get hasTransparency(): boolean;
protected set hasTransparency(_hasTransparency: boolean);
/**
* Returns the image source of this texture.
*/
Expand Down
46 changes: 1 addition & 45 deletions Distribution/FudgeCore.js

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions Source/Core/Component/ComponentMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ namespace FudgeCore {
// this.mutatorCoat = _material.getCoat().getMutatorForComponent();
}

/**
* Returns true if the material has any areas (color or texture) with alpha < 1.
* ⚠️ CAUTION: Computionally expensive for textured materials, see {@link Texture.hasTransparency}
*/
public get hasTransparency(): boolean {
return this.material?.hasTransparency || this.clrPrimary.a < 1;
}

//#region Transfer
public serialize(): Serialization {
Expand Down
9 changes: 0 additions & 9 deletions Source/Core/Material/Material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ namespace FudgeCore {
this.#coat = _coat;
}

/**
* Returns true if the material has any areas (color or texture) with alpha < 1.
* ⚠️ CAUTION: Computionally expensive for textured materials, see {@link Texture.hasTransparency}
*/
public get hasTransparency(): boolean {
let coat: CoatTextured = <CoatTextured>this.coat;
return coat.color?.a < 1 || coat.texture?.hasTransparency;
}

/**
* Creates a new {@link Coat} instance that is valid for the {@link Shader} referenced by this material
*/
Expand Down
35 changes: 0 additions & 35 deletions Source/Core/Texture/Texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ namespace FudgeCore {
#mipmap: MIPMAP = MIPMAP.CRISP;
#wrap: WRAP = WRAP.REPEAT;

#hasTransparency: boolean;

public constructor(_name: string = "Texture") {
super();
this.name = _name;
Expand All @@ -59,38 +57,6 @@ namespace FudgeCore {
return this.#wrap;
}

/**
* Returns true if the texture has any texels with alpha < 1.
* ⚠️ CAUTION: Has to be recomputed whenever the texture/image data changes.
*/
public get hasTransparency(): boolean { // Only tested for texImageSource of type HTMLImageElement and HTMLCanvasElement
if (this.#hasTransparency != null)
return this.#hasTransparency;

let imageData: ImageData;

if (this.texImageSource instanceof ImageData) {
imageData = this.texImageSource;
} else {
const canvas: HTMLCanvasElement = document.createElement('canvas');
canvas.width = this.texImageSource.width;
canvas.height = this.texImageSource.height;
const crc2: CanvasRenderingContext2D = canvas.getContext('2d');
crc2.drawImage(this.texImageSource, 0, 0);
imageData = crc2.getImageData(0, 0, this.texImageSource.width, this.texImageSource.height);
}

for (let i: number = 0; i < imageData.data.length; i += 4)
if (imageData.data[i + 3] < 255)
return this.#hasTransparency = true;

return this.#hasTransparency = false;
}

protected set hasTransparency(_hasTransparency: boolean) {
this.#hasTransparency = _hasTransparency;
}

/**
* Returns the image source of this texture.
*/
Expand Down Expand Up @@ -198,7 +164,6 @@ namespace FudgeCore {
return new Promise((_resolve, _reject) => {
this.image.addEventListener("load", () => {
this.renderData = null; // refresh render data on next draw call
this.hasTransparency = null; // reset transparency check
_resolve();
});
this.image.addEventListener("error", () => _reject());
Expand Down

0 comments on commit 40dd13e

Please sign in to comment.