diff --git a/EngineErrorMap.md b/EngineErrorMap.md index dc66c95ed8..adfe5825a1 100644 --- a/EngineErrorMap.md +++ b/EngineErrorMap.md @@ -3367,4 +3367,12 @@ node '%s' doesn't have any ModelRenderer component, this component will not work ### 16302 -There is no reflection probe in the scene or no probe is near the current object. No reflection probe will take effect on this object. Please create a new reflection probe or move existing ones closer. \ No newline at end of file +There is no reflection probe in the scene or no probe is near the current object. No reflection probe will take effect on this object. Please create a new reflection probe or move existing ones closer. + +### 16303 + +Skin material needs floating-point render target, please check ENABLE_FLOAT_OUTPUT define in Project Settings--Macro + +### 16304 + +Skin material may need more accurate calculations, please select a head model of standard size, check the isGlobalStandardSkinObject option in the MeshRender component. \ No newline at end of file diff --git a/cocos/3d/framework/mesh-renderer.ts b/cocos/3d/framework/mesh-renderer.ts index 45a82fcf89..4786526279 100644 --- a/cocos/3d/framework/mesh-renderer.ts +++ b/cocos/3d/framework/mesh-renderer.ts @@ -876,7 +876,7 @@ export class MeshRenderer extends ModelRenderer { if (!mainLight) { return; } const visibility = mainLight.visibility; if (!mainLight.node) { return; } - + if (mainLight.node.mobility === MobilityMode.Static) { let forceClose = false; if (this.bakeSettings.texture && !this.node.scene.globals.disableLightmap) { @@ -885,7 +885,7 @@ export class MeshRenderer extends ModelRenderer { if (this.node.scene.globals.lightProbeInfo.data && this.node.scene.globals.lightProbeInfo.data.hasCoefficients() && this._model.useLightProbe) { - forceClose = true; + forceClose = true; } this.onUpdateReceiveDirLight(visibility, forceClose); @@ -1009,6 +1009,7 @@ export class MeshRenderer extends ModelRenderer { protected _onMaterialModified (idx: number, material: Material | null) { if (!this._model || !this._model.inited) { return; } this._onRebuildPSO(idx, material || this._getBuiltinMaterial()); + this._updateStandardSkin(); } /** diff --git a/cocos/3d/lights/directional-light-component.ts b/cocos/3d/lights/directional-light-component.ts index 57ad9d5f86..aace784868 100644 --- a/cocos/3d/lights/directional-light-component.ts +++ b/cocos/3d/lights/directional-light-component.ts @@ -28,7 +28,7 @@ import { scene } from '../../render-scene'; import { cclegacy, clamp, warnID, CCBoolean, CCFloat, _decorator, settings, Settings, CCInteger } from '../../core'; import { Camera, PCFType, Shadows, ShadowType, CSMOptimizationMode, CSMLevel } from '../../render-scene/scene'; import { Root } from '../../root'; -import { MeshRenderer } from '../framework'; +import { MeshRenderer } from '../framework/mesh-renderer'; import { director } from '../../game/director'; import { rangeMin } from '../../core/data/decorators'; diff --git a/cocos/misc/model-renderer.ts b/cocos/misc/model-renderer.ts index e33d2d9a7b..8bc3febcad 100644 --- a/cocos/misc/model-renderer.ts +++ b/cocos/misc/model-renderer.ts @@ -29,6 +29,24 @@ import { scene } from '../render-scene'; import { Layers } from '../scene-graph/layers'; import { Renderer } from './renderer'; import { CCBoolean, cclegacy, _decorator } from '../core'; +import { Model, SubModel } from '../render-scene/scene'; +import { isEnableEffect } from '../rendering/define'; +import { Root } from '../root'; +import { getPhaseID } from '../rendering/pass-phase'; + +let _phaseID = getPhaseID('specular-pass'); +function getSkinPassIndex (subModel: SubModel): number { + const passes = subModel.passes; + const r = cclegacy.rendering; + if (isEnableEffect()) _phaseID = r.getPhaseID(r.getPassID('specular-pass'), 'default'); + for (let k = 0; k < passes.length; k++) { + if (((!r || !r.enableEffectImport) && passes[k].phase === _phaseID) + || (isEnableEffect() && passes[k].phaseID === _phaseID)) { + return k; + } + } + return -1; +} /** * @en Base class for all rendering components containing model. @@ -127,8 +145,21 @@ export class ModelRenderer extends Renderer { } protected _updateStandardSkin () { + const pipelineSceneData = (cclegacy.director.root as Root).pipeline.pipelineSceneData; if (this._enabledStandardSkin) { - cclegacy.director.root.pipeline.pipelineSceneData.standardSkinModel = this; + pipelineSceneData.standardSkinModel = this; + } + if (!pipelineSceneData.skinMaterialModel) { + for (let i = 0; i < this._models.length; i++) { + const subModels = this._models[i].subModels; + for (let j = 0; j < subModels.length; j++) { + const subModel = subModels[j]; + const skinPassIdx = getSkinPassIndex(subModel); + if (skinPassIdx < 0) { continue; } + pipelineSceneData.skinMaterialModel = this._models[i]; + return; + } + } } } } diff --git a/cocos/render-scene/scene/skin.ts b/cocos/render-scene/scene/skin.ts index 0d17667bde..03d3d273b7 100644 --- a/cocos/render-scene/scene/skin.ts +++ b/cocos/render-scene/scene/skin.ts @@ -64,7 +64,7 @@ export class Skin { return this._sssIntensity; } - protected _enabled = false; + protected _enabled = true; protected _blurRadius = 0.01; protected _sssIntensity = 5.0; diff --git a/cocos/rendering/pipeline-scene-data.ts b/cocos/rendering/pipeline-scene-data.ts index ad84e73d51..177f31f5d7 100644 --- a/cocos/rendering/pipeline-scene-data.ts +++ b/cocos/rendering/pipeline-scene-data.ts @@ -35,6 +35,8 @@ import { CSMLayers } from './shadow/csm-layers'; import { cclegacy } from '../core'; import { Skin } from '../render-scene/scene/skin'; import { ModelRenderer } from '../misc/model-renderer'; +import { scene } from '../render-scene'; +import { Model } from '../render-scene/scene'; const GEOMETRY_RENDERER_TECHNIQUE_COUNT = 6; @@ -85,6 +87,13 @@ export class PipelineSceneData { this._standardSkinModel = val; } + get skinMaterialModel () { + return this._skinMaterialModel!; + } + set skinMaterialModel (val: Model) { + this._skinMaterialModel = val; + } + public fog: Fog = new Fog(); public ambient: Ambient = new Ambient(); public skybox: Skybox = new Skybox(); @@ -119,6 +128,7 @@ export class PipelineSceneData { protected _shadingScale = 1.0; protected _csmSupported = true; private _standardSkinModel: ModelRenderer | null = null; + private _skinMaterialModel: Model | null = null; constructor () { this._shadingScale = 1.0; diff --git a/cocos/rendering/post-process/passes/base-pass.ts b/cocos/rendering/post-process/passes/base-pass.ts index c9b886a1a2..1cfedef347 100644 --- a/cocos/rendering/post-process/passes/base-pass.ts +++ b/cocos/rendering/post-process/passes/base-pass.ts @@ -3,7 +3,7 @@ import { EDITOR } from 'internal:constants'; import { Material } from '../../../asset/assets'; import { Camera } from '../../../render-scene/scene'; import { getCameraUniqueID } from '../../custom/define'; -import { BasicPipeline, Pipeline } from '../../custom/pipeline'; +import { BasicPipeline, Pipeline, PipelineRuntime } from '../../custom/pipeline'; import { passContext } from '../utils/pass-context'; import { Format } from '../../../gfx'; import { supportsRGBA16FloatTexture } from '../../define'; @@ -15,12 +15,16 @@ export function getRTFormatBeforeToneMapping (ppl: BasicPipeline) { const useFloatOutput = ppl.getMacroBool('CC_USE_FLOAT_OUTPUT'); return ppl.pipelineSceneData.isHDR && useFloatOutput && supportsRGBA16FloatTexture(ppl.device) ? Format.RGBA16F : Format.RGBA8; } -export function forceEnableFloatOutput (ppl: BasicPipeline) { +export function forceEnableFloatOutput (ppl: PipelineRuntime) { + let enabled = false; if (ppl.pipelineSceneData.isHDR && !ppl.getMacroBool('CC_USE_FLOAT_OUTPUT')) { const supportFloatOutput = supportsRGBA16FloatTexture(ppl.device); ppl.setMacroBool('CC_USE_FLOAT_OUTPUT', supportFloatOutput); macro.ENABLE_FLOAT_OUTPUT = supportFloatOutput; + enabled = supportFloatOutput; } + + return enabled; } export function disablePostProcessForDebugView () { diff --git a/cocos/rendering/post-process/passes/skin-pass.ts b/cocos/rendering/post-process/passes/skin-pass.ts index 8fcd1756e0..d563fb882d 100644 --- a/cocos/rendering/post-process/passes/skin-pass.ts +++ b/cocos/rendering/post-process/passes/skin-pass.ts @@ -22,14 +22,15 @@ THE SOFTWARE. */ -import { Vec4, Vec3 } from '../../../core'; +import { Vec4, Vec3, cclegacy, warnID } from '../../../core'; import { Camera } from '../../../render-scene/scene'; -import { BasicPipeline, LightInfo, QueueHint, SceneFlags } from '../../custom'; +import { BasicPipeline, LightInfo, PipelineRuntime, QueueHint, SceneFlags } from '../../custom'; import { getCameraUniqueID } from '../../custom/define'; import { passContext } from '../utils/pass-context'; import { ClearFlagBit, Format } from '../../../gfx'; -import { MeshRenderer } from '../../../3d'; +import { MeshRenderer } from '../../../3d/framework/mesh-renderer'; import { ShadowPass } from './shadow-pass'; +import { Root } from '../../../root'; import { SettingPass } from './setting-pass'; import { forceEnableFloatOutput, getRTFormatBeforeToneMapping } from './base-pass'; @@ -38,7 +39,7 @@ export const COPY_INPUT_DS_PASS_INDEX = 0; export const SSSS_BLUR_X_PASS_INDEX = 1; export const SSSS_BLUR_Y_PASS_INDEX = 2; -function hasSkinObject (ppl: BasicPipeline) { +function hasSkinObject (ppl: PipelineRuntime) { const sceneData = ppl.pipelineSceneData; return sceneData.skin.enabled && sceneData.standardSkinModel !== null; } @@ -189,20 +190,34 @@ export class SkinPass extends SettingPass { outputNames = ['SSSSBlur', 'SSSSBlurDS'] ssssBlurData = new SSSSBlurData(); + private _activate = false; + enableInAllEditorCamera = true; + checkEnable (camera: Camera) { + const ppl = (cclegacy.director.root as Root).pipeline; + let enable = hasSkinObject(ppl); + if (enable) { + if (!this._activate) { + if (!ppl.getMacroBool('CC_USE_FLOAT_OUTPUT')) { + warnID(16303); + } + if (!ppl.pipelineSceneData.standardSkinModel) { + warnID(16304); + } + this._activate = true; + } + enable = forceEnableFloatOutput(ppl); + } + return enable; + } public render (camera: Camera, ppl: BasicPipeline): void { passContext.material = this.material; const inputRT = this.lastPass?.slotName(camera, 0); - const inputDS = this.lastPass?.slotName(camera, 1); - if (hasSkinObject(ppl)) { - forceEnableFloatOutput(ppl); - const blurInfo = this._buildSSSSBlurPass(camera, ppl, inputRT!, inputDS!); - this._buildSpecularPass(camera, ppl, blurInfo.rtName, blurInfo.dsName); - } else { - this._buildSpecularPass(camera, ppl, inputRT!, inputDS!); - } + const inputDS = passContext.depthSlotName; + this._buildSSSSBlurPass(camera, ppl, inputRT!, inputDS); + this._buildSpecularPass(camera, ppl, inputRT!, inputDS); } private _buildSSSSBlurPass (camera: Camera, @@ -210,14 +225,19 @@ export class SkinPass extends SettingPass { inputRT: string, inputDS: string) { const cameraID = getCameraUniqueID(camera); - let boundingBox = 0.4; - const standardSkinModel = ppl.pipelineSceneData.standardSkinModel; - const model = (standardSkinModel as MeshRenderer).model; - if (model) { - const halfExtents = model.worldBounds.halfExtents; - boundingBox = Math.min(halfExtents.x, halfExtents.y, halfExtents.z) * 2.0; + const pipelineSceneData = ppl.pipelineSceneData; + + let halfExtents = new Vec3(0.2, 0.2, 0.2); + const standardSkinModel = pipelineSceneData.standardSkinModel; + const skinMaterialModel = pipelineSceneData.skinMaterialModel; + if (standardSkinModel && (standardSkinModel as MeshRenderer).model) { + halfExtents = (standardSkinModel as MeshRenderer).model!.worldBounds.halfExtents; + } else if (skinMaterialModel) { + halfExtents = skinMaterialModel.worldBounds.halfExtents; } - const skin = ppl.pipelineSceneData.skin; + const boundingBox = Math.min(halfExtents.x, halfExtents.y, halfExtents.z) * 2.0; + + const skin = pipelineSceneData.skin; const ssssBlurRTName = super.slotName(camera, 0); const ssssBlurDSName = super.slotName(camera, 1); @@ -274,8 +294,6 @@ export class SkinPass extends SettingPass { .addRasterView(inputDS, Format.DEPTH_STENCIL) .blitScreen(passIdx) .version(); - - return { rtName: inputRT, dsName: inputDS }; } private _buildSpecularPass (camera: Camera, @@ -310,13 +328,13 @@ export class SkinPass extends SettingPass { } } - pass.addQueue(QueueHint.RENDER_TRANSPARENT, 'default') + pass.addQueue(QueueHint.RENDER_OPAQUE, 'default') .addSceneOfCamera(camera, new LightInfo(), - SceneFlags.OPAQUE_OBJECT | SceneFlags.TRANSPARENT_OBJECT | SceneFlags.DEFAULT_LIGHTING | SceneFlags.PLANAR_SHADOW + SceneFlags.TRANSPARENT_OBJECT | SceneFlags.DEFAULT_LIGHTING | SceneFlags.PLANAR_SHADOW | SceneFlags.CUTOUT_OBJECT | SceneFlags.DRAW_INSTANCING); pass.addQueue(QueueHint.RENDER_TRANSPARENT, 'forward-add') .addSceneOfCamera(camera, new LightInfo(), - SceneFlags.OPAQUE_OBJECT | SceneFlags.TRANSPARENT_OBJECT | SceneFlags.DEFAULT_LIGHTING | SceneFlags.PLANAR_SHADOW + SceneFlags.TRANSPARENT_OBJECT | SceneFlags.DEFAULT_LIGHTING | SceneFlags.PLANAR_SHADOW | SceneFlags.CUTOUT_OBJECT | SceneFlags.DRAW_INSTANCING); } diff --git a/cocos/scene-graph/scene-globals.ts b/cocos/scene-graph/scene-globals.ts index c796ecb575..6da6736ede 100644 --- a/cocos/scene-graph/scene-globals.ts +++ b/cocos/scene-graph/scene-globals.ts @@ -1092,13 +1092,11 @@ export class SkinInfo { * @zh 是否开启皮肤后效。 */ @editable + @readOnly @tooltip('i18n:skin.enabled') set enabled (val: boolean) { if (this._enabled === val) return; this._enabled = val; - if (val && !macro.ENABLE_FLOAT_OUTPUT) { - console.warn('Separable-SSS skin filter need float output, please open ENABLE_FLOAT_OUTPUT define...'); - } if (this._resource) { this._resource.enabled = val; } @@ -1118,11 +1116,6 @@ export class SkinInfo { @type(CCFloat) @tooltip('i18n:skin.blurRadius') set blurRadius (val: number) { - if (this._blurRadius === val) return; - if ((cclegacy.director.root.pipeline.pipelineSceneData.standardSkinModel === null)) { - console.warn('Separable-SSS skin filter need set standard model, please check the isGlobalStandardSkinObject option in the MeshRender component.'); - return; - } this._blurRadius = val; if (this._resource) { this._resource.blurRadius = val; } } @@ -1140,11 +1133,6 @@ export class SkinInfo { @type(CCFloat) @tooltip('i18n:skin.sssIntensity') set sssIntensity (val: number) { - if (this._sssIntensity === val) return; - if ((cclegacy.director.root.pipeline.pipelineSceneData.standardSkinModel === null)) { - console.warn('Separable-SSS skin filter need set standard model, please check the isGlobalStandardSkinObject option in the MeshRender component.'); - return; - } this._sssIntensity = val; if (this._resource) { this._resource.sssIntensity = val; } } @@ -1153,7 +1141,7 @@ export class SkinInfo { } @serializable - protected _enabled = false; + protected _enabled = true; @serializable protected _blurRadius = 0.01; @serializable