Skip to content

Commit

Permalink
getProperty to get material uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
zxx43 committed Sep 19, 2023
1 parent c58cb54 commit 648bf55
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions cocos/asset/assets/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { EffectAsset } from './effect-asset';
import { Texture, Type } from '../../gfx';
import { TextureBase } from './texture-base';
import { IPassInfoFull, Pass, PassOverrides } from '../../render-scene/core/pass';
import { MacroRecord, MaterialProperty } from '../../render-scene/core/pass-utils';
import { Color, warnID, Vec4, cclegacy } from '../../core';
import { MacroRecord, MaterialProperty, type2reader } from '../../render-scene/core/pass-utils';
import { Color, warnID, Vec4, cclegacy, Vec2, Vec3, Mat3, Mat4 } from '../../core';
import { SRGBToLinear } from '../../rendering/pipeline-funcs';
import { Renderer } from '../../misc/renderer';

Expand Down Expand Up @@ -352,6 +352,52 @@ export class Material extends Asset {
const props = this._props[this._passes[passIdx].propertyIndex];
if (name in props) { return props[name]; }
}
const passid = passIdx;
let pass: Pass | null = null;
if (passid !== undefined) {
pass = this._passes[passid];
} else {
for (let i = 0; i < this._passes.length; ++i) {
const handle = this._passes[i].getHandle(name);
if (handle !== 0) {
pass = this._passes[i];
break;
}
}
}
if (pass) {
const handle = pass.getHandle(name);
if (handle !== 0) {
const type = Pass.getTypeFromHandle(handle);
if (type2reader[type]) {
if (type as Type === Type.INT || type as Type === Type.FLOAT) {
const result: number = 0;
pass.getUniform(handle, result);
return result;
} else if (type as Type === Type.INT2 || type as Type === Type.FLOAT2) {
const result: Vec2 = new Vec2();
pass.getUniform(handle, result);
return result;
} else if (type as Type === Type.INT3 || type as Type === Type.FLOAT3) {
const result: Vec3 = new Vec3();
pass.getUniform(handle, result);
return result;
} else if (type as Type === Type.INT4 || type as Type === Type.FLOAT4) {
const result: Vec4 = new Vec4();
pass.getUniform(handle, result);
return result;
} else if (type as Type === Type.MAT3) {
const result: Mat3 = new Mat3();
pass.getUniform(handle, result);
return result;
} else if (type as Type === Type.MAT4) {
const result: Mat4 = new Mat4();
pass.getUniform(handle, result);
return result;
}
}
}
}
return null;
}

Expand Down

0 comments on commit 648bf55

Please sign in to comment.