diff --git a/.eslintrc.yaml b/.eslintrc.yaml index b3b7303f20..98e5a9d449 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -76,7 +76,7 @@ rules: lines-between-class-members: off # be more lenient on member declarations max-classes-per-file: off # helper classes are common max-len: [warn, 150] # more lenient on max length per line - no-console: off # this is just too much work, cc.warn is still too much pain to use + no-console: error # prefer the uniform logging methods no-plusplus: off # allow increment/decrement operators no-continue: off # allow unlabeled continues no-mixed-operators: off # this is just cumbersome diff --git a/@types/pal/wasm.d.ts b/@types/pal/wasm.d.ts index 40568c718e..ed2c7523a7 100644 --- a/@types/pal/wasm.d.ts +++ b/@types/pal/wasm.d.ts @@ -8,4 +8,14 @@ declare module 'pal/wasm' { * @param importObject the standard `WebAssembly.Imports` instance */ export function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Imports): Promise; + + /** + * Fetch binary data from wasm url or js mem url. + * NOTE: This method should only use to instantiate asm.js compiled with `-O2` options, + * because not all platforms support instantiate wasm by wasm binary. + * eg. WeChat can only instantiate wasm by wasm url. + * + * @param binaryUrl the url of wasm or js mem, this should be a url relative from build output chunk. + */ + export function fetchBuffer (binaryUrl: string): Promise; } diff --git a/EngineErrorMap.md b/EngineErrorMap.md index 8385a84bae..214e156a5c 100644 --- a/EngineErrorMap.md +++ b/EngineErrorMap.md @@ -3267,6 +3267,34 @@ The font size is too big to be fitted into texture atlas. Please switch to other The asset %s has been destroyed! +### 12102 + +Base pass cannot override states, please use pass instance instead. + +### 12103 + +Custom pipeline create shader %s failed. Please restart editor. + +### 12104 + +Create shader %s failed. + +### 12105 + +Pass resources incomplete. + +### 12106 + +Cannot patch non-builtin macros. + +### 12107 + +Custom pipeline invalid render pass, program: %s. Please restart editor. + +### 12108 + +Custom pipeline invalid render phase, program: %s. Please restart editor. + ### 13100 Incorrect CCON magic. diff --git a/cocos/animation/animation-clip.ts b/cocos/animation/animation-clip.ts index 2df73f911e..7285e2a1fd 100644 --- a/cocos/animation/animation-clip.ts +++ b/cocos/animation/animation-clip.ts @@ -1533,7 +1533,19 @@ class EventEvaluator { } } + public reset () { + this._lastFrameIndex = -1; + this._lastIterations = 0.0; + this._lastDirection = 0; + this._ignoreIndex = InvalidIndex; + this._sampled = false; + } + public sample (ratio: number, direction: number, iterations: number): void { + if (this._eventGroups.length === 0) { + return; + } + const length = this._eventGroups.length; let eventIndex = getEventGroupIndexAtRatio(ratio, this._ratios); if (eventIndex < 0) { diff --git a/cocos/animation/marionette/motion/animation-blend.ts b/cocos/animation/marionette/motion/animation-blend.ts index fa39971e69..9162838c10 100644 --- a/cocos/animation/marionette/motion/animation-blend.ts +++ b/cocos/animation/marionette/motion/animation-blend.ts @@ -212,6 +212,14 @@ class AnimationBlendPort implements MotionPort { return this._host.__evaluatePort(this, progress, context); } + public reenter () { + const { childPorts } = this; + const nChildPorts = childPorts.length; + for (let iChild = 0; iChild < nChildPorts; ++iChild) { + childPorts[iChild]?.reenter(); + } + } + private _host: AnimationBlendEval; } diff --git a/cocos/animation/marionette/motion/clip-motion.ts b/cocos/animation/marionette/motion/clip-motion.ts index 6350625326..def4d6ca5a 100644 --- a/cocos/animation/marionette/motion/clip-motion.ts +++ b/cocos/animation/marionette/motion/clip-motion.ts @@ -151,6 +151,9 @@ class ClipMotionEval implements MotionEval { const pose = clipEval.evaluate(clipTime, context); + // Sample frame events. + this._frameEventEval?.sample(wrapInfo.ratio, wrapInfo.direction, wrapInfo.iterations); + // Evaluate embedded players. this._clipEmbeddedPlayerEval?.evaluate(clipTime, Math.trunc(wrapInfo.iterations)); @@ -165,6 +168,10 @@ class ClipMotionEval implements MotionEval { } } + public reenter () { + this._frameEventEval?.reset(); + } + /** * Preserved here for clip overriding. */ @@ -175,12 +182,14 @@ class ClipMotionEval implements MotionEval { private declare _clip: AnimationClip; private declare _clipEval: AnimationClipAGEvaluation; private _clipEmbeddedPlayerEval: ReturnType | null = null; + private _frameEventEval: ReturnType | null = null; private _wrapInfo = new WrappedInfo(); private _duration = 0.0; private _ignoreEmbeddedPlayers: boolean; private _setClip (clip: AnimationClip, context: AnimationGraphBindingContext): void { this._clipEval?.destroy(); + this._frameEventEval = null; if (this._clipEmbeddedPlayerEval) { this._clipEmbeddedPlayerEval.destroy(); this._clipEmbeddedPlayerEval = null; @@ -191,6 +200,7 @@ class ClipMotionEval implements MotionEval { ? 0.0 : clip.duration / clip.speed; // TODO, a test for `clip.speed === 0` is required! this._clipEval = createAnimationAGEvaluation(clip, context); + this._frameEventEval = clip.createEventEvaluator(context.origin); if (!this._ignoreEmbeddedPlayers && clip.containsAnyEmbeddedPlayer()) { this._clipEmbeddedPlayerEval = clip.createEmbeddedPlayerEvaluator(context.origin); } @@ -206,5 +216,9 @@ class ClipMotionPort implements MotionPort { return this._eval[evaluatePortTag](progress, context); } + public reenter () { + this._eval.reenter(); + } + private _eval: ClipMotionEval; } diff --git a/cocos/animation/marionette/motion/motion.ts b/cocos/animation/marionette/motion/motion.ts index e7f487dd72..d6084f3db2 100644 --- a/cocos/animation/marionette/motion/motion.ts +++ b/cocos/animation/marionette/motion/motion.ts @@ -84,4 +84,6 @@ export abstract class Motion extends EditorExtendable { export interface MotionPort { evaluate(progress: number, context: AnimationGraphEvaluationContext): Pose; + + reenter(): void; } diff --git a/cocos/animation/marionette/pose-graph/pose-nodes/modify-pose-base.ts b/cocos/animation/marionette/pose-graph/pose-nodes/modify-pose-base.ts index adc048af35..c2ff4ed7b7 100644 --- a/cocos/animation/marionette/pose-graph/pose-nodes/modify-pose-base.ts +++ b/cocos/animation/marionette/pose-graph/pose-nodes/modify-pose-base.ts @@ -10,57 +10,6 @@ import { PoseGraphType } from '../foundation/type-system'; import { assertIsTrue, CachedArray, Pool } from '../../../../core'; import { Transform } from '../../../core/transform'; -@ccclass(`${CLASS_NAME_PREFIX_ANIM}PoseNodeModifyPoseBase`) -@poseGraphNodeHide() -export abstract class PoseNodeModifyPoseBase extends PoseNode { - @serializable - @input({ type: PoseGraphType.POSE }) - public pose: PoseNode | null = null; - - public settle (context: AnimationGraphSettleContext): void { - this.pose?.settle(context); - this._spaceFlagTable = new PoseTransformSpaceFlagTable(context.transformCount); - } - - public reenter (): void { - this.pose?.reenter(); - } - - public bind (context: AnimationGraphBindingContext): void { - this.pose?.bind(context); - } - - protected doUpdate (context: AnimationGraphUpdateContext): void { - this.pose?.update(context); - } - - protected doEvaluate (context: AnimationGraphEvaluationContext): Pose { - const poseTransformSpaceRequirement = this.getPoseTransformSpaceRequirement(); - const inputPose = this.pose?.evaluate(context, poseTransformSpaceRequirement) - ?? PoseNode.evaluateDefaultPose(context, poseTransformSpaceRequirement); - - const { _modificationQueue: modificationQueue } = this; - assertIsTrue(modificationQueue.length === 0); - this.modifyPose(context, inputPose, modificationQueue); - - applyTransformModificationQueue(context, inputPose, modificationQueue, this._spaceFlagTable); - modificationQueue.clear(); - - return inputPose; - } - - protected abstract getPoseTransformSpaceRequirement(): PoseTransformSpaceRequirement; - - protected abstract modifyPose( - context: AnimationGraphEvaluationContext, - pose: Pose, - transformModificationQueue: TransformModificationQueue, - ): void; - - private _modificationQueue = new TransformModificationQueue(); - private _spaceFlagTable = new PoseTransformSpaceFlagTable(0); -} - class TransformModification { public transformIndex = -1; public transform = new Transform(); @@ -249,3 +198,54 @@ function applyTransformModificationQueue ( } } } + +@ccclass(`${CLASS_NAME_PREFIX_ANIM}PoseNodeModifyPoseBase`) +@poseGraphNodeHide() +export abstract class PoseNodeModifyPoseBase extends PoseNode { + @serializable + @input({ type: PoseGraphType.POSE }) + public pose: PoseNode | null = null; + + public settle (context: AnimationGraphSettleContext): void { + this.pose?.settle(context); + this._spaceFlagTable = new PoseTransformSpaceFlagTable(context.transformCount); + } + + public reenter (): void { + this.pose?.reenter(); + } + + public bind (context: AnimationGraphBindingContext): void { + this.pose?.bind(context); + } + + protected doUpdate (context: AnimationGraphUpdateContext): void { + this.pose?.update(context); + } + + protected doEvaluate (context: AnimationGraphEvaluationContext): Pose { + const poseTransformSpaceRequirement = this.getPoseTransformSpaceRequirement(); + const inputPose = this.pose?.evaluate(context, poseTransformSpaceRequirement) + ?? PoseNode.evaluateDefaultPose(context, poseTransformSpaceRequirement); + + const { _modificationQueue: modificationQueue } = this; + assertIsTrue(modificationQueue.length === 0); + this.modifyPose(context, inputPose, modificationQueue); + + applyTransformModificationQueue(context, inputPose, modificationQueue, this._spaceFlagTable); + modificationQueue.clear(); + + return inputPose; + } + + protected abstract getPoseTransformSpaceRequirement(): PoseTransformSpaceRequirement; + + protected abstract modifyPose( + context: AnimationGraphEvaluationContext, + pose: Pose, + transformModificationQueue: TransformModificationQueue, + ): void; + + private _modificationQueue = new TransformModificationQueue(); + private _spaceFlagTable = new PoseTransformSpaceFlagTable(0); +} diff --git a/cocos/animation/marionette/state-machine/state-machine-eval.ts b/cocos/animation/marionette/state-machine/state-machine-eval.ts index 933f04410d..7a794dd1e8 100644 --- a/cocos/animation/marionette/state-machine/state-machine-eval.ts +++ b/cocos/animation/marionette/state-machine/state-machine-eval.ts @@ -1345,6 +1345,7 @@ class VMSMInternalState extends EventifiedStateEval { public reenter (initialTimeNormalized: number): void { this._progress = initialTimeNormalized; + this._port?.reenter(); } public getStatus (): MotionStateStatus { diff --git a/cocos/core/platform/macro.ts b/cocos/core/platform/macro.ts index a9756215a2..c27506d7dd 100644 --- a/cocos/core/platform/macro.ts +++ b/cocos/core/platform/macro.ts @@ -985,15 +985,6 @@ interface Macro { */ ENABLE_WEBGL_ANTIALIAS: boolean; - /** - * @en - * Used to set FXAA post-processing anti-aliasing, the default value is false. - * @zh - * 用于开启 FXAA 后处理抗锯齿, 默认值为 false。 - * @default false - */ - ENABLE_ANTIALIAS_FXAA: boolean; - /** * @en * Used to set float output, the default value is false. @@ -1003,15 +994,6 @@ interface Macro { */ ENABLE_FLOAT_OUTPUT: boolean; - /** - * @en - * Used to set bloom, the default value is false. - * @zh - * 用于开启 bloom, 默认值为 false。 - * @default false - */ - ENABLE_BLOOM: boolean; - /** * @en * Whether to clear the original image cache after uploaded a texture to GPU. @@ -1116,9 +1098,7 @@ const macro: Macro = { TOUCH_TIMEOUT: 5000, ENABLE_TRANSPARENT_CANVAS: false, ENABLE_WEBGL_ANTIALIAS: true, - ENABLE_ANTIALIAS_FXAA: false, ENABLE_FLOAT_OUTPUT: false, - ENABLE_BLOOM: false, CLEANUP_IMAGE_CACHE: false, ENABLE_MULTI_TOUCH: true, MAX_LABEL_CANVAS_POOL_SIZE: 20, diff --git a/cocos/physics-2d/box2d/platform/physics-contact-listener.ts b/cocos/physics-2d/box2d/platform/physics-contact-listener.ts index ba21adbb26..c70469b4e8 100644 --- a/cocos/physics-2d/box2d/platform/physics-contact-listener.ts +++ b/cocos/physics-2d/box2d/platform/physics-contact-listener.ts @@ -56,16 +56,12 @@ export class PhysicsContactListener extends b2.ContactListener { if (PhysicsContactListener._contactMap.has(key)) { const retContact = PhysicsContactListener._contactMap.get(key)!; retContact.ref++; - //console.log(' collision++', key, 'current ref is:', retContact.ref); if (retContact.status === Contact2DType.END_CONTACT) { retContact.status = Contact2DType.STAY_CONTACT; - //console.log(' set as stay'); } else if (retContact.status !== Contact2DType.STAY_CONTACT) { retContact.status = Contact2DType.BEGIN_CONTACT; - //console.log(' set as enter'); } } else { - //console.log(' new collision', key, 'current ref is:', 1); const retCollision = new PhysicsContact(contact); PhysicsContactListener._contactMap.set(key, retCollision); retCollision.status = Contact2DType.BEGIN_CONTACT; @@ -79,9 +75,7 @@ export class PhysicsContactListener extends b2.ContactListener { assert(typeof retContact !== 'undefined'); retContact.ref--; - //console.log(' collision--', key, 'current ref is:', retCollision.ref); if (retContact.ref <= 0) { - //console.log(' set as exit'); retContact.status = Contact2DType.END_CONTACT; } } @@ -94,18 +88,13 @@ export class PhysicsContactListener extends b2.ContactListener { public finalizeContactEvent (): void { PhysicsContactListener._contactMap.forEach((contact: PhysicsContact, key: string): void => { - //console.log('forEach', key, collision); - // emit collision event if (!contact.disabled || contact.status === Contact2DType.BEGIN_CONTACT) { //BEGIN_CONTACT always emits if (contact.status === Contact2DType.END_CONTACT) { - //console.log(' report end collision', key, 'current ref is:', contact.ref); this.emit(Contact2DType.END_CONTACT, contact); } else if (contact.status === Contact2DType.BEGIN_CONTACT) { - //console.log(' report enter collision', key, 'current ref is:', contact.ref); this.emit(Contact2DType.BEGIN_CONTACT, contact); } else if (contact.status === Contact2DType.STAY_CONTACT) { - //console.log(' report stay collision', key, 'current ref is:', contact.ref); this.emit(Contact2DType.STAY_CONTACT, contact); } } diff --git a/cocos/physics/framework/components/constraints/configurable-constraint.ts b/cocos/physics/framework/components/constraints/configurable-constraint.ts index 1fa3f4245d..3d5f8ecce0 100644 --- a/cocos/physics/framework/components/constraints/configurable-constraint.ts +++ b/cocos/physics/framework/components/constraints/configurable-constraint.ts @@ -39,6 +39,10 @@ import { Vec3, CCFloat, CCBoolean } from '../../../../core'; import { EConstraintType, EConstraintMode, EDriverMode } from '../../physics-enum'; import { IConfigurableConstraint } from '../../../spec/i-physics-constraint'; +/** + * @en The linear limit settings of the configurable constraint. + * @zh 可配置约束的线性限制设置。 + */ @ccclass('cc.LinearLimitSettings') export class LinearLimitSettings { @type(EConstraintMode) @@ -190,6 +194,10 @@ export class LinearLimitSettings { } } +/** + * @en The angular limit settings of the configurable constraint. + * @zh 可配置约束的角度限制设置。 + */ @ccclass('cc.AngularLimitSettings') export class AngularLimitSettings { @type(EConstraintMode) @@ -409,6 +417,10 @@ export class AngularLimitSettings { } } +/** + * @en The linear driver settings of the configurable constraint. + * @zh 可配置约束的线性驱动器设置。 + */ @ccclass('cc.LinearDriverSettings') export class LinearDriverSettings { @type(EDriverMode) @@ -511,6 +523,10 @@ export class LinearDriverSettings { } } +/** + * @en The angular driver settings of the configurable constraint. + * @zh 可配置约束的角度驱动器设置。 + */ @ccclass('cc.AngularDriverSettings') export class AngularDriverSettings { @type(EDriverMode) @@ -613,6 +629,12 @@ export class AngularDriverSettings { } } +/** + * @en The configurable constraint component. + * The configurable constraint provides all the functionality of other constraints, and provides comprehensive configurable options. + * @zh 可配置约束组件。 + * 可配置约束提供了其他约束的所有功能支持,提供了全面的可配置选项。 + */ @ccclass('cc.ConfigurableConstraint') @help('i18n:cc.ConfigurableConstraint') @menu('Physics/ConfigurableConstraint(beta)') diff --git a/cocos/physics/framework/components/constraints/fixed-constraint.ts b/cocos/physics/framework/components/constraints/fixed-constraint.ts index cd09e164ba..653735d759 100644 --- a/cocos/physics/framework/components/constraints/fixed-constraint.ts +++ b/cocos/physics/framework/components/constraints/fixed-constraint.ts @@ -37,6 +37,12 @@ import { CCFloat, IVec3Like, Vec3 } from '../../../../core'; import { EConstraintType } from '../../physics-enum'; import { IFixedConstraint } from '../../../spec/i-physics-constraint'; +/** + * @en The fixed constraint. + * It locks the relative position and rotation between two rigid bodies. + * @zh 固定关节。 + * 固定关节会锁定两个刚体间的相对位置和相对旋转。 + */ @ccclass('cc.FixedConstraint') @help('i18n:cc.FixedConstraint') @menu('Physics/FixedConstraint(beta)') diff --git a/cocos/physics/framework/components/constraints/hinge-constraint.ts b/cocos/physics/framework/components/constraints/hinge-constraint.ts index e50beac6f1..ffd283834d 100644 --- a/cocos/physics/framework/components/constraints/hinge-constraint.ts +++ b/cocos/physics/framework/components/constraints/hinge-constraint.ts @@ -37,6 +37,10 @@ import { Vec3, CCFloat, CCBoolean } from '../../../../core'; import { EConstraintType } from '../../physics-enum'; import { IHingeConstraint } from '../../../spec/i-physics-constraint'; +/** + * @en The hinge constraint limitation data. + * @zh 铰链约束的限制数据。 + */ @ccclass('cc.HingeLimitData') export class HingeLimitData { @serializable @@ -96,6 +100,10 @@ export class HingeLimitData { } } +/** + * @en The hinge constraint motor data. + * @zh 铰链约束的马达数据。 + */ @ccclass('cc.HingeMotorData') export class HingeMotorData { @serializable @@ -155,6 +163,13 @@ export class HingeMotorData { } } +/** + * @en Hinge constraint. + * It keeps the local rotation axes of two rigid bodies aligned, + * and locks the relative motion along the rotation axis. + * @zh 铰链约束。 + * 它保持两个刚体的本地旋转轴对齐,并锁定沿旋转轴的相对运动。 + */ @ccclass('cc.HingeConstraint') @help('i18n:cc.HingeConstraint') @menu('Physics/HingeConstraint(beta)') diff --git a/cocos/physics/framework/components/constraints/point-to-point-constraint.ts b/cocos/physics/framework/components/constraints/point-to-point-constraint.ts index 4346f30a41..99057eb93b 100644 --- a/cocos/physics/framework/components/constraints/point-to-point-constraint.ts +++ b/cocos/physics/framework/components/constraints/point-to-point-constraint.ts @@ -36,6 +36,12 @@ import { Vec3, IVec3Like } from '../../../../core'; import { EConstraintType } from '../../physics-enum'; import { IPointToPointConstraint } from '../../../spec/i-physics-constraint'; +/** + * @en The point to point constraint. + * It locks the relative position of the pivots between two rigid bodies. + * @zh 点对点约束。 + * 点对点约束会锁定两个刚体间的连接点的相对位置。 + */ @ccclass('cc.PointToPointConstraint') @help('i18n:cc.PointToPointConstraint') @menu('Physics/PointToPointConstraint(beta)') diff --git a/cocos/render-scene/core/pass.ts b/cocos/render-scene/core/pass.ts index 5be2542206..a1a7c93ca7 100644 --- a/cocos/render-scene/core/pass.ts +++ b/cocos/render-scene/core/pass.ts @@ -27,7 +27,7 @@ import { Root } from '../../root'; import { TextureBase } from '../../asset/assets/texture-base'; import { builtinResMgr } from '../../asset/asset-manager/builtin-res-mgr'; import { getPhaseID } from '../../rendering/pass-phase'; -import { murmurhash2_32_gc, errorID, assertID, cclegacy } from '../../core'; +import { murmurhash2_32_gc, errorID, assertID, cclegacy, warnID } from '../../core'; import { BufferUsageBit, DynamicStateFlagBit, DynamicStateFlags, Feature, GetTypeSize, MemoryUsageBit, PrimitiveMode, Type, Color, BlendState, BlendTarget, Buffer, BufferInfo, BufferViewInfo, DepthStencilState, DescriptorSet, DescriptorSetInfo, DescriptorSetLayout, Device, RasterizerState, Sampler, Texture, Shader, PipelineLayout, deviceManager, UniformBlock, @@ -347,7 +347,7 @@ export class Pass { * @param value The override pipeline state info */ public overridePipelineStates (original: EffectAsset.IPassInfo, overrides: PassOverrides): void { - console.warn('base pass cannot override states, please use pass instance instead.'); + warnID(12102); } /** @@ -491,7 +491,7 @@ export class Pass { this._device, this._phaseID, this._programName, this._defines, ); if (!program) { - console.warn(`create shader ${this._programName} failed`); + warnID(12103, this._programName); return false; } this._shader = program.shader; @@ -499,7 +499,7 @@ export class Pass { } else { const shader = programLib.getGFXShader(this._device, this._programName, this._defines, pipeline); if (!shader) { - console.warn(`create shader ${this._programName} failed`); + warnID(12104, this._programName); return false; } this._shader = shader; @@ -517,7 +517,7 @@ export class Pass { */ public getShaderVariant (patches: Readonly = null): Shader | null { if (!this._shader && !this.tryCompile()) { - console.warn('pass resources incomplete'); + warnID(12105); return null; } @@ -528,7 +528,7 @@ export class Pass { if (EDITOR) { for (let i = 0; i < patches.length; i++) { if (!patches[i].name.startsWith('CC_')) { - console.warn('cannot patch non-builtin macros'); + warnID(12106); return null; } } @@ -584,11 +584,11 @@ export class Pass { } } if (this._passID === r.INVALID_ID) { - console.error(`Invalid render pass, program: ${info.program}`); + errorID(12107, info.program); return; } if (this._phaseID === r.INVALID_ID) { - console.error(`Invalid render phase, program: ${info.program}`); + errorID(12108, info.program); return; } } diff --git a/cocos/rendering/custom/builtin-pipelines.ts b/cocos/rendering/custom/builtin-pipelines.ts index 10216b63b2..eafed239db 100644 --- a/cocos/rendering/custom/builtin-pipelines.ts +++ b/cocos/rendering/custom/builtin-pipelines.ts @@ -25,12 +25,33 @@ import { EDITOR } from 'internal:constants'; import { Camera, CameraUsage } from '../../render-scene/scene'; import { BasicPipeline, PipelineBuilder } from './pipeline'; -import { buildForwardPass, buildGBufferPass, buildLightingPass, buildPostprocessPass, buildUIPass } from './define'; +import { buildClusterPasses } from './define'; import { isUICamera } from './utils'; -import { prepareResource, setupForwardPass, setupForwardRes, setupReflectionProbePass, setupReflectionProbeRes, - updateForwardRes, updateReflectionProbeRes, CameraInfo, setupGBufferPass, - updateGBufferRes, setupGBufferRes, setupLightingPass, setupLightingRes, updateLightingRes, - setupPostprocessPass, setupPostprocessRes, updatePostprocessRes, setupUIPass, setupUIRes, updateUIRes } from './pipeline-define'; +import { + prepareResource, + setupForwardPass, + setupForwardRes, + setupReflectionProbePass, + setupReflectionProbeRes, + updateForwardRes, + updateReflectionProbeRes, + CameraInfo, + setupGBufferPass, + updateGBufferRes, + setupGBufferRes, + setupLightingPass, + setupLightingRes, + updateLightingRes, + setupPostprocessPass, + setupPostprocessRes, + updatePostprocessRes, + setupUIPass, + setupUIRes, + updateUIRes, + setupDeferredForward, + setupScenePassTiled, +} from './pipeline-define'; +import { Feature } from '../../gfx'; export class ForwardPipelineBuilder implements PipelineBuilder { public setup (cameras: Camera[], ppl: BasicPipeline): void { @@ -65,6 +86,9 @@ export class DeferredPipelineBuilder implements PipelineBuilder { continue; } ppl.update(camera); + const forceDisableCluster = false; + const useCluster = !forceDisableCluster && ppl.device.hasFeature(Feature.COMPUTE_SHADER); + const isGameView = camera.cameraUsage === CameraUsage.GAME || camera.cameraUsage === CameraUsage.GAME_VIEW; const info = prepareResource(ppl, camera, this.initResource, this.updateResource); @@ -73,12 +97,19 @@ export class DeferredPipelineBuilder implements PipelineBuilder { continue; } if (!isUICamera(camera)) { + if (useCluster) { + buildClusterPasses(camera, ppl); + } + // GBuffer Pass setupGBufferPass(ppl, info); // Lighting Pass - const lightInfo = setupLightingPass(ppl, info); + const lightInfo = setupLightingPass(ppl, info, useCluster); + // Deferred ForwardPass, for non-surface-shader material and transparent material + setupDeferredForward(ppl, info, lightInfo.rtName); // Postprocess setupPostprocessPass(ppl, info, lightInfo.rtName); + continue; } // render ui diff --git a/cocos/rendering/custom/compiler.ts b/cocos/rendering/custom/compiler.ts index d19d8e0459..76ee8d6066 100644 --- a/cocos/rendering/custom/compiler.ts +++ b/cocos/rendering/custom/compiler.ts @@ -29,9 +29,9 @@ import { DefaultVisitor, depthFirstSearch, ReferenceGraphView } from './graph'; import { LayoutGraphData } from './layout-graph'; import { BasicPipeline } from './pipeline'; import { Blit, ClearView, ComputePass, ComputeSubpass, CopyPass, Dispatch, FormatView, ManagedBuffer, ManagedResource, ManagedTexture, MovePass, - RasterPass, RasterSubpass, RaytracePass, RenderGraph, RenderGraphVisitor, + RasterPass, RasterSubpass, RaytracePass, RenderGraph, RenderGraphVisitor, RasterView, ComputeView, RenderQueue, RenderSwapchain, ResolvePass, ResourceGraph, ResourceGraphVisitor, SceneData, SubresourceView } from './render-graph'; -import { AccessType, RasterView, ComputeView, ResourceResidency, SceneFlags } from './types'; +import { AccessType, ResourceResidency, SceneFlags } from './types'; let hashCode = 0; diff --git a/cocos/rendering/custom/define.ts b/cocos/rendering/custom/define.ts index 0ce86e7345..4689c5bc16 100644 --- a/cocos/rendering/custom/define.ts +++ b/cocos/rendering/custom/define.ts @@ -32,8 +32,8 @@ import { import { supportsR32FloatTexture, supportsRGBA16HalfFloatTexture } from '../define'; import { BasicPipeline, Pipeline } from './pipeline'; import { - AccessType, AttachmentType, ComputeView, CopyPair, LightInfo, - QueueHint, RasterView, ResourceResidency, SceneFlags, UpdateFrequency, UploadPair, + AccessType, AttachmentType, CopyPair, LightInfo, + QueueHint, ResourceResidency, SceneFlags, UpdateFrequency, UploadPair, } from './types'; import { Vec2, Vec3, Vec4, macro, geometry, toRadian, cclegacy, assert, nextPow2 } from '../../core'; import { ImageAsset, Material, Texture2D } from '../../asset/assets'; @@ -43,7 +43,6 @@ import { RenderData } from './render-graph'; import { WebPipeline } from './web-pipeline'; import { DescriptorSetData } from './layout-graph'; import { AABB } from '../../core/geometry'; -import { MeshRenderer } from '../../3d'; import { DebugViewCompositeType, DebugViewSingleType } from '../debug-view'; const _rangedDirLightBoundingBox = new AABB(0.0, 0.0, 0.0, 0.5, 0.5, 0.5); @@ -118,6 +117,8 @@ export function validPunctualLightsCulling (pipeline: BasicPipeline, camera: Cam validPunctualLights.push(light); } } + // array push not supported. + pipeline.pipelineSceneData.validPunctualLights = validPunctualLights; } const _cameras: Camera[] = []; @@ -168,7 +169,7 @@ export function getRenderArea (camera: Camera, width: number, height: number, li } else { const screenSpaceSignY = cclegacy.director.root.device.capabilities.screenSpaceSignY; out.x = level % 2 * 0.5 * w; - if (screenSpaceSignY) { + if (screenSpaceSignY > 0) { out.y = (1 - Math.floor(level / 2)) * 0.5 * h; } else { out.y = Math.floor(level / 2) * 0.5 * h; @@ -456,9 +457,6 @@ export class PostInfo { private _init (): void { this.postMaterial = new Material(); this.postMaterial.name = 'builtin-post-process-material'; - if (macro.ENABLE_ANTIALIAS_FXAA) { - this.antiAliasing = AntiAliasing.FXAA; - } this.postMaterial.initialize({ effectName: 'pipeline/post-process', defines: { @@ -804,18 +802,21 @@ export function buildGBufferPass (camera: Camera, export class LightingInfo { declare deferredLightingMaterial: Material; + public enableCluster: number; + private _init (): void { this.deferredLightingMaterial = new Material(); this.deferredLightingMaterial.name = 'builtin-deferred-material'; this.deferredLightingMaterial.initialize({ effectName: 'pipeline/deferred-lighting', - defines: { CC_RECEIVE_SHADOW: 1 }, + defines: { CC_ENABLE_CLUSTERED_LIGHT_CULLING: this.enableCluster, CC_RECEIVE_SHADOW: 1 }, }); for (let i = 0; i < this.deferredLightingMaterial.passes.length; ++i) { this.deferredLightingMaterial.passes[i].tryCompile(); } } - constructor () { + constructor (clusterEn: boolean) { + this.enableCluster = clusterEn ? 1 : 0; this._init(); } } @@ -823,9 +824,9 @@ export class LightingInfo { let lightingInfo: LightingInfo; // deferred lighting pass -export function buildLightingPass (camera: Camera, ppl: BasicPipeline, gBuffer: GBufferInfo): { rtName: string; dsName: string; } { +export function buildLightingPass (camera: Camera, ppl: BasicPipeline, gBuffer: GBufferInfo): { rtName: string } { if (!lightingInfo) { - lightingInfo = new LightingInfo(); + lightingInfo = new LightingInfo(false); } const cameraID = getCameraUniqueID(camera); const cameraName = `Camera${cameraID}`; @@ -835,13 +836,10 @@ export function buildLightingPass (camera: Camera, ppl: BasicPipeline, gBuffer: const height = area.height; const deferredLightingPassRTName = `deferredLightingPassRTName`; - const deferredLightingPassDS = `deferredLightingPassDS`; if (!ppl.containsResource(deferredLightingPassRTName)) { ppl.addRenderTarget(deferredLightingPassRTName, Format.RGBA8, width, height, ResourceResidency.MANAGED); - ppl.addDepthStencil(deferredLightingPassDS, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); } ppl.updateRenderTarget(deferredLightingPassRTName, width, height); - ppl.updateDepthStencil(deferredLightingPassDS, width, height); // lighting pass const lightingPass = ppl.addRenderPass(width, height, 'deferred-lighting'); lightingPass.name = `CameraLightingPass${cameraID}`; @@ -857,10 +855,10 @@ export function buildLightingPass (camera: Camera, ppl: BasicPipeline, gBuffer: } } if (ppl.containsResource(gBuffer.color)) { - lightingPass.addTexture(gBuffer.color, 'gbuffer_albedoMap'); - lightingPass.addTexture(gBuffer.normal, 'gbuffer_normalMap'); - lightingPass.addTexture(gBuffer.emissive, 'gbuffer_emissiveMap'); - lightingPass.addTexture(gBuffer.ds, 'depth_stencil'); + lightingPass.addTexture(gBuffer.color, 'albedoMap'); + lightingPass.addTexture(gBuffer.normal, 'normalMap'); + lightingPass.addTexture(gBuffer.emissive, 'emissiveMap'); + lightingPass.addTexture(gBuffer.ds, 'depthStencil'); } const lightingClearColor = new Color(0, 0, 0, 0); if (camera.clearFlag & ClearFlagBit.COLOR) { @@ -876,7 +874,7 @@ export function buildLightingPass (camera: Camera, ppl: BasicPipeline, gBuffer: ); // lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(), // SceneFlags.TRANSPARENT_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.GEOMETRY); - return { rtName: deferredLightingPassRTName, dsName: deferredLightingPassDS }; + return { rtName: deferredLightingPassRTName }; } function getClearFlags (attachment: AttachmentType, clearFlag: ClearFlagBit, loadOp: LoadOp): ClearFlagBit { @@ -937,141 +935,6 @@ export function buildUIPass (camera: Camera, } } -export function buildNativeForwardPass (camera: Camera, ppl: BasicPipeline): void { - const cameraID = getCameraUniqueID(camera); - const cameraName = `Camera${cameraID}`; - const area = getRenderArea(camera, camera.window.width, camera.window.height); - const width = area.width; - const height = area.height; - - // Resources - const forwardPassRTName = `dsForwardPassColor${cameraName}`; - const forwardPassDSName = `dsForwardPassDS${cameraName}`; - if (!ppl.containsResource(forwardPassRTName)) { - ppl.addRenderTexture(forwardPassRTName, Format.BGRA8, width, height, camera.window); - ppl.addDepthStencil(forwardPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); - } - - ppl.updateRenderWindow(forwardPassRTName, camera.window); - ppl.updateDepthStencil(forwardPassDSName, width, height); - // Passes - const forwardPass = ppl.addRenderPass(width, height, 'default'); - forwardPass.name = `CameraForwardPass${cameraID}`; - forwardPass.setViewport(new Viewport(area.x, area.y, width, height)); - - const cameraRenderTargetLoadOp = getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.RENDER_TARGET); - const cameraDepthStencilLoadOp = getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.DEPTH_STENCIL); - - forwardPass.addRasterView(forwardPassRTName, - new RasterView('_', - AccessType.WRITE, AttachmentType.RENDER_TARGET, - cameraRenderTargetLoadOp, - StoreOp.STORE, - getClearFlags(AttachmentType.RENDER_TARGET, camera.clearFlag, cameraRenderTargetLoadOp), - new Color(camera.clearColor.x, camera.clearColor.y, camera.clearColor.z, camera.clearColor.w))); - forwardPass.addRasterView(forwardPassDSName, - new RasterView('_', - AccessType.WRITE, AttachmentType.DEPTH_STENCIL, - cameraDepthStencilLoadOp, - StoreOp.STORE, - getClearFlags(AttachmentType.DEPTH_STENCIL, camera.clearFlag, cameraDepthStencilLoadOp), - new Color(camera.clearDepth, camera.clearStencil, 0, 0))); - - forwardPass - .addQueue(QueueHint.RENDER_OPAQUE) - .addSceneOfCamera(camera, new LightInfo(), - SceneFlags.OPAQUE_OBJECT - | SceneFlags.PLANAR_SHADOW - | SceneFlags.CUTOUT_OBJECT - | SceneFlags.DEFAULT_LIGHTING - | SceneFlags.DRAW_INSTANCING); - forwardPass - .addQueue(QueueHint.RENDER_TRANSPARENT) - .addSceneOfCamera(camera, new LightInfo(), - SceneFlags.TRANSPARENT_OBJECT - | SceneFlags.GEOMETRY); - forwardPass - .addQueue(QueueHint.RENDER_TRANSPARENT) - .addSceneOfCamera(camera, new LightInfo(), - SceneFlags.UI); - forwardPass.showStatistics = true; -} - -export function buildNativeDeferredPipeline (camera: Camera, ppl: BasicPipeline): void { - const cameraID = getCameraUniqueID(camera); - const area = getRenderArea(camera, camera.window.width, camera.window.height); - const width = area.width; - const height = area.height; - if (!ppl.containsResource('Albedo')) { - // GBuffers - ppl.addRenderTarget('Albedo', Format.RGBA16F, width, height, ResourceResidency.MANAGED); - ppl.addRenderTarget('Normal', Format.RGBA16F, width, height, ResourceResidency.MANAGED); - ppl.addRenderTarget('Emissive', Format.RGBA16F, width, height, ResourceResidency.MANAGED); - ppl.addDepthStencil('DepthStencil', Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); - // Lighting - ppl.addRenderTexture('Color', Format.BGRA8, width, height, camera.window); - } - if (!lightingInfo) { - lightingInfo = new LightingInfo(); - } - // GeometryPass - { - const gBufferPass = ppl.addRenderPass(width, height, 'default'); - gBufferPass.name = 'GeometryPass'; - gBufferPass.setViewport(new Viewport(area.x, area.y, area.width, area.height)); - - gBufferPass.addRasterView('Albedo', new RasterView('_', - AccessType.WRITE, AttachmentType.RENDER_TARGET, - LoadOp.CLEAR, StoreOp.STORE, ClearFlagBit.COLOR)); - gBufferPass.addRasterView('Normal', new RasterView('_', - AccessType.WRITE, AttachmentType.RENDER_TARGET, - LoadOp.CLEAR, StoreOp.STORE, ClearFlagBit.COLOR)); - gBufferPass.addRasterView('Emissive', new RasterView('_', - AccessType.WRITE, AttachmentType.RENDER_TARGET, - LoadOp.CLEAR, StoreOp.STORE, ClearFlagBit.COLOR)); - gBufferPass.addRasterView('DepthStencil', new RasterView('_', - AccessType.WRITE, AttachmentType.DEPTH_STENCIL, - LoadOp.CLEAR, StoreOp.STORE, - ClearFlagBit.DEPTH_STENCIL, - new Color(1, 0, 0, 0))); - gBufferPass - .addQueue(QueueHint.RENDER_OPAQUE) - .addSceneOfCamera(camera, new LightInfo(), SceneFlags.OPAQUE_OBJECT | SceneFlags.CUTOUT_OBJECT); - } - // LightingPass - { - const lightingPass = ppl.addRenderPass(width, height, 'default'); - lightingPass.name = 'LightingPass'; - lightingPass.setViewport(new Viewport(area.x, area.y, width, height)); - - const lightingClearColor = new Color(0, 0, 0, 0); - if (camera.clearFlag & ClearFlagBit.COLOR) { - lightingClearColor.x = camera.clearColor.x; - lightingClearColor.y = camera.clearColor.y; - lightingClearColor.z = camera.clearColor.z; - } - lightingClearColor.w = 1; - lightingPass.addRasterView('Color', new RasterView('_', - AccessType.WRITE, AttachmentType.RENDER_TARGET, - LoadOp.CLEAR, StoreOp.STORE, - camera.clearFlag, - lightingClearColor)); - - lightingPass.addComputeView('Albedo', new ComputeView('gbuffer_albedoMap')); - lightingPass.addComputeView('Normal', new ComputeView('gbuffer_normalMap')); - lightingPass.addComputeView('Emissive', new ComputeView('gbuffer_emissiveMap')); - lightingPass.addComputeView('DepthStencil', new ComputeView('depth_stencil')); - - lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addCameraQuad( - camera, lightingInfo.deferredLightingMaterial, 0, - SceneFlags.VOLUMETRIC_LIGHTING, - ); - lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, - new LightInfo(), - SceneFlags.TRANSPARENT_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.GEOMETRY); - } -} - export function updateCameraUBO (setter: any, camera: Readonly, ppl: Readonly): void { const pipeline = cclegacy.director.root.pipeline; const sceneData = ppl.pipelineSceneData; @@ -1485,18 +1348,10 @@ function _buildSSSSBlurPass (camera: Camera, sampler.minFilter = Filter.POINT; sampler.magFilter = Filter.POINT; sampler.mipFilter = Filter.NONE; - const computeView = new ComputeView(); - computeView.name = 'depthRaw'; - copyInputDSPass.addComputeView(inputDS, computeView); + copyInputDSPass.addTexture(inputDS, 'depthRaw'); } - const copyInputDSPassView = new RasterView('_', - AccessType.WRITE, - AttachmentType.RENDER_TARGET, - LoadOp.CLEAR, - StoreOp.STORE, - camera.clearFlag, - new Color(1.0, 0.0, 0.0, 0.0)); - copyInputDSPass.addRasterView(ssssBlurDSName, copyInputDSPassView); + copyInputDSPass.addRenderTarget(ssssBlurDSName, + LoadOp.CLEAR, StoreOp.STORE, new Color(1.0, 0.0, 0.0, 0.0)); copyInputDSPass.addQueue(QueueHint.RENDER_OPAQUE | QueueHint.RENDER_TRANSPARENT).addCameraQuad( camera, ssssBlurData.ssssBlurMaterial, COPY_INPUT_DS_PASS_INDEX, SceneFlags.NONE, @@ -1512,9 +1367,7 @@ function _buildSSSSBlurPass (camera: Camera, sampler.minFilter = Filter.POINT; sampler.magFilter = Filter.POINT; sampler.mipFilter = Filter.NONE; - const computeView = new ComputeView(); - computeView.name = 'colorTex'; - ssssblurXPass.addComputeView(inputRT, computeView); + ssssblurXPass.addTexture(inputRT, 'colorTex'); } if (ppl.containsResource(ssssBlurDSName)) { const verId = webPipeline.resourceGraph.vertex(ssssBlurDSName); @@ -1522,26 +1375,11 @@ function _buildSSSSBlurPass (camera: Camera, sampler.minFilter = Filter.POINT; sampler.magFilter = Filter.POINT; sampler.mipFilter = Filter.NONE; - const computeView = new ComputeView(); - computeView.name = 'depthTex'; - ssssblurXPass.addComputeView(ssssBlurDSName, computeView); + ssssblurXPass.addTexture(ssssBlurDSName, 'depthTex'); } - const ssssBlurXPassRTView = new RasterView('_', - AccessType.WRITE, - AttachmentType.RENDER_TARGET, - LoadOp.CLEAR, - StoreOp.STORE, - camera.clearFlag, - ssssBlurClearColor); - ssssblurXPass.addRasterView(ssssBlurRTName, ssssBlurXPassRTView); - const ssssBlurXPassDSView = new RasterView('_', - AccessType.WRITE, - AttachmentType.DEPTH_STENCIL, - LoadOp.LOAD, - StoreOp.STORE, - camera.clearFlag, - new Color(camera.clearDepth, camera.clearStencil, 0.0, 0.0)); - ssssblurXPass.addRasterView(inputDS, ssssBlurXPassDSView); + ssssblurXPass.addRenderTarget(ssssBlurRTName, LoadOp.CLEAR, StoreOp.STORE, ssssBlurClearColor); + ssssblurXPass.addDepthStencil(inputDS, LoadOp.LOAD, StoreOp.STORE, + camera.clearDepth, camera.clearStencil, camera.clearFlag); ssssBlurData.ssssBlurMaterial.setProperty('blurInfo', new Vec4(ssssBlurData.ssssFov, ssssBlurData.ssssWidth, ssssBlurData.boundingBox, ssssBlurData.ssssScale), SSSS_BLUR_X_PASS_INDEX); ssssBlurData.ssssBlurMaterial.setProperty('kernel', ssssBlurData.kernel, SSSS_BLUR_X_PASS_INDEX); @@ -1560,9 +1398,7 @@ function _buildSSSSBlurPass (camera: Camera, sampler.minFilter = Filter.POINT; sampler.magFilter = Filter.POINT; sampler.mipFilter = Filter.NONE; - const computeView = new ComputeView(); - computeView.name = 'colorTex'; - ssssblurYPass.addComputeView(ssssBlurRTName, computeView); + ssssblurYPass.addTexture(ssssBlurRTName, 'colorTex'); } if (ppl.containsResource(ssssBlurDSName)) { const verId = webPipeline.resourceGraph.vertex(ssssBlurDSName); @@ -1570,26 +1406,11 @@ function _buildSSSSBlurPass (camera: Camera, sampler.minFilter = Filter.POINT; sampler.magFilter = Filter.POINT; sampler.mipFilter = Filter.NONE; - const computeView = new ComputeView(); - computeView.name = 'depthTex'; - ssssblurYPass.addComputeView(ssssBlurDSName, computeView); + ssssblurYPass.addTexture(ssssBlurDSName, 'depthTex'); } - const ssssBlurYPassView = new RasterView('_', - AccessType.WRITE, - AttachmentType.RENDER_TARGET, - LoadOp.LOAD, - StoreOp.STORE, - camera.clearFlag, - ssssBlurClearColor); - ssssblurYPass.addRasterView(inputRT, ssssBlurYPassView); - const ssssBlurYPassDSView = new RasterView('_', - AccessType.WRITE, - AttachmentType.DEPTH_STENCIL, - LoadOp.LOAD, - StoreOp.STORE, - camera.clearFlag, - new Color(camera.clearDepth, camera.clearStencil, 0.0, 0.0)); - ssssblurYPass.addRasterView(inputDS, ssssBlurYPassDSView); + ssssblurYPass.addRenderTarget(inputRT, LoadOp.LOAD, StoreOp.STORE, ssssBlurClearColor); + ssssblurYPass.addDepthStencil(inputDS, LoadOp.LOAD, StoreOp.STORE, + camera.clearDepth, camera.clearStencil, camera.clearFlag); ssssBlurData.ssssBlurMaterial.setProperty('blurInfo', new Vec4(ssssBlurData.ssssFov, ssssBlurData.ssssWidth, ssssBlurData.boundingBox, ssssBlurData.ssssScale), SSSS_BLUR_Y_PASS_INDEX); ssssBlurData.ssssBlurMaterial.setProperty('kernel', ssssBlurData.kernel, SSSS_BLUR_Y_PASS_INDEX); @@ -1651,24 +1472,15 @@ export function buildToneMappingPass (camera: Camera, toneMappingPass.name = `CameraToneMappingPass${cameraID}`; toneMappingPass.setViewport(new Viewport(area.x, area.y, area.width, area.height)); if (ppl.containsResource(inputRT)) { - const computeView = new ComputeView(); - computeView.name = 'u_texSampler'; - toneMappingPass.addComputeView(inputRT, computeView); + toneMappingPass.addTexture(inputRT, 'u_texSampler'); } - const toneMappingPassView = new RasterView('_', - AccessType.WRITE, AttachmentType.RENDER_TARGET, + toneMappingPass.addRenderTarget(toneMappingPassRTName, getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.RENDER_TARGET), - StoreOp.STORE, - camera.clearFlag, - toneMappingClearColor); - const toneMappingPassDSView = new RasterView('_', - AccessType.WRITE, AttachmentType.DEPTH_STENCIL, + StoreOp.STORE, toneMappingClearColor); + toneMappingPass.addDepthStencil(toneMappingPassDS, getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.DEPTH_STENCIL), StoreOp.STORE, - camera.clearFlag, - new Color(camera.clearDepth, camera.clearStencil, 0, 0)); - toneMappingPass.addRasterView(toneMappingPassRTName, toneMappingPassView); - toneMappingPass.addRasterView(toneMappingPassDS, toneMappingPassDSView); + camera.clearDepth, camera.clearStencil, camera.clearFlag); toneMappingPass.addQueue(QueueHint.NONE).addFullscreenQuad( toneMappingInfo.toneMappingMaterial, 0, SceneFlags.NONE, ); @@ -1707,22 +1519,12 @@ export function buildTransparencyPass (camera: Camera, alphaPass.addTexture(spotShadowName, 'cc_spotShadowMap'); } } - const alphaPassView = new RasterView('_', - AccessType.WRITE, - AttachmentType.RENDER_TARGET, - LoadOp.LOAD, - StoreOp.STORE, - camera.clearFlag, + alphaPass.addRenderTarget(inputRT, + LoadOp.LOAD, StoreOp.STORE, new Color(camera.clearDepth, camera.clearStencil, 0, 0)); - const alphaPassDSView = new RasterView('_', - AccessType.WRITE, - AttachmentType.DEPTH_STENCIL, - LoadOp.LOAD, - StoreOp.STORE, - camera.clearFlag, - new Color(camera.clearDepth, camera.clearStencil, 0, 0)); - alphaPass.addRasterView(inputRT, alphaPassView); - alphaPass.addRasterView(inputDS, alphaPassDSView); + alphaPass.addDepthStencil(inputDS, + LoadOp.LOAD, StoreOp.STORE, + camera.clearDepth, camera.clearStencil, camera.clearFlag); alphaPass .addQueue(QueueHint.RENDER_TRANSPARENT) .addSceneOfCamera(camera, new LightInfo(), SceneFlags.TRANSPARENT_OBJECT | SceneFlags.GEOMETRY); @@ -1748,32 +1550,20 @@ function _buildSpecularPass (camera: Camera, specalurPass.setViewport(new Viewport(area.x, area.y, width, height)); for (const dirShadowName of cameraInfo.mainLightShadowNames) { if (ppl.containsResource(dirShadowName)) { - const computeView = new ComputeView('cc_shadowMap'); - specalurPass.addComputeView(dirShadowName, computeView); + specalurPass.addTexture(dirShadowName, 'cc_shadowMap'); } } for (const spotShadowName of cameraInfo.spotLightShadowNames) { if (ppl.containsResource(spotShadowName)) { - const computeView = new ComputeView('cc_spotShadowMap'); - specalurPass.addComputeView(spotShadowName, computeView); + specalurPass.addTexture(spotShadowName, 'cc_spotShadowMap'); } } - const passView = new RasterView('_', - AccessType.WRITE, - AttachmentType.RENDER_TARGET, - LoadOp.LOAD, - StoreOp.STORE, - camera.clearFlag, + specalurPass.addRenderTarget(inputRT, + LoadOp.LOAD, StoreOp.STORE, new Color(camera.clearColor.x, camera.clearColor.y, camera.clearColor.z, camera.clearColor.w)); - const passDSView = new RasterView('_', - AccessType.WRITE, - AttachmentType.DEPTH_STENCIL, - LoadOp.LOAD, - StoreOp.STORE, - camera.clearFlag, - new Color(camera.clearDepth, camera.clearStencil, 0, 0)); - specalurPass.addRasterView(inputRT, passView); - specalurPass.addRasterView(inputDS, passDSView); + specalurPass.addDepthStencil(inputDS, + LoadOp.LOAD, StoreOp.STORE, + camera.clearDepth, camera.clearStencil, camera.clearFlag); specalurPass .addQueue(QueueHint.RENDER_OPAQUE, 'default') .addSceneOfCamera(camera, new LightInfo(), @@ -1907,9 +1697,6 @@ class HBAOParams { this.randomTexture.setMipFilter(Texture2D.Filter.NONE); this.randomTexture.setWrapMode(Texture2D.WrapMode.REPEAT, Texture2D.WrapMode.REPEAT, Texture2D.WrapMode.REPEAT); this.randomTexture.image = image; - if (!this.randomTexture.getGFXTexture()) { - console.warn('Unexpected: failed to create ao texture?'); - } this.hbaoMaterial.setProperty('RandomTex', this.randomTexture, 0); } @@ -1977,9 +1764,7 @@ function _buildHBAOPass (camera: Camera, sampler.minFilter = sampler.magFilter = Filter.POINT; sampler.mipFilter = Filter.NONE; sampler.addressU = sampler.addressV = Address.CLAMP; - const computeView = new ComputeView(); - computeView.name = 'DepthTex'; - hbaoPass.addComputeView(inputDS, computeView); + hbaoPass.addTexture(inputDS, 'DepthTex'); } hbaoPass.addRenderTarget( hbaoRTName, @@ -2040,9 +1825,7 @@ function _buildHBAOBlurPass (camera: Camera, sampler.minFilter = sampler.magFilter = Filter.POINT; sampler.mipFilter = Filter.NONE; sampler.addressU = sampler.addressV = Address.CLAMP; - const computeView = new ComputeView(); - computeView.name = 'DepthTex'; - blurPass.addComputeView(inputDS, computeView); + blurPass.addTexture(inputDS, 'DepthTex'); } if (ppl.containsResource(inputRTName)) { const webPipeline = (ppl as WebPipeline); @@ -2051,9 +1834,7 @@ function _buildHBAOBlurPass (camera: Camera, sampler.minFilter = sampler.magFilter = Filter.LINEAR; sampler.mipFilter = Filter.NONE; sampler.addressU = sampler.addressV = Address.CLAMP; - const computeView = new ComputeView(); - computeView.name = 'AOTexNearest'; - blurPass.addComputeView(inputRTName, computeView); + blurPass.addTexture(inputRTName, 'AOTexNearest'); } blurPass.addRenderTarget( outputRTName, @@ -2104,9 +1885,7 @@ function _buildHBAOCombinedPass (camera: Camera, sampler.minFilter = sampler.magFilter = Filter.LINEAR; sampler.mipFilter = Filter.NONE; sampler.addressU = sampler.addressV = Address.CLAMP; - const computeView = new ComputeView(); - computeView.name = 'AOTexNearest'; - hbaoPass.addComputeView(inputRTName, computeView); + hbaoPass.addTexture(inputRTName, 'AOTexNearest'); } hbaoPass.addRenderTarget( @@ -2226,9 +2005,9 @@ export function buildLightClusterBuildPass (camera: Camera, clusterData: Cluster const cameraID = getCameraUniqueID(camera); const clusterBufferName = `clusterBuffer${cameraID}`; - const clusterBufferSize = CLUSTER_COUNT * 2 * 4; + const clusterBufferSize = CLUSTER_COUNT * 2 * 4 * 4; if (!ppl.containsResource(clusterBufferName)) { - ppl.addStorageBuffer(clusterBufferName, Format.UNKNOWN, clusterBufferSize, ResourceResidency.PERSISTENT); + ppl.addStorageBuffer(clusterBufferName, Format.UNKNOWN, clusterBufferSize, ResourceResidency.MANAGED); } ppl.updateStorageBuffer(clusterBufferName, clusterBufferSize); @@ -2240,7 +2019,7 @@ export function buildLightClusterBuildPass (camera: Camera, clusterData: Cluster const width = camera.width * ppl.pipelineSceneData.shadingScale; const height = camera.height * ppl.pipelineSceneData.shadingScale; clusterPass.setVec4('cc_nearFar', new Vec4(camera.nearClip, camera.farClip, 0, 0)); - clusterPass.setVec4('cc_viewPort', new Vec4(width, height, width, height)); + clusterPass.setVec4('cc_viewPort', new Vec4(0, 0, width, height)); clusterPass.setVec4('cc_workGroup', new Vec4(CLUSTERS_X, CLUSTERS_Y, CLUSTERS_Z, 0)); clusterPass.setMat4('cc_matView', camera.matView); clusterPass.setMat4('cc_matProjInv', camera.matProjInv); @@ -2251,18 +2030,18 @@ export function buildLightClusterCullingPass (camera: Camera, clusterData: Clust const cameraID = getCameraUniqueID(camera); const clusterBufferName = `clusterBuffer${cameraID}`; const clusterLightBufferName = `clusterLightBuffer${cameraID}`; - const clusterGlobalIndexBufferName = `b_globalIndexBuffer${cameraID}`; - const clusterLightIndicesBufferName = `clusterLIghtIndicesBuffer${cameraID}`; + const clusterGlobalIndexBufferName = `globalIndexBuffer${cameraID}`; + const clusterLightIndicesBufferName = `clusterLightIndicesBuffer${cameraID}`; const clusterLightGridBufferName = `clusterLightGridBuffer${cameraID}`; // index buffer const lightIndexBufferSize = MAX_LIGHTS_PER_CLUSTER * CLUSTER_COUNT * 4; const lightGridBufferSize = CLUSTER_COUNT * 4 * 4; if (!ppl.containsResource(clusterLightIndicesBufferName)) { - ppl.addStorageBuffer(clusterLightIndicesBufferName, Format.UNKNOWN, lightIndexBufferSize, ResourceResidency.PERSISTENT); + ppl.addStorageBuffer(clusterLightIndicesBufferName, Format.UNKNOWN, lightIndexBufferSize, ResourceResidency.MANAGED); } if (!ppl.containsResource(clusterLightGridBufferName)) { - ppl.addStorageBuffer(clusterLightGridBufferName, Format.UNKNOWN, lightGridBufferSize, ResourceResidency.PERSISTENT); + ppl.addStorageBuffer(clusterLightGridBufferName, Format.UNKNOWN, lightGridBufferSize, ResourceResidency.MANAGED); } const clusterPass = ppl.addComputePass('cluster-culling-cs'); @@ -2283,44 +2062,23 @@ export function buildLightClusterCullingPass (camera: Camera, clusterData: Clust clusterPass.setMat4('cc_matProjInv', camera.matProjInv); } -export function buildLightData (camera: Camera, pipeline: BasicPipeline): void { - validPunctualLightsCulling(pipeline, camera); +export function buildLightBuffer (size: number, floatPerLight: number, camera: Camera, pipeline: BasicPipeline): ArrayBuffer { + const buffer = new ArrayBuffer(size); + const view = new Float32Array(buffer); - // build cluster light data const data = pipeline.pipelineSceneData; - const validLightCountForBuffer = nextPow2(Math.max(data.validPunctualLights.length, 1)); - - const lightBufferStride = 16; // 4 * vec4 - const clusterLightBufferSize = validLightCountForBuffer * 4 * lightBufferStride; - const lightMeterScale = 10000.0; const exposure = camera.exposure; - const cameraID = getCameraUniqueID(camera); - const clusterLightBufferName = `clusterLightBuffer${cameraID}`; - const clusterGlobalIndexBufferName = `b_globalIndexBuffer${cameraID}`; - - const ppl = (pipeline as Pipeline); - if (!ppl.containsResource(clusterGlobalIndexBufferName)) { - ppl.addStorageBuffer(clusterGlobalIndexBufferName, Format.UNKNOWN, 4, ResourceResidency.PERSISTENT); - } - - if (!ppl.containsResource(clusterLightBufferName)) { - ppl.addStorageBuffer(clusterLightBufferName, Format.UNKNOWN, clusterLightBufferSize, ResourceResidency.PERSISTENT); - } - ppl.updateStorageBuffer(clusterLightBufferName, clusterLightBufferSize); - - const buffer = new ArrayBuffer(clusterLightBufferSize); - const view = new Float32Array(buffer); - // gather light data let index = 0; for (const light of data.validPunctualLights) { - const offset = index * lightBufferStride; + const offset = index * floatPerLight; const positionOffset = offset + 0; const colorOffset = offset + 4; const sizeRangeAngleOffset = offset + 8; const directionOffset = offset + 12; + const boundSizeOffset = offset + 16; let luminanceHDR = 0; let luminanceLDR = 0; @@ -2378,6 +2136,12 @@ export function buildLightData (camera: Camera, pipeline: BasicPipeline): void { view[directionOffset + 1] = dir.y; view[directionOffset + 2] = dir.z; view[directionOffset + 3] = 0; + + const scale = directional.scale; + view[boundSizeOffset] = scale.x * 0.5; + view[boundSizeOffset + 1] = scale.y * 0.5; + view[boundSizeOffset + 2] = scale.z * 0.5; + view[boundSizeOffset + 3] = 0; } // position view[positionOffset] = position!.x; @@ -2402,6 +2166,38 @@ export function buildLightData (camera: Camera, pipeline: BasicPipeline): void { } // last float of first light data view[3 * 4 + 3] = data.validPunctualLights.length; + return buffer; +} + +export function buildStandardLightData (camera: Camera, pipeline: BasicPipeline): void { + validPunctualLightsCulling(pipeline, camera); +} + +export function buildClusterLightData (camera: Camera, pipeline: BasicPipeline): void { + validPunctualLightsCulling(pipeline, camera); + + // build cluster light data + const data = pipeline.pipelineSceneData; + const validLightCountForBuffer = nextPow2(Math.max(data.validPunctualLights.length, 1)); + + const lightBufferFloatNum = 20; // 5 * vec4 + const clusterLightBufferSize = validLightCountForBuffer * 4 * lightBufferFloatNum; + + const cameraID = getCameraUniqueID(camera); + const clusterLightBufferName = `clusterLightBuffer${cameraID}`; + const clusterGlobalIndexBufferName = `globalIndexBuffer${cameraID}`; + + const ppl = (pipeline as Pipeline); + if (!ppl.containsResource(clusterGlobalIndexBufferName)) { + ppl.addStorageBuffer(clusterGlobalIndexBufferName, Format.UNKNOWN, 4, ResourceResidency.PERSISTENT); + } + + if (!ppl.containsResource(clusterLightBufferName)) { + ppl.addStorageBuffer(clusterLightBufferName, Format.UNKNOWN, clusterLightBufferSize, ResourceResidency.PERSISTENT); + } + ppl.updateStorageBuffer(clusterLightBufferName, clusterLightBufferSize); + + const buffer = buildLightBuffer(clusterLightBufferSize, lightBufferFloatNum, camera, pipeline); // global index buffer const globalIndexBuffer = new ArrayBuffer(4); @@ -2414,7 +2210,7 @@ export function buildLightData (camera: Camera, pipeline: BasicPipeline): void { } export function buildClusterPasses (camera: Camera, pipeline: BasicPipeline): void { - buildLightData(camera, pipeline); + buildClusterLightData(camera, pipeline); const ppl = (pipeline as Pipeline); if (!_clusterLightData) _clusterLightData = new ClusterLightData(); diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index 9257584bf8..239cc53a9b 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -49,12 +49,11 @@ import { DescriptorSetData, LayoutGraphData, PipelineLayoutData, RenderPhaseData import { BasicPipeline, SceneVisitor } from './pipeline'; import { Blit, ClearView, ComputePass, ComputeSubpass, CopyPass, Dispatch, FormatView, ManagedBuffer, ManagedResource, ManagedTexture, MovePass, RasterPass, RasterSubpass, RaytracePass, RenderData, RenderGraph, RenderGraphVisitor, RenderQueue, RenderSwapchain, ResolvePass, ResourceDesc, - ResourceGraph, ResourceGraphVisitor, ResourceTraits, SceneData, SubresourceView } from './render-graph'; -import { AttachmentType, ComputeView, QueueHint, RasterView, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UpdateFrequency } from './types'; + ResourceGraph, ResourceGraphVisitor, ResourceTraits, SceneData, SubresourceView, ComputeView, RasterView } from './render-graph'; +import { AttachmentType, QueueHint, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UpdateFrequency } from './types'; import { PipelineUBO } from '../pipeline-ubo'; import { RenderInfo, RenderObject, WebSceneTask, WebSceneTransversal } from './web-scene'; import { WebSceneVisitor } from './web-scene-visitor'; -import { stringify } from './utils'; import { RenderAdditiveLightQueue } from '../render-additive-light-queue'; import { RenderShadowMapBatchedQueue } from '../render-shadow-map-batched-queue'; import { PlanarShadowQueue } from '../planar-shadow-queue'; diff --git a/cocos/rendering/custom/pipeline-define.ts b/cocos/rendering/custom/pipeline-define.ts index 339988d44b..87d6a02dd3 100644 --- a/cocos/rendering/custom/pipeline-define.ts +++ b/cocos/rendering/custom/pipeline-define.ts @@ -4,11 +4,28 @@ import { ClearFlagBit, Color, Format, LoadOp, StoreOp, Viewport } from '../../gf import { RenderWindow } from '../../render-scene/core/render-window'; import { Camera, Light, LightType, ProbeType, ReflectionProbe, ShadowType } from '../../render-scene/scene'; import { supportsR32FloatTexture } from '../define'; -import { AntiAliasing, GBufferInfo, getRTFormatBeforeToneMapping, LightingInfo, PostInfo, ShadowInfo, getLoadOpOfClearFlag, - getRenderArea, updateCameraUBO, validPunctualLightsCulling } from './define'; -import { BasicPipeline, BasicRenderPassBuilder } from './pipeline'; -import { AttachmentType, LightInfo, QueueHint, ResourceResidency, SceneFlags } from './types'; -import { SRGBToLinear, getProfilerCamera } from '../pipeline-funcs'; +import { + GBufferInfo, + getCameraUniqueID, + getLoadOpOfClearFlag, + getRenderArea, + getRTFormatBeforeToneMapping, + LightingInfo, + PostInfo, + ShadowInfo, + updateCameraUBO, + validPunctualLightsCulling, +} from './define'; +import { BasicPipeline, Pipeline, BasicRenderPassBuilder } from './pipeline'; +import { + AccessType, + AttachmentType, + LightInfo, + QueueHint, + ResourceResidency, + SceneFlags, +} from './types'; +import { getProfilerCamera, SRGBToLinear } from '../pipeline-funcs'; export class CameraInfo { constructor (camera: Camera, id: number, windowID: number, width: number, height: number) { @@ -50,9 +67,6 @@ export function prepareResource (ppl: BasicPipeline, camera: Camera, height = 1; } const windowID = prepareRenderWindow(camera); - if (info.width !== width || info.height !== height || info.windowID !== windowID) { - return info; - } updateResourceFunc(ppl, info); return info; } @@ -221,6 +235,34 @@ export function updateForwardRes (ppl: BasicPipeline, cameraInfo: CameraInfo, is ppl.updateDepthStencil(`ForwardDepthStencil${cameraInfo.id}`, width, height); } +export function setupDeferredForward (ppl: BasicPipeline, cameraInfo: CameraInfo, inputColor: string): void { + const area = getRenderArea(cameraInfo.camera, cameraInfo.camera.window.width, cameraInfo.camera.window.height); + const width = area.width; + const height = area.height; + const forwardPass = ppl.addRenderPass(width, height, 'default'); + const camera = cameraInfo.camera; + forwardPass.addRenderTarget(inputColor, LoadOp.LOAD, StoreOp.STORE); + forwardPass.addDepthStencil(gBufferInfo.ds, LoadOp.LOAD, StoreOp.DISCARD); + + for (const dirShadowName of shadowInfo.mainLightShadowNames) { + if (ppl.containsResource(dirShadowName)) { + forwardPass.addTexture(dirShadowName, 'cc_shadowMap'); + } + } + for (const spotShadowName of shadowInfo.spotLightShadowNames) { + if (ppl.containsResource(spotShadowName)) { + forwardPass.addTexture(spotShadowName, 'cc_spotShadowMap'); + } + } + + forwardPass.addQueue(QueueHint.RENDER_OPAQUE, 'deferred-forward') + .addSceneOfCamera(camera, new LightInfo(), + SceneFlags.OPAQUE_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.CUTOUT_OBJECT + | SceneFlags.DEFAULT_LIGHTING | SceneFlags.DRAW_INSTANCING); + forwardPass.addQueue(QueueHint.RENDER_TRANSPARENT, 'deferred-forward') + .addSceneOfCamera(camera, new LightInfo(), SceneFlags.TRANSPARENT_OBJECT | SceneFlags.GEOMETRY); +} + export function setupForwardPass (ppl: BasicPipeline, cameraInfo: CameraInfo, isOffScreen = false, enabledAlpha = true): { rtName: string; dsName: string; } { if (EDITOR) { ppl.setMacroInt('CC_PIPELINE_TYPE', 0); @@ -260,6 +302,7 @@ export function setupForwardPass (ppl: BasicPipeline, cameraInfo: CameraInfo, is .addSceneOfCamera(camera, new LightInfo(), SceneFlags.OPAQUE_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.CUTOUT_OBJECT | SceneFlags.DEFAULT_LIGHTING | SceneFlags.DRAW_INSTANCING); + let sceneFlags = SceneFlags.TRANSPARENT_OBJECT | SceneFlags.GEOMETRY; if (!isOffScreen) { sceneFlags |= SceneFlags.UI; @@ -283,7 +326,7 @@ export function buildReflectionProbeRes (ppl: BasicPipeline, probe: ReflectionPr if (!ppl.containsResource(probePassRTName)) { ppl.addRenderWindow(probePassRTName, Format.RGBA8, width, height, renderWindow); - ppl.addDepthStencil(probePassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.EXTERNAL); + ppl.addDepthStencil(probePassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); } ppl.updateRenderWindow(probePassRTName, renderWindow); ppl.updateDepthStencil(probePassDSName, width, height); @@ -357,14 +400,14 @@ export function setupGBufferRes (ppl: BasicPipeline, info: CameraInfo): void { const area = getRenderArea(camera, camera.window.width, camera.window.height); const width = area.width; const height = area.height; - const gBufferPassRTName = `gBufferPassColorCamera`; - const gBufferPassNormal = `gBufferPassNormal`; - const gBufferPassEmissive = `gBufferPassEmissive`; - const gBufferPassDSName = `gBufferPassDSCamera`; + const gBufferPassRTName = `gBufferPassColorCamera${info.id}`; + const gBufferPassNormal = `gBufferPassNormal${info.id}`; + const gBufferPassEmissive = `gBufferPassEmissive${info.id}`; + const gBufferPassDSName = `gBufferPassDSCamera${info.id}`; const colFormat = Format.RGBA16F; ppl.addRenderTarget(gBufferPassRTName, colFormat, width, height, ResourceResidency.MANAGED); - ppl.addRenderTarget(gBufferPassNormal, colFormat, width, height, ResourceResidency.MANAGED); ppl.addRenderTarget(gBufferPassEmissive, colFormat, width, height, ResourceResidency.MANAGED); + ppl.addRenderTarget(gBufferPassNormal, colFormat, width, height, ResourceResidency.MANAGED); ppl.addDepthStencil(gBufferPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); gBufferInfo.color = gBufferPassRTName; gBufferInfo.normal = gBufferPassNormal; @@ -377,16 +420,86 @@ export function updateGBufferRes (ppl: BasicPipeline, info: CameraInfo): void { const area = getRenderArea(camera, camera.window.width, camera.window.height); const width = area.width; const height = area.height; - const gBufferPassRTName = `gBufferPassColorCamera`; - const gBufferPassNormal = `gBufferPassNormal`; - const gBufferPassEmissive = `gBufferPassEmissive`; - const gBufferPassDSName = `gBufferPassDSCamera`; + const gBufferPassRTName = `gBufferPassColorCamera${info.id}`; + const gBufferPassNormal = `gBufferPassNormal${info.id}`; + const gBufferPassEmissive = `gBufferPassEmissive${info.id}`; + const gBufferPassDSName = `gBufferPassDSCamera${info.id}`; ppl.updateRenderTarget(gBufferPassRTName, width, height); - ppl.updateRenderTarget(gBufferPassNormal, width, height); ppl.updateRenderTarget(gBufferPassEmissive, width, height); + ppl.updateRenderTarget(gBufferPassNormal, width, height); ppl.updateDepthStencil(gBufferPassDSName, width, height); } +const emptyColor = new Color(0, 0, 0, 0); +export function setupScenePassTiled (pipeline: BasicPipeline, info: CameraInfo, useCluster: boolean): { rtName: string } { + if (!lightingInfo) { + lightingInfo = new LightingInfo(useCluster); + } + + const ppl = (pipeline as Pipeline); + const camera = info.camera; + const cameraID = getCameraUniqueID(camera); + const area = getRenderArea(camera, camera.window.width, camera.window.height); + const width = area.width; + const height = area.height; + const gBufferPassRTName = gBufferInfo.color; + const gBufferPassNormal = gBufferInfo.normal; + const gBufferPassEmissive = gBufferInfo.emissive; + const gBufferPassDSName = gBufferInfo.ds; + const scenePass = ppl.addRenderPass(width, height, 'deferred-scene-tiled'); + + // gbuffer subpass + const gBufferPass = scenePass.addRenderSubpass('gbuffer-tiled'); + gBufferPass.name = `CameraGBufferPass${info.id}`; + gBufferPass.setViewport(new Viewport(area.x, area.y, width, height)); + const rtColor = new Color(0, 0, 0, 0); + if (camera.clearFlag & ClearFlagBit.COLOR) { + if (ppl.pipelineSceneData.isHDR) { + SRGBToLinear(rtColor, camera.clearColor); + } else { + rtColor.x = camera.clearColor.x; + rtColor.y = camera.clearColor.y; + rtColor.z = camera.clearColor.z; + } + } + gBufferPass.addRenderTarget(gBufferPassRTName, AccessType.WRITE, '_', LoadOp.CLEAR, StoreOp.DISCARD, emptyColor); + gBufferPass.addRenderTarget(gBufferPassNormal, AccessType.WRITE, '_', LoadOp.CLEAR, StoreOp.DISCARD, emptyColor); + gBufferPass.addRenderTarget(gBufferPassEmissive, AccessType.WRITE, '_', LoadOp.CLEAR, StoreOp.DISCARD, emptyColor); + gBufferPass.addDepthStencil(gBufferPassDSName, AccessType.WRITE, '_', '_', + LoadOp.CLEAR, StoreOp.DISCARD, camera.clearDepth, camera.clearStencil, camera.clearFlag); + gBufferPass + .addQueue(QueueHint.RENDER_OPAQUE, 'gbuffer-tiled') + .addSceneOfCamera(camera, new LightInfo(), SceneFlags.OPAQUE_OBJECT | SceneFlags.CUTOUT_OBJECT); + + // lighting subpass + const lightingPass = scenePass.addRenderSubpass('deferred-lighting-tiled'); + lightingPass.name = `CameraLightingPass${info.id}`; + lightingPass.setViewport(new Viewport(area.x, area.y, width, height)); + + lightingPass.addRenderTarget(gBufferPassRTName, AccessType.READ, 'albedoMap', LoadOp.DISCARD, StoreOp.DISCARD); + lightingPass.addRenderTarget(gBufferPassNormal, AccessType.READ, 'normalMap', LoadOp.DISCARD, StoreOp.DISCARD); + lightingPass.addRenderTarget(gBufferPassEmissive, AccessType.READ, 'emissiveMap', LoadOp.DISCARD, StoreOp.DISCARD); + lightingPass.addDepthStencil(gBufferPassDSName, AccessType.READ, 'depthStencil', '_', LoadOp.DISCARD, StoreOp.DISCARD); + + // cluster data + const clusterLightBufferName = `clusterLightBuffer${cameraID}`; + const clusterLightIndicesBufferName = `clusterLightIndicesBuffer${cameraID}`; + const clusterLightGridBufferName = `clusterLightGridBuffer${cameraID}`; + if (ppl.containsResource(clusterLightBufferName)) { + lightingPass.addStorageBuffer(clusterLightBufferName, AccessType.READ, 'b_ccLightsBuffer'); + lightingPass.addStorageBuffer(clusterLightIndicesBufferName, AccessType.READ, 'b_clusterLightIndicesBuffer'); + lightingPass.addStorageBuffer(clusterLightGridBufferName, AccessType.READ, 'b_clusterLightGridBuffer'); + } + + const deferredLightingPassRTName = `deferredLightingPassRTName${info.id}`; + lightingPass.addRenderTarget(deferredLightingPassRTName, AccessType.WRITE, '_', LoadOp.CLEAR, StoreOp.STORE, rtColor); + lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT, 'deferred-lighting-tiled').addCameraQuad( + camera, lightingInfo.deferredLightingMaterial, 1, + SceneFlags.VOLUMETRIC_LIGHTING, + ); + return { rtName: deferredLightingPassRTName }; +} + export function setupGBufferPass (ppl: BasicPipeline, info: CameraInfo): BasicRenderPassBuilder { const camera = info.camera; const area = getRenderArea(camera, camera.window.width, camera.window.height); @@ -397,7 +510,7 @@ export function setupGBufferPass (ppl: BasicPipeline, info: CameraInfo): BasicRe const gBufferPassEmissive = gBufferInfo.emissive; const gBufferPassDSName = gBufferInfo.ds; // gbuffer pass - const gBufferPass = ppl.addRenderPass(width, height, 'default'); + const gBufferPass = ppl.addRenderPass(width, height, 'gbuffer'); gBufferPass.name = `CameraGBufferPass${info.id}`; gBufferPass.setViewport(new Viewport(area.x, area.y, width, height)); const rtColor = new Color(0, 0, 0, 0); @@ -411,11 +524,11 @@ export function setupGBufferPass (ppl: BasicPipeline, info: CameraInfo): BasicRe } } gBufferPass.addRenderTarget(gBufferPassRTName, LoadOp.CLEAR, StoreOp.STORE, rtColor); - gBufferPass.addRenderTarget(gBufferPassNormal, LoadOp.CLEAR, StoreOp.STORE, new Color(0, 0, 0, 0)); gBufferPass.addRenderTarget(gBufferPassEmissive, LoadOp.CLEAR, StoreOp.STORE, new Color(0, 0, 0, 0)); + gBufferPass.addRenderTarget(gBufferPassNormal, LoadOp.CLEAR, StoreOp.STORE, new Color(0, 0, 0, 0)); gBufferPass.addDepthStencil(gBufferPassDSName, LoadOp.CLEAR, StoreOp.STORE, camera.clearDepth, camera.clearStencil, camera.clearFlag); gBufferPass - .addQueue(QueueHint.RENDER_OPAQUE) + .addQueue(QueueHint.RENDER_OPAQUE, 'gbuffer') .addSceneOfCamera(camera, new LightInfo(), SceneFlags.OPAQUE_OBJECT | SceneFlags.CUTOUT_OBJECT); return gBufferPass; } @@ -427,10 +540,8 @@ export function setupLightingRes (ppl: BasicPipeline, info: CameraInfo): void { const width = area.width; const height = area.height; - const deferredLightingPassRTName = `deferredLightingPassRTName`; - const deferredLightingPassDS = `deferredLightingPassDS`; + const deferredLightingPassRTName = `deferredLightingPassRTName${info.id}`; ppl.addRenderTarget(deferredLightingPassRTName, Format.RGBA8, width, height, ResourceResidency.MANAGED); - ppl.addDepthStencil(deferredLightingPassDS, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); } export function updateLightingRes (ppl: BasicPipeline, info: CameraInfo): void { @@ -440,24 +551,23 @@ export function updateLightingRes (ppl: BasicPipeline, info: CameraInfo): void { const width = area.width; const height = area.height; - const deferredLightingPassRTName = `deferredLightingPassRTName`; - const deferredLightingPassDS = `deferredLightingPassDS`; + const deferredLightingPassRTName = `deferredLightingPassRTName${info.id}`; ppl.updateRenderTarget(deferredLightingPassRTName, width, height); - ppl.updateDepthStencil(deferredLightingPassDS, width, height); } let lightingInfo: LightingInfo; -export function setupLightingPass (ppl: BasicPipeline, info: CameraInfo): { rtName: string; dsName: string; } { - setupShadowPass(ppl, info); +export function setupLightingPass (pipeline: BasicPipeline, info: CameraInfo, useCluster: boolean): { rtName: string } { + setupShadowPass(pipeline, info); if (!lightingInfo) { - lightingInfo = new LightingInfo(); + lightingInfo = new LightingInfo(useCluster); } + const ppl = pipeline as Pipeline; const camera = info.camera; const area = getRenderArea(camera, camera.window.width, camera.window.height); const width = area.width; const height = area.height; + const cameraID = getCameraUniqueID(camera); - const deferredLightingPassRTName = `deferredLightingPassRTName`; - const deferredLightingPassDS = `deferredLightingPassDS`; + const deferredLightingPassRTName = `deferredLightingPassRTName${info.id}`; // lighting pass const lightingPass = ppl.addRenderPass(width, height, 'deferred-lighting'); lightingPass.name = `CameraLightingPass${info.id}`; @@ -473,11 +583,22 @@ export function setupLightingPass (ppl: BasicPipeline, info: CameraInfo): { rtNa } } if (ppl.containsResource(gBufferInfo.color)) { - lightingPass.addTexture(gBufferInfo.color, 'gbuffer_albedoMap'); - lightingPass.addTexture(gBufferInfo.normal, 'gbuffer_normalMap'); - lightingPass.addTexture(gBufferInfo.emissive, 'gbuffer_emissiveMap'); - lightingPass.addTexture(gBufferInfo.ds, 'depth_stencil'); + lightingPass.addTexture(gBufferInfo.color, 'albedoMap'); + lightingPass.addTexture(gBufferInfo.normal, 'normalMap'); + lightingPass.addTexture(gBufferInfo.emissive, 'emissiveMap'); + lightingPass.addTexture(gBufferInfo.ds, 'depthStencil'); } + + // cluster data + const clusterLightBufferName = `clusterLightBuffer${cameraID}`; + const clusterLightIndicesBufferName = `clusterLightIndicesBuffer${cameraID}`; + const clusterLightGridBufferName = `clusterLightGridBuffer${cameraID}`; + if (ppl.containsResource(clusterLightBufferName)) { + lightingPass.addStorageBuffer(clusterLightBufferName, AccessType.READ, 'b_ccLightsBuffer'); + lightingPass.addStorageBuffer(clusterLightIndicesBufferName, AccessType.READ, 'b_clusterLightIndicesBuffer'); + lightingPass.addStorageBuffer(clusterLightGridBufferName, AccessType.READ, 'b_clusterLightGridBuffer'); + } + const lightingClearColor = new Color(0, 0, 0, 0); if (camera.clearFlag & ClearFlagBit.COLOR) { lightingClearColor.x = camera.clearColor.x; @@ -492,7 +613,7 @@ export function setupLightingPass (ppl: BasicPipeline, info: CameraInfo): { rtNa ); // lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(), // SceneFlags.TRANSPARENT_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.GEOMETRY); - return { rtName: deferredLightingPassRTName, dsName: deferredLightingPassDS }; + return { rtName: deferredLightingPassRTName }; } export function setupPostprocessRes (ppl: BasicPipeline, info: CameraInfo): void { @@ -504,7 +625,7 @@ export function setupPostprocessRes (ppl: BasicPipeline, info: CameraInfo): void const postprocessPassRTName = `postprocessPassRTName${cameraID}`; const postprocessPassDS = `postprocessPassDS${cameraID}`; ppl.addRenderWindow(postprocessPassRTName, Format.BGRA8, width, height, camera.window); - ppl.addDepthStencil(postprocessPassDS, Format.DEPTH_STENCIL, width, height, ResourceResidency.EXTERNAL); + ppl.addDepthStencil(postprocessPassDS, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); } export function updatePostprocessRes (ppl: BasicPipeline, info: CameraInfo): void { @@ -549,8 +670,9 @@ export function setupPostprocessPass (ppl: BasicPipeline, postprocessPass.addDepthStencil(postprocessPassDS, getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.DEPTH_STENCIL), StoreOp.STORE, camera.clearDepth, camera.clearStencil, camera.clearFlag); - postprocessPass.addQueue(QueueHint.NONE).addFullscreenQuad( - postInfo.postMaterial, 0, SceneFlags.NONE, + postprocessPass.addQueue(QueueHint.NONE).addCameraQuad( + camera, postInfo.postMaterial, 0, + SceneFlags.NONE, ); if (getProfilerCamera() === camera) { postprocessPass.showStatistics = true; @@ -568,7 +690,7 @@ export function setupUIRes (ppl: BasicPipeline, const dsUIAndProfilerPassRTName = `dsUIAndProfilerPassColor${info.id}`; const dsUIAndProfilerPassDSName = `dsUIAndProfilerPassDS${info.id}`; ppl.addRenderWindow(dsUIAndProfilerPassRTName, Format.BGRA8, width, height, camera.window); - ppl.addDepthStencil(dsUIAndProfilerPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.EXTERNAL); + ppl.addDepthStencil(dsUIAndProfilerPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); } export function updateUIRes (ppl: BasicPipeline, diff --git a/cocos/rendering/custom/pipeline.ts b/cocos/rendering/custom/pipeline.ts index 5b55811c14..a705a5c139 100644 --- a/cocos/rendering/custom/pipeline.ts +++ b/cocos/rendering/custom/pipeline.ts @@ -36,7 +36,7 @@ import { GlobalDSManager } from '../global-descriptor-set-manager'; import { Mat4, Quat, Vec2, Vec4 } from '../../core/math'; import { MacroRecord } from '../../render-scene/core/pass-utils'; import { PipelineSceneData } from '../pipeline-scene-data'; -import { AccessType, ComputeView, CopyPair, LightInfo, MovePair, QueueHint, RasterView, ResolvePair, ResourceResidency, SceneFlags, TaskType, UpdateFrequency, UploadPair } from './types'; +import { AccessType, CopyPair, LightInfo, MovePair, QueueHint, ResolvePair, ResourceResidency, SceneFlags, TaskType, UpdateFrequency, UploadPair } from './types'; import { RenderWindow } from '../../render-scene/core/render-window'; import { Model } from '../../render-scene/scene'; @@ -157,14 +157,6 @@ export interface BasicRenderPassBuilder extends Setter { slotName: string, sampler?: Sampler | null, plane?: number): void; - /** - * @deprecated method will be removed in 3.9.0 - */ - addRasterView (name: string, view: RasterView): void; - /** - * @deprecated method will be removed in 3.9.0 - */ - addComputeView (name: string, view: ComputeView): void; addQueue (hint?: QueueHint, phaseName?: string): RenderQueueBuilder; setViewport (viewport: Viewport): void; setVersion (name: string, version: number): void; @@ -264,10 +256,6 @@ export interface RenderSubpassBuilder extends Setter { name: string, accessType: AccessType, slotName: string): void; - /** - * @deprecated method will be removed in 3.9.0 - */ - addComputeView (name: string, view: ComputeView): void; setViewport (viewport: Viewport): void; addQueue (hint?: QueueHint, phaseName?: string): RenderQueueBuilder; showStatistics: boolean; @@ -310,10 +298,6 @@ export interface ComputeSubpassBuilder extends Setter { name: string, accessType: AccessType, slotName: string): void; - /** - * @deprecated method will be removed in 3.9.0 - */ - addComputeView (name: string, view: ComputeView): void; addQueue (phaseName?: string): ComputeQueueBuilder; /** * @beta function signature might change @@ -361,10 +345,6 @@ export interface ComputePassBuilder extends Setter { accessType: AccessType, slotName: string): void; addMaterialTexture (resourceName: string, flags?: ShaderStageFlagBit): void; - /** - * @deprecated method will be removed in 3.9.0 - */ - addComputeView (name: string, view: ComputeView): void; addQueue (phaseName?: string): ComputeQueueBuilder; /** * @beta function signature might change diff --git a/cocos/rendering/custom/render-graph.ts b/cocos/rendering/custom/render-graph.ts index 5bc0d77a86..afbb675ef8 100644 --- a/cocos/rendering/custom/render-graph.ts +++ b/cocos/rendering/custom/render-graph.ts @@ -31,11 +31,81 @@ import { AdjI, AdjacencyGraph, BidirectionalGraph, ComponentGraph, ED, InEI, MutableGraph, MutableReferenceGraph, NamedGraph, OutE, OutEI, PolymorphicGraph, PropertyGraph, PropertyMap, ReferenceGraph, UuidGraph, VertexListGraph, directional, parallel, reindexEdgeList, traversal } from './graph'; import { Material } from '../../asset/assets'; import { Camera } from '../../render-scene/scene/camera'; -import { AccessFlagBit, Buffer, ClearFlagBit, Color, Format, Framebuffer, RenderPass, SampleCount, Sampler, SamplerInfo, ShaderStageFlagBit, Swapchain, Texture, TextureFlagBit, Viewport } from '../../gfx'; -import { ComputeView, CopyPair, LightInfo, MovePair, QueueHint, RasterView, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UploadPair } from './types'; +import { AccessFlagBit, Buffer, ClearFlagBit, Color, Format, Framebuffer, LoadOp, RenderPass, SampleCount, Sampler, SamplerInfo, ShaderStageFlagBit, StoreOp, Swapchain, Texture, TextureFlagBit, Viewport } from '../../gfx'; +import { AccessType, AttachmentType, ClearValueType, CopyPair, LightInfo, MovePair, QueueHint, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UploadPair } from './types'; import { RenderScene } from '../../render-scene/core/render-scene'; import { RenderWindow } from '../../render-scene/core/render-window'; +export class ClearValue { + constructor (x = 0, y = 0, z = 0, w = 0) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + x: number; + y: number; + z: number; + w: number; +} + +export class RasterView { + constructor ( + slotName = '', + accessType: AccessType = AccessType.WRITE, + attachmentType: AttachmentType = AttachmentType.RENDER_TARGET, + loadOp: LoadOp = LoadOp.LOAD, + storeOp: StoreOp = StoreOp.STORE, + clearFlags: ClearFlagBit = ClearFlagBit.ALL, + clearColor: Color = new Color(), + shaderStageFlags: ShaderStageFlagBit = ShaderStageFlagBit.NONE, + ) { + this.slotName = slotName; + this.accessType = accessType; + this.attachmentType = attachmentType; + this.loadOp = loadOp; + this.storeOp = storeOp; + this.clearFlags = clearFlags; + this.clearColor = clearColor; + this.shaderStageFlags = shaderStageFlags; + } + slotName: string; + slotName1 = ''; + accessType: AccessType; + attachmentType: AttachmentType; + loadOp: LoadOp; + storeOp: StoreOp; + clearFlags: ClearFlagBit; + readonly clearColor: Color; + slotID = 0; + shaderStageFlags: ShaderStageFlagBit; +} + +export class ComputeView { + constructor ( + name = '', + accessType: AccessType = AccessType.READ, + clearFlags: ClearFlagBit = ClearFlagBit.NONE, + clearValueType: ClearValueType = ClearValueType.NONE, + clearValue: ClearValue = new ClearValue(), + shaderStageFlags: ShaderStageFlagBit = ShaderStageFlagBit.NONE, + ) { + this.name = name; + this.accessType = accessType; + this.clearFlags = clearFlags; + this.clearValueType = clearValueType; + this.clearValue = clearValue; + this.shaderStageFlags = shaderStageFlags; + } + name: string; + accessType: AccessType; + plane = 0; + clearFlags: ClearFlagBit; + clearValueType: ClearValueType; + readonly clearValue: ClearValue; + shaderStageFlags: ShaderStageFlagBit; +} + export class ResourceDesc { dimension: ResourceDimension = ResourceDimension.BUFFER; alignment = 0; diff --git a/cocos/rendering/custom/types.ts b/cocos/rendering/custom/types.ts index 9c0dfa3130..04e93aca20 100644 --- a/cocos/rendering/custom/types.ts +++ b/cocos/rendering/custom/types.ts @@ -28,10 +28,10 @@ * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= */ /* eslint-disable max-len */ -import { ClearFlagBit, Color, LoadOp, ResolveMode, ShaderStageFlagBit, StoreOp, Type, UniformBlock } from '../../gfx'; +import { ResolveMode, ShaderStageFlagBit, Type, UniformBlock } from '../../gfx'; import { Light } from '../../render-scene/scene'; import { OutputArchive, InputArchive } from './archive'; -import { saveColor, loadColor, saveUniformBlock, loadUniformBlock } from './serialization'; +import { saveUniformBlock, loadUniformBlock } from './serialization'; export enum UpdateFrequency { PER_INSTANCE, @@ -262,38 +262,6 @@ export function getAccessTypeName (e: AccessType): string { } } -export class RasterView { - constructor ( - slotName = '', - accessType: AccessType = AccessType.WRITE, - attachmentType: AttachmentType = AttachmentType.RENDER_TARGET, - loadOp: LoadOp = LoadOp.LOAD, - storeOp: StoreOp = StoreOp.STORE, - clearFlags: ClearFlagBit = ClearFlagBit.ALL, - clearColor: Color = new Color(), - shaderStageFlags: ShaderStageFlagBit = ShaderStageFlagBit.NONE, - ) { - this.slotName = slotName; - this.accessType = accessType; - this.attachmentType = attachmentType; - this.loadOp = loadOp; - this.storeOp = storeOp; - this.clearFlags = clearFlags; - this.clearColor = clearColor; - this.shaderStageFlags = shaderStageFlags; - } - slotName: string; - slotName1 = ''; - accessType: AccessType; - attachmentType: AttachmentType; - loadOp: LoadOp; - storeOp: StoreOp; - clearFlags: ClearFlagBit; - readonly clearColor: Color; - slotID = 0; - shaderStageFlags: ShaderStageFlagBit; -} - export enum ClearValueType { NONE, FLOAT_TYPE, @@ -313,44 +281,6 @@ export function getClearValueTypeName (e: ClearValueType): string { } } -export class ClearValue { - constructor (x = 0, y = 0, z = 0, w = 0) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - x: number; - y: number; - z: number; - w: number; -} - -export class ComputeView { - constructor ( - name = '', - accessType: AccessType = AccessType.READ, - clearFlags: ClearFlagBit = ClearFlagBit.NONE, - clearValueType: ClearValueType = ClearValueType.NONE, - clearValue: ClearValue = new ClearValue(), - shaderStageFlags: ShaderStageFlagBit = ShaderStageFlagBit.NONE, - ) { - this.name = name; - this.accessType = accessType; - this.clearFlags = clearFlags; - this.clearValueType = clearValueType; - this.clearValue = clearValue; - this.shaderStageFlags = shaderStageFlags; - } - name: string; - accessType: AccessType; - plane = 0; - clearFlags: ClearFlagBit; - clearValueType: ClearValueType; - readonly clearValue: ClearValue; - shaderStageFlags: ShaderStageFlagBit; -} - export class LightInfo { constructor (light: Light | null = null, level = 0) { this.light = light; @@ -566,67 +496,7 @@ export class PipelineStatistics { numInstancingUniformBlocks = 0; } -export function saveRasterView (ar: OutputArchive, v: RasterView): void { - ar.writeString(v.slotName); - ar.writeString(v.slotName1); - ar.writeNumber(v.accessType); - ar.writeNumber(v.attachmentType); - ar.writeNumber(v.loadOp); - ar.writeNumber(v.storeOp); - ar.writeNumber(v.clearFlags); - saveColor(ar, v.clearColor); - ar.writeNumber(v.slotID); - ar.writeNumber(v.shaderStageFlags); -} - -export function loadRasterView (ar: InputArchive, v: RasterView): void { - v.slotName = ar.readString(); - v.slotName1 = ar.readString(); - v.accessType = ar.readNumber(); - v.attachmentType = ar.readNumber(); - v.loadOp = ar.readNumber(); - v.storeOp = ar.readNumber(); - v.clearFlags = ar.readNumber(); - loadColor(ar, v.clearColor); - v.slotID = ar.readNumber(); - v.shaderStageFlags = ar.readNumber(); -} - -export function saveClearValue (ar: OutputArchive, v: ClearValue): void { - ar.writeNumber(v.x); - ar.writeNumber(v.y); - ar.writeNumber(v.z); - ar.writeNumber(v.w); -} - -export function loadClearValue (ar: InputArchive, v: ClearValue): void { - v.x = ar.readNumber(); - v.y = ar.readNumber(); - v.z = ar.readNumber(); - v.w = ar.readNumber(); -} - -export function saveComputeView (ar: OutputArchive, v: ComputeView): void { - ar.writeString(v.name); - ar.writeNumber(v.accessType); - ar.writeNumber(v.plane); - ar.writeNumber(v.clearFlags); - ar.writeNumber(v.clearValueType); - saveClearValue(ar, v.clearValue); - ar.writeNumber(v.shaderStageFlags); -} - -export function loadComputeView (ar: InputArchive, v: ComputeView): void { - v.name = ar.readString(); - v.accessType = ar.readNumber(); - v.plane = ar.readNumber(); - v.clearFlags = ar.readNumber(); - v.clearValueType = ar.readNumber(); - loadClearValue(ar, v.clearValue); - v.shaderStageFlags = ar.readNumber(); -} - -export function saveLightInfo (ar: OutputArchive, v: LightInfo): void { +export function saveLightInfo (ar: OutputArchive, v: LightInfo) { // skip, v.light: Light ar.writeNumber(v.level); } diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index 0035a35706..e2b8611dab 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -27,8 +27,8 @@ import { systemInfo } from 'pal/system-info'; import { DEBUG } from 'internal:constants'; import { Color, Buffer, DescriptorSetLayout, Device, Feature, Format, FormatFeatureBit, Sampler, Swapchain, Texture, ClearFlagBit, DescriptorSet, deviceManager, Viewport, API, CommandBuffer, Type, SamplerInfo, Filter, Address, DescriptorSetInfo, LoadOp, StoreOp, ShaderStageFlagBit, BufferInfo, TextureInfo, UniformBlock } from '../../gfx'; import { Mat4, Quat, toRadian, Vec2, Vec3, Vec4, assert, macro, cclegacy } from '../../core'; -import { AccessType, AttachmentType, ComputeView, CopyPair, LightInfo, LightingMode, MovePair, QueueHint, RasterView, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UpdateFrequency } from './types'; -import { Blit, ClearView, ComputePass, CopyPass, Dispatch, ManagedBuffer, ManagedResource, MovePass, RasterPass, RasterSubpass, RenderData, RenderGraph, RenderGraphComponent, RenderGraphValue, RenderQueue, RenderSwapchain, ResourceDesc, ResourceGraph, ResourceGraphValue, ResourceStates, ResourceTraits, SceneData, Subpass } from './render-graph'; +import { AccessType, AttachmentType, CopyPair, LightInfo, LightingMode, MovePair, QueueHint, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UpdateFrequency } from './types'; +import { ComputeView, RasterView, Blit, ClearView, ComputePass, CopyPass, Dispatch, ManagedBuffer, ManagedResource, MovePass, RasterPass, RasterSubpass, RenderData, RenderGraph, RenderGraphComponent, RenderGraphValue, RenderQueue, RenderSwapchain, ResourceDesc, ResourceGraph, ResourceGraphValue, ResourceStates, ResourceTraits, SceneData, Subpass } from './render-graph'; import { ComputePassBuilder, ComputeQueueBuilder, ComputeSubpassBuilder, BasicPipeline, PipelineBuilder, RenderPassBuilder, RenderQueueBuilder, RenderSubpassBuilder, PipelineType, BasicRenderPassBuilder, PipelineCapabilities } from './pipeline'; import { PipelineSceneData } from '../pipeline-scene-data'; import { Model, Camera, ShadowType, CSMLevel, DirectionalLight, SpotLight, PCFType, Shadows } from '../../render-scene/scene'; @@ -932,12 +932,6 @@ export class WebRenderSubpassBuilder extends WebSetter implements RenderSubpassB addStorageImage (name: string, accessType: AccessType, slotName: string): void { throw new Error('Method not implemented.'); } - addRasterView (name: string, view: RasterView): void { - throw new Error('Method not implemented.'); - } - addComputeView (name: string, view: ComputeView): void { - throw new Error('Method not implemented.'); - } setViewport (viewport: Viewport): void { throw new Error('Method not implemented.'); } @@ -986,23 +980,6 @@ export class WebRenderPassBuilder extends WebSetter implements BasicRenderPassBu setCustomShaderStages (name: string, stageFlags: ShaderStageFlagBit): void { throw new Error('Method not implemented.'); } - addRasterView (name: string, view: RasterView): void { - this._pass.rasterViews.set(name, view); - } - addComputeView (name: string, view: ComputeView): void { - if (DEBUG) { - assert(Boolean(view.name)); - assert(Boolean(name && this._resourceGraph.contains(name))); - const descriptorName = view.name; - const descriptorID = this._layoutGraph.attributeIndex.get(descriptorName); - assert(descriptorID !== undefined); - } - if (this._pass.computeViews.has(name)) { - this._pass.computeViews.get(name)?.push(view); - } else { - this._pass.computeViews.set(name, [view]); - } - } setArrayBuffer (name: string, arrayBuffer: ArrayBuffer): void { throw new Error('Method not implemented.'); } @@ -1216,17 +1193,7 @@ export class WebComputePassBuilder extends WebSetter implements ComputePassBuild addMaterialTexture (resourceName: string, flags?: ShaderStageFlagBit | undefined): void { throw new Error('Method not implemented.'); } - addComputeView (name: string, view: ComputeView): void { - if (DEBUG) { - assert(Boolean(name && this._resourceGraph.contains(name))); - } - if (this._pass.computeViews.has(name)) { - this._pass.computeViews.get(name)?.push(view); - } else { - this._pass.computeViews.set(name, [view]); - } - } - addQueue (layoutName = 'default'): WebComputeQueueBuilder { + addQueue (layoutName = 'default') { if (DEBUG) { const layoutId = this._layoutGraph.locateChild(this._layoutID, layoutName); assert(layoutId !== 0xFFFFFFFF); diff --git a/cocos/rendering/deferred/deferred-pipeline-scene-data.ts b/cocos/rendering/deferred/deferred-pipeline-scene-data.ts index 18b655e545..690d89dd06 100644 --- a/cocos/rendering/deferred/deferred-pipeline-scene-data.ts +++ b/cocos/rendering/deferred/deferred-pipeline-scene-data.ts @@ -141,9 +141,6 @@ export class DeferredPipelineSceneData extends PipelineSceneData { const postMat = new Material(); postMat._uuid = 'builtin-post-process-material'; - if (macro.ENABLE_ANTIALIAS_FXAA) { - this._antiAliasing = AntiAliasing.FXAA; - } postMat.initialize({ effectName: 'pipeline/post-process', defines: { diff --git a/cocos/rendering/post-process/passes/forward-pass.ts b/cocos/rendering/post-process/passes/forward-pass.ts index 24c99bf8c9..da9fc13331 100644 --- a/cocos/rendering/post-process/passes/forward-pass.ts +++ b/cocos/rendering/post-process/passes/forward-pass.ts @@ -71,7 +71,6 @@ export class ForwardPass extends BasePass { } } } - pass.addQueue(QueueHint.RENDER_OPAQUE) .addSceneOfCamera(camera, new LightInfo(), diff --git a/cocos/rendering/post-process/utils/pass-context.ts b/cocos/rendering/post-process/utils/pass-context.ts index ded3193728..a3677222b7 100644 --- a/cocos/rendering/post-process/utils/pass-context.ts +++ b/cocos/rendering/post-process/utils/pass-context.ts @@ -1,6 +1,6 @@ import { EDITOR } from 'internal:constants'; -import { AccessType, AttachmentType, ComputeView, QueueHint, RasterView, ResourceResidency, SceneFlags } from '../../custom/types'; +import { QueueHint, ResourceResidency, SceneFlags } from '../../custom/types'; import { ClearFlagBit, Color, Format, LoadOp, Rect, StoreOp, Viewport } from '../../../gfx'; import { Pipeline, RenderPassBuilder } from '../../custom/pipeline'; import { Camera } from '../../../render-scene/scene'; @@ -164,9 +164,7 @@ export class PassContext { } setPassInput (inputName: string, shaderName: string): PassContext { if (this.ppl!.containsResource(inputName)) { - const computeView = new ComputeView(); - computeView.name = shaderName; - this.pass!.addComputeView(inputName, computeView); + this.pass!.addTexture(inputName, shaderName); } return this; } diff --git a/cocos/scene-graph/node-event-processor.ts b/cocos/scene-graph/node-event-processor.ts index d01ba5fab2..d86e13a804 100644 --- a/cocos/scene-graph/node-event-processor.ts +++ b/cocos/scene-graph/node-event-processor.ts @@ -648,7 +648,6 @@ export class NodeEventProcessor { } event.getLocation(pos); - //console.log('pos: ' + pos); if (node._uiProps.uiTransformComp.hitTest(pos, event.windowId)) { event.type = NodeEventType.TOUCH_END; diff --git a/cocos/spine/lib/instantiated.ts b/cocos/spine/lib/instantiated.ts index 71e4d64836..c1f0daeb14 100644 --- a/cocos/spine/lib/instantiated.ts +++ b/cocos/spine/lib/instantiated.ts @@ -44,7 +44,6 @@ const wasmInstance: SpineWasm.instance = {} as any; const registerList: any[] = []; /////////////////////////////////////////////////////////////////////////////////////////////////// function initWasm (wasmUrl): Promise { - console.log('[Spine]: Using wasm libs.'); // eslint-disable-next-line @typescript-eslint/no-unsafe-return return wasmFactory({ instantiateWasm (importObject: WebAssembly.Imports, @@ -62,7 +61,6 @@ function initWasm (wasmUrl): Promise { } function initAsm (resolve): Promise { - console.log('[Spine]: Using asmjs libs.'); const wasmMemory: any = {}; wasmMemory.buffer = new ArrayBuffer(MEMORYSIZE); const module = { @@ -77,7 +75,6 @@ function initAsm (resolve): Promise { } export function waitForSpineWasmInstantiation (): Promise { - console.log('[spine] waitForSpineWasmInstantiation'); return new Promise((resolve) => { const errorReport = (msg: any): void => { console.error(msg); }; if (WASM_SUPPORT_MODE === WebAssemblySupportMode.MAYBE_SUPPORT) { diff --git a/editor/assets/chunks/common/common-define.chunk b/editor/assets/chunks/common/common-define.chunk index db65a1fed8..27fc46daad 100644 --- a/editor/assets/chunks/common/common-define.chunk +++ b/editor/assets/chunks/common/common-define.chunk @@ -8,13 +8,13 @@ #define PI 3.14159265359 #define PI2 6.28318530718 #define PI4 12.5663706144 - + #define INV_QUATER_PI 1.27323954474 #define INV_HALF_PI 0.63661977237 #define INV_PI 0.31830988618 #define INV_PI2 0.15915494309 #define INV_PI4 0.07957747155 - + #define EPSILON 1e-6 #define EPSILON_LOWP 1e-4 #define LOG2 1.442695 @@ -31,6 +31,12 @@ #pragma define clip(value) if(value < 0.0) discard; #pragma define lerp(value1, value2, value2Multiplier) mix(value1, value2, value2Multiplier) +float saturate(float value) { return clamp(value, 0.0, 1.0); } +vec2 saturate(vec2 value) { return clamp(value, vec2(0.0), vec2(1.0)); } +vec3 saturate(vec3 value) { return clamp(value, vec3(0.0), vec3(1.0)); } +vec4 saturate(vec4 value) { return clamp(value, vec4(0.0), vec4(1.0)); } + + // runtime constants #pragma define-meta CC_DEVICE_SUPPORT_FLOAT_TEXTURE default(1) #pragma define-meta CC_DEVICE_MAX_FRAGMENT_UNIFORM_VECTORS default(1024) @@ -40,7 +46,6 @@ #pragma define-meta CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT default(0) #pragma define-meta CC_PLATFORM_ANDROID_AND_WEBGL default(0) #pragma define-meta CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES default(0) -#pragma define-meta CC_ENABLE_CLUSTERED_LIGHT_CULLING default(0) // When sampling RTs, Y-flip is needed if the screen space sign Y is positive (pointing upwards) #pragma define CC_HANDLE_RT_SAMPLE_FLIP(uv) uv = cc_cameraPos.w > 1.0 ? vec2(uv.x, 1.0 - uv.y) : uv diff --git a/editor/assets/chunks/common/math/coordinates.chunk b/editor/assets/chunks/common/math/coordinates.chunk index e78714070c..08c05a227c 100644 --- a/editor/assets/chunks/common/math/coordinates.chunk +++ b/editor/assets/chunks/common/math/coordinates.chunk @@ -2,6 +2,12 @@ // cc_cameraPos.w is flipNDCSign #pragma define CC_HANDLE_NDC_SAMPLE_FLIP(uv, flipNDCSign) uv = flipNDCSign == 1.0 ? vec2(uv.x, 1.0 - uv.y) : uv +#ifdef CC_USE_METAL +#define CC_HANDLE_SAMPLE_NDC_FLIP_STATIC(y) y = -y +#else +#define CC_HANDLE_SAMPLE_NDC_FLIP_STATIC(y) +#endif + // return 0-1 vec2 GetScreenUV(vec4 clipPos, float flipNDCSign) diff --git a/editor/assets/chunks/common/math/number.chunk b/editor/assets/chunks/common/math/number.chunk index 5dd6f2ba7b..cec08efffa 100644 --- a/editor/assets/chunks/common/math/number.chunk +++ b/editor/assets/chunks/common/math/number.chunk @@ -39,19 +39,10 @@ bool isinfs(vec4 val) { vec4 round(vec4 value) { return vec4(round(value.x), round(value.y), round(value.z), round(value.w)); } #endif -float rsqrt(float value) { - return 1.0 / sqrt(value); -} -vec2 rsqrt(vec2 value) { return vec2(rsqrt(value.x), rsqrt(value.y)); } -vec3 rsqrt(vec3 value) { return vec3(rsqrt(value.x), rsqrt(value.y), rsqrt(value.z)); } -vec4 rsqrt(vec4 value) { return vec4(rsqrt(value.x), rsqrt(value.y), rsqrt(value.z), rsqrt(value.w)); } - -float saturate(float value) { - return min(max(value, 0.0), 1.0); -} -vec2 saturate(vec2 value) { return vec2(saturate(value.x), saturate(value.y)); } -vec3 saturate(vec3 value) { return vec3(saturate(value.x), saturate(value.y), saturate(value.z)); } -vec4 saturate(vec4 value) { return vec4(saturate(value.x), saturate(value.y), saturate(value.z), saturate(value.w)); } +float rsqrt(float value) { return 1.0 / sqrt(value); } +vec2 rsqrt(vec2 value) { return vec2(1.0) / sqrt(value); } +vec3 rsqrt(vec3 value) { return vec3(1.0) / sqrt(value); } +vec4 rsqrt(vec4 value) { return vec4(1.0) / sqrt(value); } // random number diff --git a/editor/assets/chunks/legacy/shading-cluster-additive.chunk b/editor/assets/chunks/legacy/shading-cluster-additive.chunk index 3dc7965ca6..0bf35248e7 100644 --- a/editor/assets/chunks/legacy/shading-cluster-additive.chunk +++ b/editor/assets/chunks/legacy/shading-cluster-additive.chunk @@ -1,17 +1,20 @@ // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. -#pragma define CLUSTERS_X 16 -#pragma define CLUSTERS_Y 8 -#pragma define CLUSTERS_Z 24 +#pragma define CLUSTERS_X 16u +#pragma define CLUSTERS_Y 8u +#pragma define CLUSTERS_Z 24u #pragma define MAX_LIGHTS_PER_CLUSTER 100u -#pragma glBinding(4) -readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; }; +#pragma rate b_ccLightsBuffer pass +#pragma glBinding(0) +layout(std430) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; }; -#pragma glBinding(5) -readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; }; +#pragma rate b_clusterLightIndicesBuffer pass +#pragma glBinding(1) +layout(std430) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; }; -#pragma glBinding(6) -readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; }; +#pragma rate b_clusterLightGridBuffer pass +#pragma glBinding(2) +layout(std430) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; }; struct CCLight { @@ -19,6 +22,7 @@ struct CCLight vec4 cc_lightColor; vec4 cc_lightSizeRangeAngle; vec4 cc_lightDir; + vec4 cc_lightBoundingSizeVS; }; struct Cluster @@ -43,10 +47,11 @@ float screen2EyeDepth(float depth, float near, float far) CCLight getCCLight(uint i) { CCLight light; - light.cc_lightPos = b_ccLights[4u * i + 0u]; - light.cc_lightColor = b_ccLights[4u * i + 1u]; - light.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u]; - light.cc_lightDir = b_ccLights[4u * i + 3u]; + light.cc_lightPos = b_ccLights[5u * i + 0u]; + light.cc_lightColor = b_ccLights[5u * i + 1u]; + light.cc_lightSizeRangeAngle = b_ccLights[5u * i + 2u]; + light.cc_lightDir = b_ccLights[5u * i + 3u]; + light.cc_lightBoundingSizeVS = b_ccLights[5u * i + 4u]; return light; } @@ -79,7 +84,7 @@ uint getClusterIndex(vec4 fragCoord, vec4 worldPos) float clusterSizeX = ceil(cc_viewPort.z / float(CLUSTERS_X)); float clusterSizeY = ceil(cc_viewPort.w / float(CLUSTERS_Y)); uvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex); - uint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x; + uint cluster = (CLUSTERS_X * CLUSTERS_Y) * indices.z + CLUSTERS_X * indices.y + indices.x; return cluster; } @@ -133,7 +138,7 @@ vec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) { float shadow = 1.0; #if CC_RECEIVE_SHADOW && CC_SHADOW_TYPE == CC_SHADOW_MAP - if (IS_SPOT_LIGHT(light.cc_lightPos.w) && cc_lightSizeRangeAngle.w > 0.0) { + if (IS_SPOT_LIGHT(light.cc_lightPos.w) && light.cc_lightSizeRangeAngle.w > 0.0) { shadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias); } #endif diff --git a/editor/assets/chunks/legacy/standard-surface-entry.chunk b/editor/assets/chunks/legacy/standard-surface-entry.chunk index a15b52fb85..5266ffb212 100644 --- a/editor/assets/chunks/legacy/standard-surface-entry.chunk +++ b/editor/assets/chunks/legacy/standard-surface-entry.chunk @@ -45,15 +45,15 @@ #elif CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED \ #include \ \ - layout(location = 0) out vec4 fragColor0; \ - layout(location = 1) out vec4 fragColor1; \ - layout(location = 2) out vec4 fragColor2; \ + layout(location = 0) out vec4 albedoOut; \ + layout(location = 1) out vec4 emissiveOut; \ + layout(location = 2) out vec4 normalOut; \ \ void main () { \ StandardSurface s; surf(s); \ - fragColor0 = s.albedo; \ - fragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic); \ - fragColor2 = vec4(s.emissive, s.occlusion); \ + albedoOut = s.albedo; \ + normalOut = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic); \ + emissiveOut = vec4(s.emissive, s.occlusion); \ } \ \ #endif \ diff --git a/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk b/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk index 34828b0848..a9a6316003 100644 --- a/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk +++ b/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk @@ -1,5 +1,5 @@ #if (CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD || CC_FORCE_FORWARD_SHADING) - #if CC_FORWARD_ADD && !CC_ENABLE_CLUSTERED_LIGHT_CULLING + #if CC_FORWARD_ADD void CCSurfacesLighting(inout LightingResult lightingResultAccumulated, in SurfacesMaterialData surfaceData, in vec2 shadowBias) { vec3 worldPos; @@ -30,7 +30,7 @@ vec3 lightDirWithLength = IS_RANGED_DIRECTIONAL_LIGHT(cc_lightPos[i].w) ? -normalize(cc_lightDir[i].xyz) : cc_lightPos[i].xyz - worldPos; CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData, surfaceData, lightDirWithLength); CCSurfacesLightingCalculateColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, lightingResult.specularColorWithEnvLighting, surfaceData, lightingData); - + vec3 diffuseLighting, specularLighting; CCSurfacesLightingCalculateDirect(diffuseLighting, specularLighting, lightingData, cc_lightColor[i]); @@ -57,7 +57,7 @@ #endif } #endif - + #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_SHADOW) shadow = 1.0; @@ -134,11 +134,11 @@ { vec3 worldPos; HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos); - + LightingIntermediateData lightingData; CCSurfacesInitializeLightingIntermediateData(lightingData, surfaceData); CCSurfacesInitializeLightingResult(lightingResult, surfaceData); - + CCSurfacesLightingInitializeColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, lightingResult.specularColorWithEnvLighting, surfaceData, lightingData); CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData, surfaceData, -cc_mainLitDir.xyz); @@ -182,7 +182,7 @@ #if CC_SURFACES_USE_LIGHT_MAP && !CC_FORWARD_ADD float lightmapShadow, lightmapAO; GetLightMapColor(lightingResult.lightmapColor, lightmapShadow, lightmapAO, cc_lightingMap, FSInput_lightMapUV.xy, FSInput_lightMapUV.z, surfaceData.worldNormal); - + #if CC_SURFACES_USE_LIGHT_MAP == LIGHT_MAP_TYPE_INDIRECT_OCCLUSION lightingResult.shadow *= lightmapShadow; #endif @@ -204,7 +204,7 @@ lightingResult.directDiffuse = lightingResult.directSpecular = vec3(0.0); #if !CC_DISABLE_DIRECTIONAL_LIGHT && !CC_FORWARD_ADD CCSurfacesLightingCalculateColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, lightingResult.specularColorWithEnvLighting, surfaceData, lightingData); - + CCSurfacesLightingCalculateDirect(lightingResult.directDiffuse, lightingResult.directSpecular, lightingData, cc_mainLitColor); #endif @@ -220,7 +220,7 @@ CCSurfacesLightingCalculateDirectTransmitSpecular(lightingResult.directTransmitSpecular, lightingData, cc_mainLitColor); CCSurfacesLightingCalculateEnvironmentTransmitSpecular(lightingResult.environmentTransmitSpecular, lightingData, cc_ambientSky.w); #endif - + #if CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE LightingIntermediateData lightingDataTD; CCSurfacesGetLightingIntermediateDataTransmitDiffuse(lightingDataTD, lightingData, surfaceData); diff --git a/editor/assets/chunks/lighting-models/model-functions/toon.chunk b/editor/assets/chunks/lighting-models/model-functions/toon.chunk index 6255811131..cdea2dff79 100644 --- a/editor/assets/chunks/lighting-models/model-functions/toon.chunk +++ b/editor/assets/chunks/lighting-models/model-functions/toon.chunk @@ -20,11 +20,11 @@ float CCSurfacesLightingCalculateAngleAttenuation(in LightingIntermediateData li void CCSurfacesLightingCalculateDirect(out vec3 lightingDiffuse, out vec3 lightingSpecular, in LightingIntermediateData lightingData, in vec4 lightSourceColorAndIntensity) { vec3 irradiance = lightSourceColorAndIntensity.rgb * lightSourceColorAndIntensity.w; - + lightingDiffuse = irradiance; // no energy conservation // punctual lighting is different from dir lighting -#if CC_FORWARD_ADD || CC_ENABLE_CLUSTERED_LIGHT_CULLING +#if CC_FORWARD_ADD float NL = 0.5 * lightingData.NoL + 0.5; lightingDiffuse *= NL; #endif diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk index 1bc8766e39..4ce3131d2e 100644 --- a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk @@ -1,15 +1,16 @@ - layout(location = 0) out vec4 fragColor0; - layout(location = 1) out vec4 fragColor1; - layout(location = 2) out vec4 fragColor2; + layout(location = 0) out vec4 albedoOut; + layout(location = 1) out vec4 emissiveOut; + layout(location = 2) out vec4 normalOut; void main () { // Surface SurfacesMaterialData surfaceData; CCSurfacesFragmentGetMaterialData(surfaceData); - fragColor0 = CCSurfacesDeferredOutput0(surfaceData); - fragColor1 = CCSurfacesDeferredOutput1(surfaceData); - fragColor2 = CCSurfacesDeferredOutput2(surfaceData); + // location of subpass output should be ordered by name. + albedoOut = CCSurfacesDeferredOutputBaseColor(surfaceData); + normalOut = CCSurfacesDeferredOutputNormalMR(surfaceData); + emissiveOut = CCSurfacesDeferredOutputEmissiveAO(surfaceData); // Debug view #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_SINGLE && CC_SURFACES_ENABLE_DEBUG_VIEW @@ -17,7 +18,7 @@ CCSurfacesDebugViewMeshData(debugColor); CCSurfacesDebugViewSurfaceData(debugColor, surfaceData); if (IS_DEBUG_VIEW_ENABLE_WITH_CAMERA) { - fragColor0 = debugColor; + albedoOut = debugColor; } #endif } diff --git a/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk b/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk index df4a67ce35..ce3c9a81b5 100644 --- a/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk +++ b/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk @@ -236,15 +236,15 @@ void CCSurfacesAccumulateLightingResult(inout LightingResult lightingResultAccum #if CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED - vec4 CCSurfacesDeferredOutput0(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputBaseColor(in SurfacesMaterialData surfaceData) { return surfaceData.baseColor; } - vec4 CCSurfacesDeferredOutput1(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputNormalMR(in SurfacesMaterialData surfaceData) { return vec4(float32x3_to_oct(surfaceData.worldNormal), surfaceData.roughness, surfaceData.metallic); } - vec4 CCSurfacesDeferredOutput2(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputEmissiveAO(in SurfacesMaterialData surfaceData) { return vec4(surfaceData.emissive, surfaceData.ao); } diff --git a/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk b/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk index d530b9022c..5afc2f508e 100644 --- a/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk +++ b/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk @@ -105,15 +105,15 @@ void CCSurfacesAccumulateLightingResult(inout LightingResult lightingResultAccum // Lighting #if CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED - vec4 CCSurfacesDeferredOutput0(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputBaseColor(in SurfacesMaterialData surfaceData) { return surfaceData.baseColor; } - vec4 CCSurfacesDeferredOutput1(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputNormalMR(in SurfacesMaterialData surfaceData) { return vec4(float32x3_to_oct(surfaceData.worldNormal), 0.5, 0.0); } - vec4 CCSurfacesDeferredOutput2(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputEmissiveAO(in SurfacesMaterialData surfaceData) { return vec4(surfaceData.emissive, 1.0); } diff --git a/editor/assets/chunks/surfaces/module-functions/unlit-fs.chunk b/editor/assets/chunks/surfaces/module-functions/unlit-fs.chunk index 720a14100c..edc14d1b03 100644 --- a/editor/assets/chunks/surfaces/module-functions/unlit-fs.chunk +++ b/editor/assets/chunks/surfaces/module-functions/unlit-fs.chunk @@ -39,15 +39,15 @@ void CCSurfacesLightingCalculateColorWithLighting(inout vec3 diffuseColorWithLig #if CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED - vec4 CCSurfacesDeferredOutput0(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputBaseColor(in SurfacesMaterialData surfaceData) { return surfaceData.baseColor; } - vec4 CCSurfacesDeferredOutput1(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputNormalMR(in SurfacesMaterialData surfaceData) { return vec4(float32x3_to_oct(vec3(0.0, 1.0, 0.0)), 0.0, 0.0); } - vec4 CCSurfacesDeferredOutput2(in SurfacesMaterialData surfaceData) + vec4 CCSurfacesDeferredOutputEmissiveAO(in SurfacesMaterialData surfaceData) { return vec4(0.0, 0.0, 0.0, 1.0); } diff --git a/editor/assets/effects/advanced/eye.effect b/editor/assets/effects/advanced/eye.effect index 55a7206fc1..d2ff3f7dca 100644 --- a/editor/assets/effects/advanced/eye.effect +++ b/editor/assets/effects/advanced/eye.effect @@ -65,15 +65,20 @@ CCEffect %{ frag: reflect-map-fs phase: reflect-map propertyIndex: 0 + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -82,6 +87,14 @@ CCEffect %{ properties: *props - *forward-add - *shadow-caster + - &deferred-forward-transparent + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -131,7 +144,7 @@ CCProgram surface-fragment %{ in vec4 v_planeT; #if USE_IRIS_REFRACTION uniform sampler2D irisNormalMap; - #endif + #endif uniform sampler2D irisHeightMap; uniform sampler2D irisHeightMapAlpha; uniform sampler2D irisColorMaskMap; @@ -178,7 +191,7 @@ CCProgram surface-fragment %{ return vec2(dot(refract, planeT), dot(refract, -planeB)); } - + // definition of SurfacesMaterialData structure with corresponding shading-model #include @@ -189,7 +202,7 @@ CCProgram surface-fragment %{ vec3 worldPos; HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos); - float irisHeightScale = irisParams.x; + float irisHeightScale = irisParams.x; float IrisUVRadius = irisParams.z * 2.0; // default is 0.5 float PupilScale = irisParams.w; float VeinsPower = irisParams.y; @@ -252,7 +265,7 @@ CCProgram surface-fragment %{ #if USE_IRIS_REFRACTION vec3 worldPos; HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos); - + vec3 L = lightingData.L; vec3 viewDir = normalize(cc_cameraPos.xyz - worldPos); @@ -261,7 +274,7 @@ CCProgram surface-fragment %{ CCSurfacesLightingGetIntermediateData_PerLight(lightingDataRefract, newL); if (surfaceData.emissive.x > 0.0) { result.directSpecular = CalculateDirectSpecular(lightingDataRefract, miscData.lightColorAndIntensity); - + #if !CC_FORWARD_ADD lightingDataRefract.V = -CalculateRefractDirection(surfaceData.worldNormal, viewDir, dot(surfaceData.worldNormal, viewDir), CONREAL_IOR); result.environmentSpecular = CalculateEnvironmentSpecular(lightingDataRefract, cc_ambientSky.w); diff --git a/editor/assets/effects/advanced/hair.effect b/editor/assets/effects/advanced/hair.effect index e7eb72881c..40688eb6f4 100644 --- a/editor/assets/effects/advanced/hair.effect +++ b/editor/assets/effects/advanced/hair.effect @@ -46,7 +46,7 @@ CCEffect %{ - switch: USE_TRANSPARENCY_PASS_BACK vert: standard-vs frag: standard-fs - properties: *props + propertyIndex: 0 rasterizerState: cullMode: Front depthStencilState: @@ -64,7 +64,7 @@ CCEffect %{ - switch: USE_TRANSPARENCY_PASS_FRONT vert: standard-vs frag: standard-fs - properties: *props + propertyIndex: 0 rasterizerState: cullMode: Back depthStencilState: @@ -100,7 +100,7 @@ CCEffect %{ - switch: USE_TRANSPARENCY_PASS_BACK vert: standard-vs frag: standard-fs - properties: *props + propertyIndex: 0 rasterizerState: cullMode: Front depthStencilState: @@ -118,7 +118,7 @@ CCEffect %{ - switch: USE_TRANSPARENCY_PASS_FRONT vert: standard-vs frag: standard-fs - properties: *props + propertyIndex: 0 rasterizerState: cullMode: Back depthStencilState: diff --git a/editor/assets/effects/advanced/leaf.effect b/editor/assets/effects/advanced/leaf.effect index f7b8c6ae2b..184d747644 100644 --- a/editor/assets/effects/advanced/leaf.effect +++ b/editor/assets/effects/advanced/leaf.effect @@ -24,9 +24,9 @@ CCEffect %{ extinction: { value: 0.0, target: scatterParams.y, editor: { displayName: Scatter Extinction, slide: true, range: [0, 3.0], step: 0.001 } } thickness: { value: 1.0, target: scatterParams.z, editor: { displayName: Thickness Scaling, slide: true, range: [0, 3.0], step: 0.001 } } scatterColor: { value: [0.5, 0.75, 0.2, 1.0], linear: true, editor: { displayName: Scatter Color, type: color, tooltip: 'The color of scattered lighting' } } - rasterizerState: + rasterizerState: &r1 cullMode: None - depthStencilState: + depthStencilState: &d1 depthFunc: less_equal depthTest: true depthWrite: true @@ -62,15 +62,23 @@ CCEffect %{ albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } + + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 + rasterizerState: *r1 + depthStencilState: *d1 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &dt depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -79,6 +87,14 @@ CCEffect %{ properties: *props - *forward-add - *shadow-caster + - &deferred-forward-transparent + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *dt + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -104,7 +120,7 @@ CCProgram macro-remapping %{ #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR - + #define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE 1 #define CC_SURFACES_TRANSFER_CLIP_POS 1 @@ -180,7 +196,7 @@ CCProgram surface-fragment %{ { return vec3(0.0); } - + #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR vec3 SurfacesFragmentModifyTransmitOutScatteringColor() { diff --git a/editor/assets/effects/advanced/simple-skin.effect b/editor/assets/effects/advanced/simple-skin.effect index df8ffa22bf..f630258f89 100644 --- a/editor/assets/effects/advanced/simple-skin.effect +++ b/editor/assets/effects/advanced/simple-skin.effect @@ -31,9 +31,9 @@ CCEffect %{ transmitColor: { value: [1.0, 0.2, 0.1, 1.0], linear: true, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Color, type: color, tooltip: 'The color of scattered lighting, red for human skin' } } dualLobeRoughness: { value: 0.5, target: dualLobeParams.x, editor: { parent: USE_DUAL_LOBE_SPECULAR, range: [0, 1.0] } } dualLobeIntensity: { value: 0.02, target: dualLobeParams.w, editor: { parent: USE_DUAL_LOBE_SPECULAR, slide: true, range: [0, 0.1], step: 0.001 } } - rasterizerState: + rasterizerState: &r1 cullMode: None - depthStencilState: + depthStencilState: &d1 depthFunc: less_equal depthTest: true depthWrite: true @@ -69,15 +69,24 @@ CCEffect %{ albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } + + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 + rasterizerState: *r1 + depthStencilState: *d1 + - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &dt depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -86,6 +95,14 @@ CCEffect %{ properties: *props - *forward-add - *shadow-caster + - &deferred-forward-transparent + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *dt + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -113,7 +130,7 @@ CCProgram macro-remapping %{ #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR - + #define CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR USE_DUAL_LOBE_SPECULAR #define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE USE_BACK_LIT #define CC_SURFACES_LIGHTING_USE_SHADOWMAP_TRANSMIT USE_BACK_LIT @@ -184,7 +201,7 @@ CCProgram surface-fragment %{ { return vec3(0.0);//1.0, 0.2, 0.05); } - + #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR vec3 SurfacesFragmentModifyTransmitOutScatteringColor() { @@ -226,7 +243,7 @@ CCProgram surface-fragment %{ pbr.w *= cavity; return pbr; } - + #include #include }% diff --git a/editor/assets/effects/advanced/skin.effect b/editor/assets/effects/advanced/skin.effect index 706c51b272..4b049f0d2f 100644 --- a/editor/assets/effects/advanced/skin.effect +++ b/editor/assets/effects/advanced/skin.effect @@ -29,9 +29,9 @@ CCEffect %{ transmitColor: { value: [1.0, 0.2, 0.1, 1.0], linear: true, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Color, type: color, tooltip: 'The color of scattered lighting, red for human skin' } } dualLobeRoughness: { value: 0.5, target: dualLobeParams.x, editor: { parent: USE_DUAL_LOBE_SPECULAR, range: [0, 1.0] } } dualLobeIntensity: { value: 0.02, target: dualLobeParams.w, editor: { parent: USE_DUAL_LOBE_SPECULAR, slide: true, range: [0, 0.1], step: 0.001 } } - rasterizerState: + rasterizerState: &r1 cullMode: None - depthStencilState: + depthStencilState: &d1 depthFunc: less_equal depthTest: true depthWrite: true @@ -109,6 +109,14 @@ CCEffect %{ blendDst: one blendSrcAlpha: zero blendDstAlpha: one + + - vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 + embeddedMacros: { CC_SURFACES_LIGHTING_DISABLE_DIFFUSE: false, CC_SURFACES_LIGHTING_DISABLE_SPECULAR: true } + rasterizerState: *r1 + depthStencilState: *d1 }% CCProgram shared-ubos %{ @@ -135,7 +143,7 @@ CCProgram macro-remapping %{ #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR - + #define CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR USE_DUAL_LOBE_SPECULAR #define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE USE_BACK_LIT #define CC_SURFACES_LIGHTING_USE_SHADOWMAP_TRANSMIT USE_BACK_LIT @@ -206,7 +214,7 @@ CCProgram surface-fragment %{ { return vec3(0.0);//1.0, 0.2, 0.05); } - + #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR vec3 SurfacesFragmentModifyTransmitOutScatteringColor() { diff --git a/editor/assets/effects/advanced/sky.effect b/editor/assets/effects/advanced/sky.effect index 1a75ea6806..d8c9f59d29 100644 --- a/editor/assets/effects/advanced/sky.effect +++ b/editor/assets/effects/advanced/sky.effect @@ -9,11 +9,19 @@ CCEffect %{ properties: &props environmentMap: { value: grey } priority : max - 10 - rasterizerState : + rasterizerState : &r1 cullMode : none - depthStencilState : + depthStencilState : &d1 depthTest: true depthWrite : false + + - vert: sky-vs + frag: sky-fs + phase: deferred-forward + propertyIndex: 0 + priority: max - 10 + rasterizerState: *r1 + depthStencilState: *d1 }% diff --git a/editor/assets/effects/advanced/water.effect b/editor/assets/effects/advanced/water.effect index 604659e5aa..5cb52d1c38 100644 --- a/editor/assets/effects/advanced/water.effect +++ b/editor/assets/effects/advanced/water.effect @@ -21,7 +21,7 @@ CCEffect %{ detailedIntensity: { value: 0.5, target: waterParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 1.0], step: 0.001 } } waterInScatterColor: { value: [0.07, 0.13, 0.087, 1.0], target: waterColor, linear: true, editor: { parent: USE_WATER_SCATTERING, type: color } } waterScatterCoef: { value: 3.0, target: waterColor.w, editor: { parent: USE_WATER_SCATTERING, range: [0, 10.0], tooltip: 'The higher the value, the more turbid or deeper the water is.' } } - rasterizerState: + rasterizerState: &r1 cullMode: none - &forward-add vert: standard-vs @@ -57,15 +57,21 @@ CCEffect %{ frag: reflect-map-fs phase: reflect-map propertyIndex: 0 + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 + rasterizerState: *r1 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -74,6 +80,14 @@ CCEffect %{ properties: *props - *forward-add - *shadow-caster + - &deferred-forward-transparent + vert: standard-vs + frag: standard-fs + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + phase: deferred-forward + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -94,7 +108,7 @@ CCProgram macro-remapping %{ #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE #define CC_SURFACES_LIGHTING_USE_FRESNEL 1 #define CC_SURFACES_LIGHTING_TRANSMIT_SPECULAR 1 - + // depend on UI macros #if USE_NORMAL_MAP #define CC_SURFACES_USE_TANGENT_SPACE 1 @@ -121,7 +135,7 @@ CCProgram surface-fragment %{ vec4 SurfacesFragmentModifyBaseColorAndTransparency() { vec4 baseColor = albedo; - + #if USE_VERTEX_COLOR baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear baseColor.a *= FSInput_vertexColor.a; diff --git a/editor/assets/effects/builtin-reflection-probe-preview.effect b/editor/assets/effects/builtin-reflection-probe-preview.effect index a47e6051ac..d22c0618bb 100644 --- a/editor/assets/effects/builtin-reflection-probe-preview.effect +++ b/editor/assets/effects/builtin-reflection-probe-preview.effect @@ -9,6 +9,11 @@ CCEffect %{ migrations: &migs properties: mainColor: { formerlySerializedAs: color } + - vert: unlit-vs:vert + frag: unlit-fs:frag + phase: deferred-forward + propertyIndex: 0 + migrations: *migs - name: transparent passes: - vert: unlit-vs:vert @@ -16,7 +21,7 @@ CCEffect %{ depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -24,13 +29,20 @@ CCEffect %{ blendDstAlpha: one_minus_src_alpha properties: *props migrations: *migs + - vert: unlit-vs:vert + frag: unlit-fs:frag + phase: deferred-forward + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 + migrations: *migs - name: add passes: - vert: unlit-vs:vert frag: unlit-fs:frag rasterizerState: &r1 { cullMode: none } depthStencilState: *d1 - blendState: + blendState: &b2 targets: - blend: true blendSrc: src_alpha @@ -39,13 +51,20 @@ CCEffect %{ blendDstAlpha: one properties: *props migrations: *migs + - vert: unlit-vs:vert + frag: unlit-fs:frag + phase: deferred-forward + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 + migrations: *migs - name: alpha-blend passes: - vert: unlit-vs:vert frag: unlit-fs:frag rasterizerState: *r1 depthStencilState: *d1 - blendState: + blendState: &b3 targets: - blend: true blendSrc: src_alpha @@ -54,6 +73,13 @@ CCEffect %{ blendDstAlpha: one_minus_src_alpha properties: *props migrations: *migs + - vert: unlit-vs:vert + frag: unlit-fs:frag + phase: deferred-forward + depthStencilState: *d1 + blendState: *b3 + propertyIndex: 0 + migrations: *migs }% CCProgram unlit-vs %{ @@ -70,7 +96,7 @@ CCProgram unlit-vs %{ out mediump vec3 v_position; out mediump vec3 v_normal; - + vec4 vert () { vec4 position; CCVertInput(position); @@ -89,7 +115,7 @@ CCProgram unlit-vs %{ v_shadowBiasAndProbeId.zw = cc_localShadowBias.zw; #endif #endif - + return cc_matProj * (cc_matView * matWorld) * position; } }% diff --git a/editor/assets/effects/builtin-standard.effect b/editor/assets/effects/builtin-standard.effect index 9bca925d41..396c0e4ce8 100644 --- a/editor/assets/effects/builtin-standard.effect +++ b/editor/assets/effects/builtin-standard.effect @@ -84,15 +84,22 @@ CCEffect %{ blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha + - &deferred + vert: standard-vs + frag: standard-fs + pass: gbuffer + phase: gbuffer + embeddedMacros: { CC_PIPELINE_TYPE: 1 } + propertyIndex: 0 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -102,6 +109,14 @@ CCEffect %{ - *forward-add - *shadow-caster - *planar-shadow + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + propertyIndex: 0 + depthStencilState: *d1 + blendState: *b1 }% CCProgram shared-ubos %{ @@ -153,7 +168,7 @@ CCProgram surface-vertex %{ worldPos.y += cos(cc_time.x * worldPos.z); return worldPos; } - + #define CC_SURFACES_VERTEX_MODIFY_WORLD_NORMAL vec3 SurfacesVertexModifyWorldNormal(in SurfacesStandardVertexIntermediate In) { @@ -165,14 +180,14 @@ CCProgram surface-vertex %{ #endif return normalize(worldNormal); } - + // see for more overrided functions #define CC_SURFACES_VERTEX_MODIFY_SHARED_DATA void SurfacesVertexModifySharedData(inout SurfacesStandardVertexIntermediate In) { } */ - + #define CC_SURFACES_VERTEX_MODIFY_UV void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In) { @@ -222,7 +237,7 @@ CCProgram surface-fragment %{ vec4 SurfacesFragmentModifyBaseColorAndTransparency() { vec4 baseColor = albedo; - + #if USE_VERTEX_COLOR baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear baseColor.a *= FSInput_vertexColor.a; @@ -253,7 +268,7 @@ CCProgram surface-fragment %{ #if USE_ALBEDO_MAP alpha = texture(albedoMap, ALBEDO_UV).ALPHA_TEST_CHANNEL; #endif - + if (alpha < albedoScaleAndCutoff.w) discard; #endif } diff --git a/editor/assets/effects/builtin-terrain.effect b/editor/assets/effects/builtin-terrain.effect index ac5d592ee6..f3c3faa528 100644 --- a/editor/assets/effects/builtin-terrain.effect +++ b/editor/assets/effects/builtin-terrain.effect @@ -47,6 +47,10 @@ CCEffect %{ frag: reflect-map-fs phase: reflect-map propertyIndex: 0 + - vert: terrain-vs + frag: terrain-fs + phase: deferred-forward + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -62,10 +66,10 @@ CCProgram macro-remapping %{ #define CC_SURFACES_USE_TANGENT_SPACE USE_NORMALMAP }% -CCProgram surface-vertex %{ +CCProgram surface-vertex %{ #define CC_SURFACES_VERTEX_MODIFY_WORLD_POS vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In) - { + { vec3 worldPos; worldPos.x = cc_matWorld[3][0] + In.position.x; worldPos.y = cc_matWorld[3][1] + In.position.y; diff --git a/editor/assets/effects/builtin-toon.effect b/editor/assets/effects/builtin-toon.effect index 2d60ea3cbc..6fc7ca06a6 100644 --- a/editor/assets/effects/builtin-toon.effect +++ b/editor/assets/effects/builtin-toon.effect @@ -6,9 +6,9 @@ CCEffect %{ - switch: USE_OUTLINE_PASS vert: silhouette-edge-vs frag: silhouette-edge-fs - rasterizerState: + rasterizerState: &r1 cullMode: front - depthStencilState: + depthStencilState: &d1 depthFunc: less_equal depthTest: true depthWrite: true @@ -100,6 +100,17 @@ CCEffect %{ blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha + - switch: USE_OUTLINE_PASS + vert: silhouette-edge-vs + frag: silhouette-edge-fs + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + propertyIndex: 0 + - vert: toon-vs + frag: toon-fs + phase: deferred-forward + propertyIndex: 1 }% CCProgram shared-ubos %{ @@ -203,7 +214,7 @@ CCProgram surface-fragment %{ #if USE_BASE_COLOR_MAP alpha = texture(baseColorMap, FSInput_texcoord).ALPHA_TEST_CHANNEL; #endif - + if (alpha < colorScaleAndCutoff.w) discard; #endif } @@ -241,7 +252,7 @@ CCProgram surface-fragment %{ { return miscParams.x; } - + #define CC_SURFACES_FRAGMENT_MODIFY_TOON_SPECULAR vec4 SurfacesFragmentModifyToonSpecular() { diff --git a/editor/assets/effects/builtin-unlit.effect b/editor/assets/effects/builtin-unlit.effect index 05c523d44d..66dd4e82a3 100644 --- a/editor/assets/effects/builtin-unlit.effect +++ b/editor/assets/effects/builtin-unlit.effect @@ -35,6 +35,11 @@ CCEffect %{ blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha + - &deferred-forward + vert: unlit-vs:vert + frag: unlit-fs:frag + phase: deferred-forward + propertyIndex: 0 - name: transparent passes: - vert: unlit-vs:vert @@ -42,7 +47,7 @@ CCEffect %{ depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -51,13 +56,21 @@ CCEffect %{ properties: *props migrations: *migs - *planar-shadow + - &deferred-forward-transparent + vert: unlit-vs:vert + frag: unlit-fs:frag + phase: deferred-forward + propertyIndex: 0 + migrations: *migs + depthStencilState: *d1 + blendState: *b1 - name: add passes: - vert: unlit-vs:vert frag: unlit-fs:frag rasterizerState: &r1 { cullMode: none } depthStencilState: *d1 - blendState: + blendState: &b2 targets: - blend: true blendSrc: src_alpha @@ -66,13 +79,22 @@ CCEffect %{ blendDstAlpha: one properties: *props migrations: *migs + - &deferred-forward-add + vert: unlit-vs:vert + frag: unlit-fs:frag + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 + migrations: *migs - name: alpha-blend passes: - vert: unlit-vs:vert frag: unlit-fs:frag rasterizerState: *r1 depthStencilState: *d1 - blendState: + blendState: &b3 targets: - blend: true blendSrc: src_alpha @@ -81,6 +103,15 @@ CCEffect %{ blendDstAlpha: one_minus_src_alpha properties: *props migrations: *migs + - &deferred-forward-alpha-blend + vert: unlit-vs:vert + frag: unlit-fs:frag + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b3 + propertyIndex: 0 + migrations: *migs }% CCProgram unlit-vs %{ diff --git a/editor/assets/effects/legacy/standard.effect b/editor/assets/effects/legacy/standard.effect index 95218dfb67..27a0f682fa 100644 --- a/editor/assets/effects/legacy/standard.effect +++ b/editor/assets/effects/legacy/standard.effect @@ -74,15 +74,22 @@ CCEffect %{ blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha + - &deferred + vert: standard-vs + frag: standard-fs + pass: gbuffer + phase: gbuffer + embeddedMacros: { CC_PIPELINE_TYPE: 1 } + propertyIndex: 0 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -92,6 +99,14 @@ CCEffect %{ - *forward-add - *shadow-caster - *planar-shadow + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + propertyIndex: 0 + depthStencilState: *d1 + blendState: *b1 }% CCProgram shared-ubos %{ @@ -301,7 +316,7 @@ CCProgram standard-fs %{ #endif #if CC_USE_REFLECTION_PROBE == REFLECTION_PROBE_TYPE_BLEND || CC_USE_REFLECTION_PROBE == REFLECTION_PROBE_TYPE_BLEND_AND_SKYBOX - s.reflectionProbeBlendId = v_shadowBiasAndProbeId.w; + s.reflectionProbeBlendId = v_shadowBiasAndProbeId.w; #if USE_INSTANCING s.reflectionProbeBlendFactor = v_reflectionProbeData.x; #else diff --git a/editor/assets/effects/legacy/terrain.effect b/editor/assets/effects/legacy/terrain.effect index 957d01b6fa..45b652402b 100644 --- a/editor/assets/effects/legacy/terrain.effect +++ b/editor/assets/effects/legacy/terrain.effect @@ -41,6 +41,10 @@ CCEffect %{ propertyIndex: 0 rasterizerState: cullMode: back + - vert: terrain-vs + frag: terrain-fs + phase: deferred-forward + propertyIndex: 0 }% CCProgram terrain-vs %{ @@ -309,7 +313,7 @@ CCProgram shadow-caster-fs %{ highp float clipDepth = v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5; //todo: do not support linear mode spot shadow - + #if CC_SHADOWMAP_FORMAT == SHADOWMAP_FORMAT_RGBA8 return packDepthToRGBA(clipDepth); #else diff --git a/editor/assets/effects/legacy/toon.effect b/editor/assets/effects/legacy/toon.effect index 1358a3d124..8b17d1f90b 100644 --- a/editor/assets/effects/legacy/toon.effect +++ b/editor/assets/effects/legacy/toon.effect @@ -6,9 +6,9 @@ CCEffect %{ - switch: USE_OUTLINE_PASS vert: legacy/main-functions/outline-vs:vert frag: legacy/main-functions/outline-fs:frag - rasterizerState: + rasterizerState: &r1 cullMode: front - depthStencilState: + depthStencilState: &d1 depthFunc: less_equal depthTest: true depthWrite: true @@ -100,6 +100,17 @@ CCEffect %{ blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha + - switch: USE_OUTLINE_PASS + vert: legacy/main-functions/outline-vs:vert + frag: legacy/main-functions/outline-fs:frag + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + propertyIndex: 0 + - vert: toon-vs:vert + frag: toon-fs:frag + phase: deferred-forward + propertyIndex: 1 }% CCProgram shared-ubos %{ @@ -314,7 +325,7 @@ CCProgram shadow-caster-fs %{ #include #include #include - + in vec2 v_uv; in vec4 v_worldPos; in highp vec2 v_clip_depth; diff --git a/editor/assets/effects/particles/builtin-billboard.effect b/editor/assets/effects/particles/builtin-billboard.effect index ac98142cd9..323c4bb0f3 100644 --- a/editor/assets/effects/particles/builtin-billboard.effect +++ b/editor/assets/effects/particles/builtin-billboard.effect @@ -32,6 +32,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b1 properties: *p2 + - vert: vert:vs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 - name: alpha-blend passes: - vert: vert:vs_main @@ -40,6 +47,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p2 + - vert: vert:vs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 - name: add-multiply passes: - vert: vert:vs_main @@ -48,6 +62,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p2 + - vert: vert:vs_main + frag: tinted-fs:multiply + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 - name: add-smooth passes: - vert: vert:vs_main @@ -56,6 +77,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p1 + - vert: vert:vs_main + frag: no-tint-fs:addSmooth + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 - name: premultiply-blend passes: - vert: vert:vs_main @@ -64,6 +92,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p1 + - vert: vert:vs_main + frag: no-tint-fs:premultiplied + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 }% // TODO: soft particle diff --git a/editor/assets/effects/particles/builtin-particle-gpu.effect b/editor/assets/effects/particles/builtin-particle-gpu.effect index 7aaa5a3b8c..17757a2c44 100644 --- a/editor/assets/effects/particles/builtin-particle-gpu.effect +++ b/editor/assets/effects/particles/builtin-particle-gpu.effect @@ -40,6 +40,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b1 properties: *p2 + - vert: builtin/internal/particle-vs-gpu:gpvs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 - name: alpha-blend passes: - vert: builtin/internal/particle-vs-gpu:gpvs_main @@ -48,6 +55,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p2 + - vert: builtin/internal/particle-vs-gpu:gpvs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 - name: add-multiply passes: - vert: builtin/internal/particle-vs-gpu:gpvs_main @@ -56,6 +70,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b3 properties: *p2 + - vert: builtin/internal/particle-vs-gpu:gpvs_main + frag: tinted-fs:multiply + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b3 + propertyIndex: 0 - name: add-smooth passes: - vert: builtin/internal/particle-vs-gpu:gpvs_main @@ -64,6 +85,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b1 properties: *p1 + - vert: builtin/internal/particle-vs-gpu:gpvs_main + frag: no-tint-fs:addSmooth + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 - name: premultiply-blend passes: - vert: builtin/internal/particle-vs-gpu:gpvs_main @@ -72,6 +100,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p1 + - vert: builtin/internal/particle-vs-gpu:gpvs_main + frag: no-tint-fs:premultiplied + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 }% // TODO: soft particle diff --git a/editor/assets/effects/particles/builtin-particle-trail.effect b/editor/assets/effects/particles/builtin-particle-trail.effect index 37afc3ce1a..3fdaac2fe6 100644 --- a/editor/assets/effects/particles/builtin-particle-trail.effect +++ b/editor/assets/effects/particles/builtin-particle-trail.effect @@ -33,6 +33,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b1 properties: *p2 + - vert: builtin/internal/particle-trail:vs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 - name: alpha-blend passes: - vert: builtin/internal/particle-trail:vs_main @@ -41,6 +48,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p2 + - vert: builtin/internal/particle-trail:vs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 - name: add-multiply passes: - vert: builtin/internal/particle-trail:vs_main @@ -49,6 +63,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p2 + - vert: builtin/internal/particle-trail:vs_main + frag: tinted-fs:multiply + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 - name: add-smooth passes: - vert: builtin/internal/particle-trail:vs_main @@ -57,6 +78,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p1 + - vert: builtin/internal/particle-trail:vs_main + frag: no-tint-fs:addSmooth + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 - name: premultiply-blend passes: - vert: builtin/internal/particle-trail:vs_main @@ -65,6 +93,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p1 + - vert: builtin/internal/particle-trail:vs_main + frag: no-tint-fs:premultiplied + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 }% // TODO: soft particle diff --git a/editor/assets/effects/particles/builtin-particle-xr-trail.effect b/editor/assets/effects/particles/builtin-particle-xr-trail.effect index 4472d2e21f..e4abd293ea 100644 --- a/editor/assets/effects/particles/builtin-particle-xr-trail.effect +++ b/editor/assets/effects/particles/builtin-particle-xr-trail.effect @@ -26,6 +26,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b1 properties: *p2 + - vert: builtin/internal/particle-trail:vs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% // TODO: soft particle diff --git a/editor/assets/effects/particles/builtin-particle.effect b/editor/assets/effects/particles/builtin-particle.effect index d7838b29e5..057016f189 100644 --- a/editor/assets/effects/particles/builtin-particle.effect +++ b/editor/assets/effects/particles/builtin-particle.effect @@ -40,6 +40,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b1 properties: *p2 + - vert: builtin/internal/particle-vs-legacy:lpvs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 - name: alpha-blend passes: - vert: builtin/internal/particle-vs-legacy:lpvs_main @@ -48,6 +55,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p2 + - vert: builtin/internal/particle-vs-legacy:lpvs_main + frag: tinted-fs:add + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 - name: add-multiply passes: - vert: builtin/internal/particle-vs-legacy:lpvs_main @@ -56,6 +70,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b3 properties: *p2 + - vert: builtin/internal/particle-vs-legacy:lpvs_main + frag: tinted-fs:multiply + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b3 + propertyIndex: 0 - name: add-smooth passes: - vert: builtin/internal/particle-vs-legacy:lpvs_main @@ -64,6 +85,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b1 properties: *p1 + - vert: builtin/internal/particle-vs-legacy:lpvs_main + frag: no-tint-fs:addSmooth + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 - name: premultiply-blend passes: - vert: builtin/internal/particle-vs-legacy:lpvs_main @@ -72,6 +100,13 @@ CCEffect %{ depthStencilState: *d1 blendState: *b2 properties: *p1 + - vert: builtin/internal/particle-vs-legacy:lpvs_main + frag: no-tint-fs:premultiplied + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 + blendState: *b2 + propertyIndex: 0 }% // TODO: soft particle diff --git a/editor/assets/effects/pipeline/cluster-build.effect b/editor/assets/effects/pipeline/cluster-build.effect index 505e1ccac7..fd4f229455 100644 --- a/editor/assets/effects/pipeline/cluster-build.effect +++ b/editor/assets/effects/pipeline/cluster-build.effect @@ -10,10 +10,14 @@ CCEffect %{ CCProgram cluster-main %{ - precision highp float; - #define LOCAL_SIZE_Z 1 + #include - layout (local_size_x = 16, local_size_y = 8, local_size_z = LOCAL_SIZE_Z) in; + precision highp float; + #define LOCAL_SIZE_X 16u + #define LOCAL_SIZE_Y 8u + #define LOCAL_SIZE_Z 1u + + layout (local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in; #pragma rate CCConst pass layout(std140) uniform CCConst { @@ -28,9 +32,12 @@ CCProgram cluster-main %{ vec4 screen2Eye(vec4 coord) { vec3 ndc = vec3( - 2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.x - 1.0, - 2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.y - 1.0, + 2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0, + 2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.w - 1.0, 2.0 * coord.z - 1.0); + + CC_HANDLE_SAMPLE_NDC_FLIP_STATIC(ndc.y); + vec4 eye = ((cc_matProjInv) * (vec4(ndc, 1.0))); eye = eye / eye.w; return eye; @@ -42,8 +49,8 @@ CCProgram cluster-main %{ gl_GlobalInvocationID.y * gl_WorkGroupSize.x + gl_GlobalInvocationID.x; - float clusterSizeX = ceil(cc_viewPort.x / cc_workGroup.x); - float clusterSizeY = ceil(cc_viewPort.y / cc_workGroup.y); + float clusterSizeX = ceil(cc_viewPort.z / cc_workGroup.x); + float clusterSizeY = ceil(cc_viewPort.w / cc_workGroup.y); vec4 minScreen = vec4(vec2(gl_GlobalInvocationID.xy) * vec2(clusterSizeX, clusterSizeY), 1.0, 1.0); vec4 maxScreen = vec4(vec2(gl_GlobalInvocationID.xy + uvec2(1, 1)) * vec2(clusterSizeX, clusterSizeY), 1.0, 1.0); vec3 minEye = screen2Eye(minScreen).xyz; diff --git a/editor/assets/effects/pipeline/cluster-culling.effect b/editor/assets/effects/pipeline/cluster-culling.effect index e9f4fff53e..9c418b0138 100644 --- a/editor/assets/effects/pipeline/cluster-culling.effect +++ b/editor/assets/effects/pipeline/cluster-culling.effect @@ -11,7 +11,10 @@ CCEffect %{ CCProgram cluster-main %{ precision highp float; - #define LOCAL_SIZE_Z 1 + #define LOCAL_SIZE_X 16u + #define LOCAL_SIZE_Y 8u + #define LOCAL_SIZE_Z 1u + #define LOCAL_SIZE (LOCAL_SIZE_X * LOCAL_SIZE_Y * LOCAL_SIZE_Z) #pragma rate CCConst pass layout(std140) uniform CCConst { @@ -23,18 +26,23 @@ CCProgram cluster-main %{ }; #pragma rate b_ccLightsBuffer pass + #pragma glBinding(0) layout(std430) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; }; #pragma rate b_clustersBuffer pass + #pragma glBinding(1) layout(std430) readonly buffer b_clustersBuffer { vec4 b_clusters[]; }; #pragma rate b_clusterLightIndicesBuffer pass + #pragma glBinding(2) layout(std430) buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; }; #pragma rate b_clusterLightGridBuffer pass + #pragma glBinding(3) layout(std430) buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; }; #pragma rate b_globalIndexBuffer pass + #pragma glBinding(4) layout(std430) buffer b_globalIndexBuffer { uint b_globalIndex[]; }; struct CCLight { @@ -42,6 +50,7 @@ CCProgram cluster-main %{ vec4 cc_lightColor; vec4 cc_lightSizeRangeAngle; vec4 cc_lightDir; + vec4 cc_lightBoundingSizeVS; }; uint ccLightCount() { @@ -50,10 +59,11 @@ CCProgram cluster-main %{ CCLight getCCLight(uint i) { CCLight light; - light.cc_lightPos = b_ccLights[4u * i + 0u]; - light.cc_lightColor = b_ccLights[4u * i + 1u]; - light.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u]; - light.cc_lightDir = b_ccLights[4u * i + 3u]; + light.cc_lightPos = b_ccLights[5u * i + 0u]; + light.cc_lightColor = b_ccLights[5u * i + 1u]; + light.cc_lightSizeRangeAngle = b_ccLights[5u * i + 2u]; + light.cc_lightDir = b_ccLights[5u * i + 3u]; + light.cc_lightBoundingSizeVS = b_ccLights[5u * i + 4u]; return light; } struct Cluster { @@ -94,8 +104,8 @@ CCProgram cluster-main %{ vec3 dist = closest - light.cc_lightPos.xyz; return dot(dist, dist) <= (light.cc_lightSizeRangeAngle.y * light.cc_lightSizeRangeAngle.y); } - shared CCLight lights[(16 * 8 * LOCAL_SIZE_Z)]; - layout(local_size_x = 16, local_size_y = 8, local_size_z = LOCAL_SIZE_Z) in; + shared CCLight lights[LOCAL_SIZE]; + layout(local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in; void main() { uint visibleLights[100]; @@ -108,7 +118,7 @@ CCProgram cluster-main %{ uint lightCount = ccLightCount(); uint lightOffset = 0u; while (lightOffset < lightCount) { - uint batchSize = min((16u * 8u * uint(LOCAL_SIZE_Z)), lightCount - lightOffset); + uint batchSize = min(LOCAL_SIZE, lightCount - lightOffset); if (uint(gl_LocalInvocationIndex) < batchSize) { uint lightIndex = lightOffset + gl_LocalInvocationIndex; CCLight light = getCCLight(lightIndex); diff --git a/editor/assets/effects/pipeline/deferred-lighting.effect b/editor/assets/effects/pipeline/deferred-lighting.effect index 7c8c89dff0..b5371e49dc 100644 --- a/editor/assets/effects/pipeline/deferred-lighting.effect +++ b/editor/assets/effects/pipeline/deferred-lighting.effect @@ -6,9 +6,10 @@ CCEffect %{ - vert: lighting-vs frag: lighting-fs pass: deferred-lighting + rasterizerState: + cullMode: none depthStencilState: - depthFunc: greater - depthTest: true + depthTest: false depthWrite: false }% @@ -29,7 +30,7 @@ CCProgram lighting-vs %{ } }% -CCProgram lighting-fs %{ +CCProgram lighting-fs-tiled %{ precision highp float; #include #include @@ -43,16 +44,11 @@ CCProgram lighting-fs %{ #include #include - in vec2 v_uv; - - #pragma rate gbuffer_albedoMap pass - layout(binding = 0) uniform sampler2D gbuffer_albedoMap; - #pragma rate gbuffer_normalMap pass - layout(binding = 1) uniform sampler2D gbuffer_normalMap; - #pragma rate gbuffer_emissiveMap pass - layout(binding = 2) uniform sampler2D gbuffer_emissiveMap; - #pragma rate depth_stencil pass - layout(binding = 3) uniform sampler2D depth_stencil; + #pragma subpass + #pragma subpassColor in albedoMap + #pragma subpassColor in normalMap + #pragma subpassColor in emissiveMap + #pragma subpassDepth in depthStencil layout(location = 0) out vec4 fragColor; @@ -65,27 +61,116 @@ CCProgram lighting-fs %{ #else 2.0 * coord.z - 1.0); #endif - + + + CC_HANDLE_SAMPLE_NDC_FLIP_STATIC(ndc.y); return GetWorldPosFromNDCPosRH(ndc, cc_matProj, cc_matViewProjInv); } void main () { StandardSurface s; - vec4 albedoMap = texture(gbuffer_albedoMap,v_uv); - vec4 normalMap = texture(gbuffer_normalMap,v_uv); - vec4 emissiveMap = texture(gbuffer_emissiveMap,v_uv); - float depth = texture(depth_stencil, v_uv).x; + vec4 albedo = subpassLoad(albedoMap); + vec4 normal = subpassLoad(normalMap); + vec4 emissive = subpassLoad(emissiveMap); + float depth = subpassLoad(depthStencil).x; - s.albedo = albedoMap; + s.albedo = albedo; vec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz; s.position = position; - s.roughness = normalMap.z; - s.normal = oct_to_float32x3(normalMap.xy); + s.roughness = normal.z; + s.normal = oct_to_float32x3(normal.xy); s.specularIntensity = 0.5; - s.metallic = normalMap.w; - s.emissive = emissiveMap.xyz; - s.occlusion = emissiveMap.w; + s.metallic = normal.w; + s.emissive = emissive.xyz; + s.occlusion = emissive.w; +#if CC_RECEIVE_SHADOW + s.shadowBias = vec2(0, 0); +#endif + // fixme: default value is 0, and give black result + float fogFactor; + CC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor); + + vec4 shadowPos; + CC_TRANSFER_SHADOW_BASE(vec4(position, 1), shadowPos); + + vec4 color = CCStandardShadingBase(s, shadowPos) + +#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1 + CCClusterShadingAdditive(s, shadowPos); +#else + CCStandardShadingAdditive(s, shadowPos); +#endif + CC_APPLY_FOG_BASE(color, fogFactor); + color = CCFragOutput(color); + +#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_SINGLE + color = vec4(albedoMap.rgb, 1.0); +#endif + + fragColor = color; + } +}% + +CCProgram lighting-fs %{ + precision highp float; + #include + #include + #include +#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1 + #include +#endif + #include + #include + #include + #include + #include + + in vec2 v_uv; + #pragma rate albedoMap pass + layout(binding = 0) uniform sampler2D albedoMap; + #pragma rate normalMap pass + layout(binding = 1) uniform sampler2D normalMap; + #pragma rate emissiveMap pass + layout(binding = 2) uniform sampler2D emissiveMap; + #pragma rate depthStencil pass + layout(binding = 3) uniform sampler2D depthStencil; + + layout(location = 0) out vec4 fragColor; + + vec4 screen2WS(vec3 coord) { + vec3 ndc = vec3( + 2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0, + 2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.w - 1.0, + #if __VERSION__ >= 450 + coord.z); + #else + 2.0 * coord.z - 1.0); + #endif + + CC_HANDLE_SAMPLE_NDC_FLIP_STATIC(ndc.y); + return GetWorldPosFromNDCPosRH(ndc, cc_matProj, cc_matViewProjInv); + } + + void main () { + StandardSurface s; + + vec4 albedo = texture(albedoMap, v_uv); + vec4 normal = texture(normalMap, v_uv); + vec4 emissive = texture(emissiveMap, v_uv); + float depth = texture(depthStencil, v_uv).x; + + s.albedo = albedo; + vec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz; + s.position = position; + s.roughness = normal.z; + s.normal = oct_to_float32x3(normal.xy); + s.specularIntensity = 0.5; + s.metallic = normal.w; + s.emissive = emissive.xyz; + s.occlusion = emissive.w; +#if CC_RECEIVE_SHADOW + s.shadowBias = vec2(0, 0); +#endif // fixme: default value is 0, and give black result float fogFactor; CC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor); diff --git a/editor/assets/effects/pipeline/post-process.effect b/editor/assets/effects/pipeline/post-process.effect index 302899d1f1..aa9ca7056d 100644 --- a/editor/assets/effects/pipeline/post-process.effect +++ b/editor/assets/effects/pipeline/post-process.effect @@ -33,7 +33,6 @@ CCProgram post-process-vs %{ CCDecode(In); CC_HANDLE_GET_CLIP_FLIP(In.position.xy); gl_Position = In.position; - gl_Position.y = gl_Position.y; v_uv = a_texCoord; } }% diff --git a/editor/assets/effects/pipeline/skybox.effect b/editor/assets/effects/pipeline/skybox.effect index f9513c2d99..04c16fc0bf 100644 --- a/editor/assets/effects/pipeline/skybox.effect +++ b/editor/assets/effects/pipeline/skybox.effect @@ -6,11 +6,18 @@ CCEffect %{ properties: &props environmentMap: { value: grey } priority: max - 10 - rasterizerState: + rasterizerState: &r1 cullMode: none - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false + - vert: sky-vs:vert + frag: sky-fs:frag + propertyIndex: 0 + priority: max - 10 + phase: deferred-forward + rasterizerState: *r1 + depthStencilState: *d1 }% CCProgram sky-vs %{ diff --git a/editor/assets/effects/pipeline/ssss-blur.effect b/editor/assets/effects/pipeline/ssss-blur.effect index bfba110f79..4d57aaf895 100644 --- a/editor/assets/effects/pipeline/ssss-blur.effect +++ b/editor/assets/effects/pipeline/ssss-blur.effect @@ -52,6 +52,7 @@ CCProgram copy-fs %{ CCProgram ssssBlur %{ precision highp float; + #include #include #include #include diff --git a/editor/assets/effects/util/dcc/imported-metallic-roughness.effect b/editor/assets/effects/util/dcc/imported-metallic-roughness.effect index 780c2a3252..a385d707dd 100644 --- a/editor/assets/effects/util/dcc/imported-metallic-roughness.effect +++ b/editor/assets/effects/util/dcc/imported-metallic-roughness.effect @@ -60,15 +60,20 @@ CCEffect %{ mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } alphaSource: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } } alphaSourceMap: { value: grey, editor: { parent: USE_OPACITY_MAP } } + - &deferred-forward + vert: standard-vs + frag: standard-fs + propertyIndex: 0 + phase: deferred-forward - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -77,6 +82,14 @@ CCEffect %{ properties: *props - *forward-add - *shadow-caster + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -284,7 +297,7 @@ CCProgram surface-fragment %{ #else emissiveColor.rgb *= emissiveScale; #endif - + return emissiveColor.rgb; } @@ -297,7 +310,7 @@ CCProgram surface-fragment %{ #if USE_OCCLUSION_MAP vec4 occlusionColor = texture(occlusionMap, TEXTURE_UV); float occlusionColorValue = discolor(occlusionColor.rgb); - #if USE_OCCLUSION_CHANNEL + #if USE_OCCLUSION_CHANNEL occlusionColor.rgb = SRGBToLinear(occlusionColor.rgb); occlusionColorValue = occlusionColor.OCCLUSION_CHANNEL; #endif @@ -310,7 +323,7 @@ CCProgram surface-fragment %{ #if USE_ROUGHNESS_MAP vec4 roughnessColor = texture(roughnessMap, TEXTURE_UV); roughnessValue = discolor(roughnessColor.rgb); - #if USE_ROUGHNESS_CHANNEL + #if USE_ROUGHNESS_CHANNEL roughnessColor.rgb = SRGBToLinear(roughnessColor.rgb); roughnessValue = roughnessColor.ROUGHNESS_CHANNEL; #endif @@ -323,7 +336,7 @@ CCProgram surface-fragment %{ #if USE_METALLIC_MAP vec4 metallicColor = texture(metallicMap, TEXTURE_UV); metallicValue = discolor(metallicColor.rgb); - #if USE_METALLIC_CHANNEL + #if USE_METALLIC_CHANNEL metallicColor.rgb = SRGBToLinear(metallicColor.rgb); metallicValue = metallicColor.METALLIC_CHANNEL; #endif diff --git a/editor/assets/effects/util/dcc/imported-specular-glossiness.effect b/editor/assets/effects/util/dcc/imported-specular-glossiness.effect index 246ee9232e..fe4565b98b 100644 --- a/editor/assets/effects/util/dcc/imported-specular-glossiness.effect +++ b/editor/assets/effects/util/dcc/imported-specular-glossiness.effect @@ -8,7 +8,7 @@ CCEffect %{ frag: standard-fs properties: &props mainTexture: { value: grey, target: albedoMap, editor: { displayName: DiffuseMap } } - mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: diffuseColor, linear: true, editor: { displayName: DiffuseColor, type: color } } + mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: diffuseColor, linear: true, editor: { displayName: DiffuseColor, type: color } } albedoScale: { value: 1.0, target: diffuseFactor, editor: { displayName: diffuseFactor } } alphaThreshold: { value: 0.5, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } } emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } } @@ -18,10 +18,10 @@ CCEffect %{ shininessExponentMap: { value: grey, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } shininessExponent: { value: 100.0, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } specularGlossinessMap: { value: grey, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } - specularColor: { value: [0.0, 0.0, 0.0, 0.0], linear: true, editor: { displayName: SpecularColor, type: color } } + specularColor: { value: [0.0, 0.0, 0.0, 0.0], linear: true, editor: { displayName: SpecularColor, type: color } } specularMap: { value: grey, editor: { parent: '!HAS_EXPORTED_METALLIC' } } specularFactor: { value: 1.0, editor: { parent: '!HAS_EXPORTED_METALLIC' } } - transparencyMap: { value: grey, editor: { displayName: TransparencyMap } } + transparencyMap: { value: grey, editor: { displayName: TransparencyMap } } transparencyFactor: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } } tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } normalStrength: { value: 1.0, target: normalScale, editor: { displayName: bumpFactor, parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } } @@ -60,25 +60,37 @@ CCEffect %{ albedoScale: { value: 1.0, target: diffuseFactor, editor: { displayName: diffuseFactor } } alphaThreshold: { value: 0.5, editor: { parent: USE_ALPHA_TEST } } mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } - transparencyMap: { value: grey, editor: { displayName: TransparencyMap } } + transparencyMap: { value: grey, editor: { displayName: TransparencyMap } } transparencyFactor: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha - properties: *props - *forward-add - *shadow-caster + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -169,7 +181,7 @@ CCProgram surface-fragment %{ uniform sampler2D transparencyMap; #pragma define-meta TRANSPARENCY_MAP_CHANNEL options([a, r, g, b]) #endif - + #if USE_EMISSIVE_MAP uniform sampler2D emissiveMap; #endif @@ -220,7 +232,7 @@ CCProgram surface-fragment %{ #endif return specularIntensityMultiplier; } - + vec4 getSpecularColorAndFactor() { vec3 inSpecular = specularColor.rgb * specularFactor; @@ -271,7 +283,7 @@ CCProgram surface-fragment %{ #define CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE vec3 SurfacesFragmentModifyEmissive() - { + { vec3 emissiveColor = emissive.rgb; #if USE_EMISSIVE_MAP emissiveColor.rgb = SRGBToLinear(texture(emissiveMap, TEXTURE_UV).rgb); @@ -284,7 +296,7 @@ CCProgram surface-fragment %{ #else emissiveColor.rgb *= emissiveScale; #endif - + return emissiveColor; } diff --git a/editor/assets/effects/util/dcc/vat/houdini-fluid-v3-liquid.effect b/editor/assets/effects/util/dcc/vat/houdini-fluid-v3-liquid.effect index 30499e69a8..25d9e5c09f 100644 --- a/editor/assets/effects/util/dcc/vat/houdini-fluid-v3-liquid.effect +++ b/editor/assets/effects/util/dcc/vat/houdini-fluid-v3-liquid.effect @@ -47,7 +47,7 @@ CCEffect %{ vatRotSignMap: { value: white, target: vatRotSignTexture, editor: { displayName: RotSignMap } } vatRotAlphaMap: { value: grey, target: vatRotAlphaTexture, editor: { displayName: RotAlphaMap } } vatLookupMap: { value: grey, target: vatLookupTexture, editor: { parent: USE_LOOKUP_TEXTURE, displayName: LookupMap } } - rasterizerState: + rasterizerState: &r1 cullMode: none - &forward-add vert: standard-vs @@ -85,15 +85,21 @@ CCEffect %{ frag: reflect-map-fs phase: reflect-map propertyIndex: 0 + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 + rasterizerState: *r1 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -102,6 +108,14 @@ CCEffect %{ properties: *props - *forward-add - *shadow-caster + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -153,7 +167,7 @@ CCProgram surface-vertex %{ #if USE_LOOKUP_TEXTURE uniform highp sampler2D vatLookupTexture; #endif - + #define CC_SURFACES_VERTEX_MODIFY_LOCAL_POS vec3 SurfacesVertexModifyLocalPos(in SurfacesStandardVertexIntermediate In) { @@ -233,7 +247,7 @@ CCProgram surface-vertex %{ vec3 voxelUV = VATCalculateFluidVoxelUV(vatBBMin.xyz, vatBBMax.xyz, In.position.xyz); In.texCoord = voxelUV.xz; #endif - } + } }% CCProgram surface-fragment %{ @@ -369,7 +383,7 @@ void SurfacesLightingModifyFinalResult(inout LightingResult result, in LightingI float multiplier = 1.0 + pow(1.0 - curve, 0.3) * vatLUTParams.w; result.environmentSpecular *= multiplier; #endif - + #if CC_SURFACES_LIGHTING_USE_FRESNEL result.fresnel = GetFresnel(result.fresnel); #endif diff --git a/editor/assets/effects/util/dcc/vat/houdini-rigidbody-v2.effect b/editor/assets/effects/util/dcc/vat/houdini-rigidbody-v2.effect index 34bc0b6d82..9cdff2b1a9 100644 --- a/editor/assets/effects/util/dcc/vat/houdini-rigidbody-v2.effect +++ b/editor/assets/effects/util/dcc/vat/houdini-rigidbody-v2.effect @@ -39,7 +39,7 @@ CCEffect %{ vatRotationMap: { value: grey, target: vatRotationTexture, editor: { displayName: RotationMap } } vatRotSignMap: { value: white, target: vatRotSignTexture, editor: { displayName: RotSignMap } } vatRotAlphaMap: { value: grey, target: vatRotAlphaTexture, editor: { displayName: RotAlphaMap } } - rasterizerState: + rasterizerState: &r1 cullMode: none - &forward-add vert: standard-vs @@ -77,15 +77,21 @@ CCEffect %{ frag: reflect-map-fs phase: reflect-map propertyIndex: 0 + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 + rasterizerState: *r1 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -94,6 +100,14 @@ CCEffect %{ properties: *props - *forward-add - *shadow-caster + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -113,7 +127,7 @@ CCProgram macro-remapping %{ // ui displayed macros #pragma define-meta USE_TWOSIDE #pragma define-meta IS_ANISOTROPY - #pragma define-meta USE_VERTEX_COLOR + #pragma define-meta USE_VERTEX_COLOR #define CC_SURFACES_USE_SECOND_UV 1 #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE #define CC_SURFACES_LIGHTING_ANISOTROPIC IS_ANISOTROPY @@ -164,11 +178,11 @@ CCProgram surface-vertex %{ #endif #if CC_SURFACES_USE_TANGENT_SPACE vec3 tangent = In.tangent.xzy; - #else + #else vec3 tangent = vec3(0.0); - #endif + #endif - VATGetLocalPositionRigidBody20_UE(In.position.xyz, In.normal.xyz, tangent, color, thisFrameUV, + VATGetLocalPositionRigidBody20_UE(In.position.xyz, In.normal.xyz, tangent, color, thisFrameUV, vatMaxMin.x, vatMaxMin.y, vatMaxMin.z, vatMaxMin.w, vatPositionTexture, vatPosSignTexture, vatPosAlphaTexture, vatRotationTexture, vatRotSignTexture, vatRotAlphaTexture); @@ -217,7 +231,7 @@ CCProgram surface-fragment %{ vec4 SurfacesFragmentModifyBaseColorAndTransparency() { vec4 baseColor = albedo; - + #if USE_ALBEDO_MAP vec4 texColor = texture(albedoMap, ALBEDO_UV); texColor.rgb = SRGBToLinear(texColor.rgb); @@ -243,7 +257,7 @@ CCProgram surface-fragment %{ #if USE_ALBEDO_MAP alpha = texture(albedoMap, ALBEDO_UV).ALPHA_TEST_CHANNEL; #endif - + if (alpha < albedoScaleAndCutoff.w) discard; #endif } diff --git a/editor/assets/effects/util/dcc/vat/houdini-softbody-v3.effect b/editor/assets/effects/util/dcc/vat/houdini-softbody-v3.effect index 0a09914bc0..1e6be194e5 100644 --- a/editor/assets/effects/util/dcc/vat/houdini-softbody-v3.effect +++ b/editor/assets/effects/util/dcc/vat/houdini-softbody-v3.effect @@ -33,7 +33,7 @@ CCEffect %{ vatRotationMap: { value: grey, target: vatRotationTexture, editor: { displayName: RotationMap } } vatRotSignMap: { value: white, target: vatRotSignTexture, editor: { displayName: RotSignMap } } vatRotAlphaMap: { value: grey, target: vatRotAlphaTexture, editor: { displayName: RotAlphaMap } } - rasterizerState: + rasterizerState: &r1 cullMode: none - &forward-add vert: standard-vs @@ -71,23 +71,36 @@ CCEffect %{ frag: reflect-map-fs phase: reflect-map propertyIndex: 0 + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 + rasterizerState: *r1 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha - properties: *props - *forward-add - *shadow-caster + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -224,7 +237,7 @@ CCProgram surface-fragment %{ vec4 SurfacesFragmentModifyBaseColorAndTransparency() { vec4 baseColor = albedo; - + #if USE_VERTEX_COLOR baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear baseColor.a *= FSInput_vertexColor.a; @@ -255,7 +268,7 @@ CCProgram surface-fragment %{ #if USE_ALBEDO_MAP alpha = texture(albedoMap, ALBEDO_UV).ALPHA_TEST_CHANNEL; #endif - + if (alpha < albedoScaleAndCutoff.w) discard; #endif } diff --git a/editor/assets/effects/util/dcc/vat/zeno-fluid-liquid.effect b/editor/assets/effects/util/dcc/vat/zeno-fluid-liquid.effect index 0ef61d3b40..dee64a0c75 100644 --- a/editor/assets/effects/util/dcc/vat/zeno-fluid-liquid.effect +++ b/editor/assets/effects/util/dcc/vat/zeno-fluid-liquid.effect @@ -36,7 +36,7 @@ CCEffect %{ waterScatterCoef: { value: 3.0, target: waterColor.w, editor: { parent: USE_WATER_SCATTERING, range: [0, 10.0] } } vatPositionMap: { value: grey, target: vatPositionTexture, editor: { displayName: PositionMap } } vatNormalMap: { value: grey, target: vatNormalTexture } - rasterizerState: + rasterizerState: &r1 cullMode: none - &forward-add vert: standard-vs @@ -73,15 +73,21 @@ CCEffect %{ frag: reflect-map-fs phase: reflect-map propertyIndex: 0 + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + propertyIndex: 0 + rasterizerState: *r1 - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } - depthStencilState: + depthStencilState: &d1 depthTest: true depthWrite: false - blendState: + blendState: &b1 targets: - blend: true blendSrc: src_alpha @@ -90,6 +96,14 @@ CCEffect %{ properties: *props - *forward-add - *shadow-caster + - &deferred-forward + vert: standard-vs + frag: standard-fs + phase: deferred-forward + embeddedMacros: { CC_PIPELINE_TYPE: 0 } + depthStencilState: *d1 + blendState: *b1 + propertyIndex: 0 }% CCProgram shared-ubos %{ @@ -156,7 +170,7 @@ CCProgram surface-vertex %{ // pos is normalized 0-1 from texture and expanding to bounding box range vec3 posNormalized = SampleTextureExr(vatPositionTexture, thisFrameUV); In.position.xyz = posNormalized * (vatBBMax.xyz - vatBBMin.xyz) + vatBBMin.xyz; - + vec3 normal = texture(vatNormalTexture, thisFrameUV).rgb * 2.0 - 1.0; In.normal.xyz = normalize(normal); } @@ -253,7 +267,7 @@ CCProgram surface-fragment %{ { return vatAnimParams.w; } - + #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_SCATTERING_PARAMS vec4 SurfacesFragmentModifyTransmitScatteringParams() { @@ -264,7 +278,7 @@ CCProgram surface-fragment %{ return vec4(0.0, 0.0, 0.0, 0.0); #endif } - + #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_IN_SCATTERING_COLOR vec3 SurfacesFragmentModifyTransmitInScatteringColor() { @@ -284,7 +298,7 @@ CCProgram surface-fragment %{ vec4 SurfacesFragmentModifyBaseColorAndTransparency() { vec4 baseColor = albedo; - + #if USE_VERTEX_COLOR baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear baseColor.a *= FSInput_vertexColor.a; @@ -306,7 +320,7 @@ CCProgram surface-fragment %{ #if USE_VERTEX_COLOR alpha *= FSInput_vertexColor.a; #endif - + if (alpha < albedoScaleAndCutoff.w) discard; #endif } @@ -331,7 +345,7 @@ void SurfacesLightingModifyFinalResult(inout LightingResult result, in LightingI float multiplier = 1.0 + pow(1.0 - curve, 0.3) * vatLUTParams.w; result.environmentSpecular *= multiplier; #endif - + #if CC_SURFACES_LIGHTING_USE_FRESNEL result.fresnel = GetFresnel(result.fresnel); #endif diff --git a/editor/engine-features/render-config.json b/editor/engine-features/render-config.json index 59f4a6093b..a562f3bd67 100644 --- a/editor/engine-features/render-config.json +++ b/editor/engine-features/render-config.json @@ -234,7 +234,7 @@ "label": "i18n:ENGINE.features.spine.label", "description": "i18n:ENGINE.features.spine.description", "native": "USE_SPINE", - "wechatPlugin": true, + "wechatPlugin": false, "category": "2d" }, "dragon-bones": { diff --git a/editor/i18n/en/animation.js b/editor/i18n/en/animation.js index a9bd0f3526..7d5f7e4543 100644 --- a/editor/i18n/en/animation.js +++ b/editor/i18n/en/animation.js @@ -24,7 +24,7 @@ module.exports = { }, 'PoseNodeUseStashedPose': { displayName: 'Use Stashed Pose', - title: 'Use Stashed Pose {stashName}', + title: 'Use Stash {stashName}', }, 'PoseNodeStateMachine': { displayName: 'State Machine', @@ -213,7 +213,7 @@ module.exports = { 'rotation': { displayName: 'Rotation', }, - 'intensity': { + 'intensityValue': { displayName: 'Intensity', }, }, diff --git a/editor/i18n/zh/animation.js b/editor/i18n/zh/animation.js index 8b66ff6a48..08fe607315 100644 --- a/editor/i18n/zh/animation.js +++ b/editor/i18n/zh/animation.js @@ -4,7 +4,7 @@ module.exports = { animation_graph: { pose_graph_node_sub_categories: { - pose_nodes: '姿势结点', + pose_nodes: '姿态结点', pose_nodes_blend: '混合', pose_nodes_ik: '反向动力学', pose_nodes_choose: '选择', @@ -20,17 +20,17 @@ module.exports = { 'cc': { 'animation': { 'PoseGraphOutputNode': { - displayName: '输出姿势', + displayName: '输出姿态', }, 'PoseNodeUseStashedPose': { - displayName: '使用暂存的姿势', - title: '使用暂存的姿势 {stashName}', + displayName: '使用暂存', + title: '使用暂存 {stashName}', }, 'PoseNodeStateMachine': { displayName: '状态机', inputs: { 'emptyStatePose': { - displayName: '空状态姿势', + displayName: '空状态姿态', }, }, }, @@ -100,20 +100,20 @@ module.exports = { displayName: '按占比混合', inputs: { 'poses': { - displayName: '姿势 {elementIndex}', + displayName: '姿态 {elementIndex}', }, 'proportions': { - displayName: '姿势 {elementIndex} 占比', + displayName: '姿态 {elementIndex} 占比', }, }, }, 'PoseNodeBlendTwoPoseBase': { inputs: { 'pose0': { - displayName: '姿势 1', + displayName: '姿态 1', }, 'pose1': { - displayName: '姿势 2', + displayName: '姿态 2', }, 'ratio': { displayName: '比例', @@ -121,7 +121,7 @@ module.exports = { }, }, 'PoseNodeBlendTwoPose': { - displayName: '混合双姿势', + displayName: '混合双姿态', inputs: { __extends__: 'classes.cc.animation.PoseNodeBlendTwoPoseBase.inputs', }, @@ -133,13 +133,13 @@ module.exports = { }, }, 'PoseNodeAdditivelyBlend': { - displayName: '加性混合', + displayName: '叠加混合', inputs: { 'basePose': { - displayName: '基础姿势', + displayName: '基础姿态', }, 'additivePose': { - displayName: '累加姿势', + displayName: '叠加姿态', }, 'ratio': { displayName: '比例', @@ -150,16 +150,16 @@ module.exports = { displayName: '按布尔选择', inputs: { 'truePose': { - displayName: '为真时姿势', + displayName: '为真时姿态', }, 'falsePose': { - displayName: '为假时姿势', + displayName: '为假时姿态', }, 'trueFadeInDuration': { - displayName: '为真时姿势淡入时长', + displayName: '为真时姿态淡入时长', }, 'falseFadeInDuration': { - displayName: '为假时姿势淡入时长', + displayName: '为假时姿态淡入时长', }, 'choice': { displayName: '选择', @@ -170,10 +170,10 @@ module.exports = { displayName: '按索引选择', inputs: { poses: { - displayName: '姿势 {elementIndex}', + displayName: '姿态 {elementIndex}', }, fadeInDurations: { - displayName: '姿势 {elementIndex} 淡入时长', + displayName: '姿态 {elementIndex} 淡入时长', }, 'choice': { displayName: '选择', @@ -183,7 +183,7 @@ module.exports = { 'PoseNodeModifyPoseBase': { inputs: { 'pose': { - displayName: '姿势', + displayName: '姿态', }, }, }, diff --git a/editor/i18n/zh/assets.js b/editor/i18n/zh/assets.js index f4d354857d..80f563243d 100644 --- a/editor/i18n/zh/assets.js +++ b/editor/i18n/zh/assets.js @@ -428,14 +428,14 @@ module.exports = { }, animationSetting: { additive: { - header: '加性动画导入设置', + header: '叠加动画导入设置', enabled: { - label: '导入为加性', - tooltip: '勾选后,该动画将被导入为加性动画。', + label: '导入为叠加动画', + tooltip: '勾选后,该动画将被导入为叠加动画。', }, refClip: { label: '参考剪辑', - tooltip: '若设置,将参考该动画第 0 帧的姿势计算加性动画;否则,则将参考第动画本身第 0 帧的姿势进行计算。', + tooltip: '若设置,将参考该动画第 0 帧的姿态计算叠加动画;否则,则将参考第动画本身第 0 帧的姿态进行计算。', }, }, }, diff --git a/editor/inspector/assets/animation-mask.js b/editor/inspector/assets/animation-mask.js index 17bad1664d..3180d1e315 100644 --- a/editor/inspector/assets/animation-mask.js +++ b/editor/inspector/assets/animation-mask.js @@ -43,7 +43,8 @@ exports.style = /* css */` } .asset-animation-mask > .header { - margin-top: 10px; + margin-top: 8px; + margin-right: 4px; display: flex; } @@ -286,7 +287,7 @@ exports.ready = function() { ], listeners: { async confirm(detail) { - if (!detail) return; + if (!detail) { return; } const info = await Editor.Message.request('asset-db', 'query-asset-info', detail.value); if (!info || !info.redirect || info.redirect.type !== 'cc.Prefab') { console.error(Editor.I18n.t('ENGINE.assets.animationMask.illegalFbx') + ` {asset(${detail.value})}`); diff --git a/editor/inspector/assets/asterisk.js b/editor/inspector/assets/asterisk.js index 5a86d07e73..fc2c872bf5 100644 --- a/editor/inspector/assets/asterisk.js +++ b/editor/inspector/assets/asterisk.js @@ -18,7 +18,6 @@ exports.style = /* css */` flex: 1; display: flex; flex-direction: column; - margin-top: 4px; /* it is necessary */ height: 0px; } diff --git a/editor/inspector/assets/effect-header.js b/editor/inspector/assets/effect-header.js index e242b2a095..1c3b9c0f10 100644 --- a/editor/inspector/assets/effect-header.js +++ b/editor/inspector/assets/effect-header.js @@ -18,7 +18,6 @@ exports.style = /* css */` flex: 1; display: flex; flex-direction: column; - margin-top: 4px; margin-bottom: 4px; /* it is necessary */ height: 0px; diff --git a/editor/inspector/assets/effect.js b/editor/inspector/assets/effect.js index b991493c9c..234e7166ea 100644 --- a/editor/inspector/assets/effect.js +++ b/editor/inspector/assets/effect.js @@ -26,7 +26,9 @@ exports.template = /* html */` `; exports.style = /* css */` - .asset-effect { } + .asset-effect { + padding-right: 4px; + } .asset-effect[multiple-invalid] > *:not(.multiple-warn-tip) { display: none!important; @@ -57,12 +59,13 @@ exports.style = /* css */` color: var(--color-info-contrast-important); } .asset-effect > .codes .tabs { - margin: 4px auto; - text-align: center; + margin: 4px auto 6px auto; } .asset-effect > .codes .tabs > .tab { padding: 0; width: 110px; + height: 20px; + box-sizing: border-box; text-align: center; cursor: pointer; display: inline-block; diff --git a/editor/inspector/assets/erp-texture-cube.js b/editor/inspector/assets/erp-texture-cube.js index b530ea8fb6..dd632112cb 100644 --- a/editor/inspector/assets/erp-texture-cube.js +++ b/editor/inspector/assets/erp-texture-cube.js @@ -60,13 +60,13 @@ exports.template = /* html */ ` `; exports.style = /* css */` -.asset-erp-texture-cube ui-prop{ - margin-top: 4px; +.asset-erp-texture-cube ui-prop{ + margin-right: 4px; } .asset-erp-texture-cube #filterAdvancedSection, .asset-erp-texture-cube #wrapAdvancedSection, .asset-erp-texture-cube #generateMipmapsSection { - margin-left: 1.2em; + margin-left: 1em; display: none; } `; diff --git a/editor/inspector/assets/fbx/animation.js b/editor/inspector/assets/fbx/animation.js index a15029f9d0..9693331cf5 100644 --- a/editor/inspector/assets/fbx/animation.js +++ b/editor/inspector/assets/fbx/animation.js @@ -78,7 +78,7 @@ exports.template = /* html */` Speed - + @@ -97,6 +97,10 @@ exports.template = /* html */` `; exports.style = /* css */` +.container { + padding: 4px; +} + .container[multiple-invalid] > *:not(.multiple-warn-tip) { display: none!important; } diff --git a/editor/inspector/assets/fbx/fbx.js b/editor/inspector/assets/fbx/fbx.js index b0435e3add..ab3e90081e 100644 --- a/editor/inspector/assets/fbx/fbx.js +++ b/editor/inspector/assets/fbx/fbx.js @@ -41,6 +41,9 @@ exports.template = /* html */` `; exports.style = /* css */` +ui-prop { margin-right: 4px; } +ui-section.config { margin-right: 0; } + .warn-words { color: var(--color-warn-fill); } diff --git a/editor/inspector/assets/fbx/index.js b/editor/inspector/assets/fbx/index.js index 7ef62675ee..5df8c24e25 100644 --- a/editor/inspector/assets/fbx/index.js +++ b/editor/inspector/assets/fbx/index.js @@ -21,8 +21,10 @@ exports.style = /* css */` } .asset-fbx > .header { - padding-top: 8px; - padding-bottom: 8px; + padding: 8px 4px; +} +.asset-fbx > .header > .tabs { + height: 24px; } `; @@ -67,6 +69,7 @@ const Elements = { panel.tabs.forEach((tab) => { const button = document.createElement('ui-button'); + button.setAttribute('size', 'medium'); panel.$.tabs.appendChild(button); const label = document.createElement('ui-label'); diff --git a/editor/inspector/assets/fbx/material.js b/editor/inspector/assets/fbx/material.js index 550c4cb2b1..9b90e08d33 100644 --- a/editor/inspector/assets/fbx/material.js +++ b/editor/inspector/assets/fbx/material.js @@ -27,6 +27,9 @@ exports.template = /* html */` `; exports.style = /* css */` +ui-prop { margin-right: 4px; } +ui-section.config { margin-right: 0; } + .images { margin: 4px 0; } diff --git a/editor/inspector/assets/fbx/model.js b/editor/inspector/assets/fbx/model.js index 8ab722a8c4..f7f240b34c 100644 --- a/editor/inspector/assets/fbx/model.js +++ b/editor/inspector/assets/fbx/model.js @@ -141,6 +141,9 @@ exports.template = /* html */` `; exports.style = /* css */` +ui-prop { margin-right: 4px; } +ui-section.config { margin-right: 0; } + .warn-words { color: var(--color-warn-fill); } diff --git a/editor/inspector/assets/fbx/preview.js b/editor/inspector/assets/fbx/preview.js index 7158a19a64..08e0fcb382 100644 --- a/editor/inspector/assets/fbx/preview.js +++ b/editor/inspector/assets/fbx/preview.js @@ -76,6 +76,10 @@ exports.style = /* css*/` min-height: 200px; border-top: 1px solid var(--color-normal-border); } +.preview-container > .animation-info { + padding-right: 4px; +} + .preview[hoving] > .preview-container { outline: 2px solid var(--color-focus-fill-weaker); outline-offset: -1px; @@ -86,6 +90,7 @@ exports.style = /* css*/` } .preview-container > .model-info { display: none; + padding: 2px 4px; } .preview-container > .model-info > ui-label { margin-right: 6px; @@ -666,16 +671,16 @@ exports.methods = { addAssetChangeListener(add = true) { if (!add && this.hasListenAssetsChange) { - Editor.Message.__protected__.removeBroadcastListener('scene:asset-applied', this.onAssetChangeBind); + Editor.Message.__protected__.removeBroadcastListener('asset-db:asset-change', this.onAssetChangeBind); this.hasListenAssetsChange = false; return; } - Editor.Message.__protected__.addBroadcastListener('scene:asset-applied', this.onAssetChangeBind); + Editor.Message.__protected__.addBroadcastListener('asset-db:asset-change', this.onAssetChangeBind); this.hasListenAssetsChange = true; }, - async onAssetChange(uuids) { - if (uuids.includes(this.asset.uuid)) { + async onAssetChange(uuid) { + if (this.asset.uuid === uuid) { // Update the animation dump when the parent assets changes this.meta = await Editor.Message.request('asset-db', 'query-asset-meta', this.asset.uuid); const clipInfo = animation.methods.getCurClipInfo.call(this); @@ -684,7 +689,7 @@ exports.methods = { }, }; -exports.ready = function() { +exports.ready = function () { this.gridWidth = 0; this.gridTableWith = 0; this.activeTab = 'animation'; @@ -726,7 +731,7 @@ exports.ready = function() { this.eventEditor.ready.call(this); }; -exports.update = async function(assetList, metaList) { +exports.update = async function (assetList, metaList) { this.assetList = assetList; this.metaList = metaList; this.isMultiple = this.assetList.length > 1; @@ -757,7 +762,7 @@ exports.update = async function(assetList, metaList) { this.refreshPreview(); }; -exports.close = function() { +exports.close = function () { for (const prop in Elements) { const element = Elements[prop]; if (element.close) { diff --git a/editor/inspector/assets/image.js b/editor/inspector/assets/image.js index 2ed8894ec0..401a58ab48 100644 --- a/editor/inspector/assets/image.js +++ b/editor/inspector/assets/image.js @@ -26,11 +26,11 @@ exports.template = /* html */` - + -