diff --git a/cocos/core/animation/value-proxy-factories/uniform.ts b/cocos/core/animation/value-proxy-factories/uniform.ts index df1bde8913..87fe9c7a21 100644 --- a/cocos/core/animation/value-proxy-factories/uniform.ts +++ b/cocos/core/animation/value-proxy-factories/uniform.ts @@ -30,7 +30,7 @@ import { SpriteFrame } from '../../../2d/assets/sprite-frame'; import { TextureBase } from '../../assets/texture-base'; import { deviceManager, Type } from '../../gfx'; import { Pass } from '../../renderer/core/pass'; -import { getDefaultFromType } from '../../renderer/core/pass-utils'; +import { getDefaultFromType, getStringFromType } from '../../renderer/core/pass-utils'; import { IValueProxy, IValueProxyFactory } from '../value-proxy'; import { warn } from '../../platform/debug'; import { legacyCC } from '../../global-exports'; @@ -102,7 +102,7 @@ export class UniformProxyFactory implements IValueProxyFactory { } else { const binding = Pass.getBindingFromHandle(handle); const prop = pass.properties[this.uniformName]; - const texName = prop && prop.value ? `${prop.value as string}-texture` : getDefaultFromType(prop.type) as string; + const texName = prop && prop.value ? `${prop.value as string}${getStringFromType(prop.type)}` : getDefaultFromType(prop.type) as string; let dftTex = builtinResMgr.get(texName); if (!dftTex) { warn(`Illegal texture default value: ${texName}.`); diff --git a/cocos/core/builtin/builtin-res-mgr.ts b/cocos/core/builtin/builtin-res-mgr.ts index d8592ace42..b6747fd08e 100644 --- a/cocos/core/builtin/builtin-res-mgr.ts +++ b/cocos/core/builtin/builtin-res-mgr.ts @@ -171,6 +171,7 @@ class BuiltinResMgr { // ============================ // builtin textures + // type string postfix according to getStringFromType() // ============================ // black texture @@ -187,7 +188,7 @@ class BuiltinResMgr { emptyTexture.image = emptyImgAsset; resources[emptyTexture._uuid] = emptyTexture; - // black texture + // black cube texture const blackCubeTexture = new TextureCube(); blackCubeTexture._uuid = 'black-cube-texture'; blackCubeTexture.setMipFilter(TextureCube.Filter.NEAREST); @@ -208,6 +209,20 @@ class BuiltinResMgr { greyTexture.image = greyImgAsset; resources[greyTexture._uuid] = greyTexture; + // grey cube texture + const greyCubeTexture = new TextureCube(); + greyCubeTexture._uuid = 'grey-cube-texture'; + greyCubeTexture.setMipFilter(TextureCube.Filter.NEAREST); + greyCubeTexture.image = { + front: new ImageAsset(greyMemImageSource), + back: new ImageAsset(greyMemImageSource), + left: new ImageAsset(greyMemImageSource), + right: new ImageAsset(greyMemImageSource), + top: new ImageAsset(greyMemImageSource), + bottom: new ImageAsset(greyMemImageSource), + }; + resources[greyCubeTexture._uuid] = greyCubeTexture; + // white texture const whiteImgAsset = new ImageAsset(whiteMemImageSource); const whiteTexture = new Texture2D(); diff --git a/cocos/core/renderer/core/pass-utils.ts b/cocos/core/renderer/core/pass-utils.ts index 48f38709c8..b336857742 100644 --- a/cocos/core/renderer/core/pass-utils.ts +++ b/cocos/core/renderer/core/pass-utils.ts @@ -108,11 +108,30 @@ export function getDefaultFromType (type: Type): readonly number[] | string { return 'default-texture'; case Type.SAMPLER_CUBE: return 'default-cube-texture'; + case Type.SAMPLER2D_ARRAY: + return 'default-array-texture'; + case Type.SAMPLER3D: + return 'default-3d-texture'; default: } return defaultValues[0]; } +export function getStringFromType (type: Type) : string { + switch (type) { + case Type.SAMPLER2D: + return '-texture'; + case Type.SAMPLER_CUBE: + return '-cube-texture'; + case Type.SAMPLER2D_ARRAY: + return '-array-texture'; + case Type.SAMPLER3D: + return '-3d-texture'; + default: + return '-unknown'; + } +} + /** * @en Combination of preprocess macros * @zh 预处理宏组合 diff --git a/cocos/core/renderer/core/pass.ts b/cocos/core/renderer/core/pass.ts index b5e21c8f3e..b6dd1c9bce 100644 --- a/cocos/core/renderer/core/pass.ts +++ b/cocos/core/renderer/core/pass.ts @@ -35,7 +35,7 @@ import { BufferUsageBit, DynamicStateFlagBit, DynamicStateFlags, Feature, GetTyp } from '../../gfx'; import { EffectAsset } from '../../assets/effect-asset'; import { IProgramInfo, programLib } from './program-lib'; -import { MacroRecord, MaterialProperty, customizeType, getBindingFromHandle, getDefaultFromType, +import { MacroRecord, MaterialProperty, customizeType, getBindingFromHandle, getDefaultFromType, getStringFromType, getOffsetFromHandle, getTypeFromHandle, type2reader, type2writer, getCountFromHandle, } from './pass-utils'; import { RenderPassStage, RenderPriority } from '../../pipeline/define'; @@ -429,7 +429,7 @@ export class Pass { const binding = Pass.getBindingFromHandle(handle); const info = this._properties[name]; const value = info && info.value; - const texName = value ? `${value as string}-texture` : getDefaultFromType(type) as string; + const texName = value ? `${value as string}${getStringFromType(type)}` : getDefaultFromType(type) as string; const textureBase = builtinResMgr.get(texName); const texture = textureBase && textureBase.getGFXTexture()!; const samplerInfo = info && info.samplerHash !== undefined diff --git a/native/cocos/core/builtin/BuiltinResMgr.cpp b/native/cocos/core/builtin/BuiltinResMgr.cpp index 71e0d4a47c..97a517be9b 100644 --- a/native/cocos/core/builtin/BuiltinResMgr.cpp +++ b/native/cocos/core/builtin/BuiltinResMgr.cpp @@ -167,6 +167,12 @@ bool BuiltinResMgr::initBuiltinRes() { // default texture initTexture2DWithUuid("default-texture", DEFAULT_IMAGE_RGBA_DATA_16X16, sizeof(DEFAULT_IMAGE_RGBA_DATA_16X16), 16, 16); + // black cube texture + initTextureCubeWithUuid("black-cube-texture", BLACK_IMAGE_RGBA_DATA_2X2, sizeof(BLACK_IMAGE_RGBA_DATA_2X2), 2, 2); + + // grey cube texture + initTextureCubeWithUuid("grey-cube-texture", GREY_IMAGE_RGBA_DATA_2X2, sizeof(GREY_IMAGE_RGBA_DATA_2X2), 2, 2); + // white cube texture initTextureCubeWithUuid("white-cube-texture", WHITE_IMAGE_RGBA_DATA_2X2, sizeof(WHITE_IMAGE_RGBA_DATA_2X2), 2, 2); diff --git a/native/cocos/renderer/core/PassUtils.cpp b/native/cocos/renderer/core/PassUtils.cpp index 89b2d3ea04..7c40f13240 100644 --- a/native/cocos/renderer/core/PassUtils.cpp +++ b/native/cocos/renderer/core/PassUtils.cpp @@ -263,6 +263,27 @@ const ccstd::string &getDefaultStringFromType(gfx::Type type) { } } +const ccstd::string &getStringFromType(gfx::Type type) { + static const ccstd::string TEXTURE_2D_STR{"-texture"}; + static const ccstd::string TEXTURE_CUBE_STR{"-cube-texture"}; + static const ccstd::string TEXTURE_2D_ARRAY_STR{"-array-texture"}; + static const ccstd::string TEXTURE_3D_STR{"-3d-texture"}; + static const ccstd::string UNKNOWN_STR{"-unknown"}; + + switch (type) { + case gfx::Type::SAMPLER2D: + return TEXTURE_2D_STR; + case gfx::Type::SAMPLER_CUBE: + return TEXTURE_CUBE_STR; + case gfx::Type::SAMPLER2D_ARRAY: + return TEXTURE_2D_ARRAY_STR; + case gfx::Type::SAMPLER3D: + return TEXTURE_3D_STR; + default: + return UNKNOWN_STR; + } +} + bool overrideMacros(MacroRecord &target, const MacroRecord &source) { bool isDifferent = false; for (const auto &p : source) { diff --git a/native/cocos/renderer/core/PassUtils.h b/native/cocos/renderer/core/PassUtils.h index 51456e1bff..3dae51412a 100644 --- a/native/cocos/renderer/core/PassUtils.h +++ b/native/cocos/renderer/core/PassUtils.h @@ -95,6 +95,7 @@ extern const ccstd::unordered_map type2writer; */ const ccstd::vector &getDefaultFloatArrayFromType(gfx::Type type); const ccstd::string &getDefaultStringFromType(gfx::Type type); +const ccstd::string &getStringFromType(gfx::Type type); /** * @en Combination of preprocess macros diff --git a/native/cocos/scene/Pass.cpp b/native/cocos/scene/Pass.cpp index 9f7b0a0a10..9a10424484 100644 --- a/native/cocos/scene/Pass.cpp +++ b/native/cocos/scene/Pass.cpp @@ -364,7 +364,7 @@ void Pass::resetTexture(const ccstd::string &name, uint32_t index) { info = &iter->second; ccstd::string *pStrVal = ccstd::get_if(&iter->second.value.value()); if (pStrVal != nullptr) { - texName = (*pStrVal) + "-texture"; + texName = (*pStrVal) + GetStringFromType(type); } } }