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

upload property from asset #16281

Merged
merged 7 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 4 additions & 0 deletions cocos/asset/assets/effect-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Asset } from './asset';
import { cclegacy, warnID } from '../../core';
import { ProgramLibrary } from '../../rendering/custom/private';
import { addEffectDefaultProperties, getCombinationDefines } from '../../render-scene/core/program-utils';
import { MaterialPropertyFull } from './material';

export declare namespace EffectAsset {
export interface IPropertyInfo {
Expand Down Expand Up @@ -324,6 +325,9 @@ export class EffectAsset extends Asset {
@editorOnly
public hideInEditor = false;

@serializable
public props: Record<string, MaterialPropertyFull | MaterialPropertyFull[]>[] = [];

/**
* @en The loaded callback which should be invoked by the [[AssetManager]], will automatically register the effect.
* @zh 通过 [[AssetManager]] 加载完成时的回调,将自动注册 effect 资源。
Expand Down
3 changes: 2 additions & 1 deletion cocos/asset/assets/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
* @param passIdx @en The pass to apply to. Will apply to all passes if not specified. @zh 要重编的 pass 索引,如果没有指定,则重编所有 pass。
*/
public recompileShaders (overrides: MacroRecord, passIdx?: number): void {
console.warn(`Shaders in material asset '${this.name}' cannot be modified at runtime, please instantiate the material first.`);

Check failure on line 253 in cocos/asset/assets/material.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected console statement
}

/**
Expand All @@ -260,7 +260,7 @@
* @param passIdx The pass to apply to. Will apply to all passes if not specified.
*/
public overridePipelineStates (overrides: PassOverrides, passIdx?: number): void {
console.warn(`Pipeline states in material asset '${this.name}' cannot be modified at runtime, please instantiate the material first.`);

Check failure on line 263 in cocos/asset/assets/material.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected console statement
}

/**
Expand Down Expand Up @@ -312,7 +312,7 @@
}
}
} else {
if (passIdx >= this._passes.length) { console.warn(`illegal pass index: ${passIdx}.`); return; }

Check failure on line 315 in cocos/asset/assets/material.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected console statement
const pass = this._passes[passIdx];
if (this._uploadProperty(pass, name, val)) {
this._props[pass.propertyIndex][name] = val;
Expand All @@ -320,7 +320,7 @@
}
}
if (!success) {
console.warn(`illegal property name: ${name}.`);

Check failure on line 323 in cocos/asset/assets/material.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected console statement
}
}

Expand Down Expand Up @@ -348,7 +348,7 @@
if (name in props) { return props[name]; }
}
} else {
if (passIdx >= this._passes.length) { console.warn(`illegal pass index: ${passIdx}.`); return null; }

Check failure on line 351 in cocos/asset/assets/material.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected console statement
const props = this._props[this._passes[passIdx].propertyIndex];
if (name in props) { return props[name]; }
}
Expand Down Expand Up @@ -428,7 +428,7 @@
Object.assign(defines, passInfo.embeddedMacros);
}
if (passInfo.switch && !defines[passInfo.switch]) { continue; }
const pass = new Pass(cclegacy.director.root);

Check failure on line 431 in cocos/asset/assets/material.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Root`
pass.initialize(passInfo);
passes.push(pass);
}
Expand All @@ -448,8 +448,9 @@
this._passes.forEach((pass, i): void => {
let props = this._props[i];
if (!props) { props = this._props[i] = {}; }
Object.assign(props, this._effectAsset!.props[i]);
xubing0906 marked this conversation as resolved.
Show resolved Hide resolved
if (pass.propertyIndex !== undefined) {
Object.assign(props, this._props[pass.propertyIndex]);
Object.assign(props, this._props[pass.propertyIndex], this._effectAsset!.props[pass.propertyIndex]);
}
for (const p in props) {
this._uploadProperty(pass, p, props[p]);
Expand All @@ -469,7 +470,7 @@
const handle = pass.getHandle(name);
if (!handle) { return false; }
const type = Pass.getTypeFromHandle(handle);
if (type < Type.SAMPLER1D) {

Check failure on line 473 in cocos/asset/assets/material.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type
if (Array.isArray(val)) {
pass.setUniformArray(handle, val as MaterialProperty[]);
} else if (val !== null) {
Expand Down
1 change: 1 addition & 0 deletions cocos/render-scene/core/pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export class Pass {
const value = info && info.value;
const texName = value ? `${value as string}${getStringFromType(type)}` : getDefaultFromType(type) as string;
const textureBase = builtinResMgr.get<TextureBase>(texName);
if (!textureBase) return;
const texture = textureBase && textureBase.getGFXTexture()!;
const samplerInfo = info && info.samplerHash !== undefined
? Sampler.unpackFromHash(info.samplerHash) : textureBase && textureBase.getSamplerInfo();
Expand Down
Loading