mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
[fix] default colored texture support for effect texture cube parameters (#12697)
This commit is contained in:
@@ -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<TextureBase>(texName);
|
||||
if (!dftTex) {
|
||||
warn(`Illegal texture default value: ${texName}.`);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 预处理宏组合
|
||||
|
||||
@@ -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<TextureBase>(texName);
|
||||
const texture = textureBase && textureBase.getGFXTexture()!;
|
||||
const samplerInfo = info && info.samplerHash !== undefined
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -95,6 +95,7 @@ extern const ccstd::unordered_map<gfx::Type, GFXTypeWriterCallback> type2writer;
|
||||
*/
|
||||
const ccstd::vector<float> &getDefaultFloatArrayFromType(gfx::Type type);
|
||||
const ccstd::string &getDefaultStringFromType(gfx::Type type);
|
||||
const ccstd::string &getStringFromType(gfx::Type type);
|
||||
|
||||
/**
|
||||
* @en Combination of preprocess macros
|
||||
|
||||
@@ -364,7 +364,7 @@ void Pass::resetTexture(const ccstd::string &name, uint32_t index) {
|
||||
info = &iter->second;
|
||||
ccstd::string *pStrVal = ccstd::get_if<ccstd::string>(&iter->second.value.value());
|
||||
if (pStrVal != nullptr) {
|
||||
texName = (*pStrVal) + "-texture";
|
||||
texName = (*pStrVal) + GetStringFromType(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user