Skip to content
Open
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
20 changes: 20 additions & 0 deletions src/core/renderers/CoreShaderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export class CoreShaderNode<Props extends object = Record<string, unknown>> {
protected node: CoreNode | null = null;
readonly time: CoreShaderType['time'] = undefined;
update: (() => void) | undefined = undefined;
private _valueKeyCache = '';
private _valueKeyDirty = true;
private _lastW = 0;
private _lastH = 0;

constructor(
readonly shaderKey: string,
Expand Down Expand Up @@ -141,6 +145,7 @@ export class CoreShaderNode<Props extends object = Record<string, unknown>> {
} else {
this.resolvedProps![key] = value;
}
this._valueKeyDirty = true;

if (this.update !== undefined && this.node !== null) {
this.node.setUpdateType(UpdateType.RecalcUniforms);
Expand All @@ -158,12 +163,27 @@ export class CoreShaderNode<Props extends object = Record<string, unknown>> {
}

createValueKey() {
if (
this._valueKeyDirty === false &&
this.node !== null &&
this.node.w === this._lastW &&
this.node.h === this._lastH
) {
return this._valueKeyCache;
}

let valueKey = '';
for (const key in this.resolvedProps) {
valueKey += `${key}:${this.resolvedProps[key]!};`;
}
valueKey += `node-width:${this.node!.w}`;
valueKey += `node-height:${this.node!.h}`;

this._valueKeyCache = valueKey;
this._valueKeyDirty = false;
this._lastW = this.node!.w;
this._lastH = this.node!.h;

return valueKey;
}

Expand Down