Skip to content

Commit

Permalink
Merge pull request #16148 from cocos/v3.8.1
Browse files Browse the repository at this point in the history
V3.8.1
  • Loading branch information
minggo authored Aug 31, 2023
2 parents e63456c + 77d3f7c commit 1e3155b
Show file tree
Hide file tree
Showing 24 changed files with 324 additions and 91 deletions.
1 change: 1 addition & 0 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
"modules": ["custom-pipeline"],
"dependentAssets": [
"15049ccd-4dd7-451e-a8ae-af66735c929e",
"521c5f6e-1a26-42e2-8108-4400c912d9bf",
"4c3ce6de-e6d1-47f7-aa36-36b9b58f72d3",
"4361db28-3f24-44cc-8e51-32ee5fd651ac",
"cafd95c9-c558-46f9-9812-1224b65c09ee",
Expand Down
77 changes: 42 additions & 35 deletions cocos/3d/misc/mesh-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import meshopt_asm_factory from 'external:emscripten/meshopt/meshopt_decoder.asm.js';
import meshopt_wasm_factory from 'external:emscripten/meshopt/meshopt_decoder.wasm.js';
import meshopt_wasm_url from 'external:emscripten/meshopt/meshopt_decoder.wasm.wasm';

import { WASM_SUPPORT_MODE } from 'internal:constants';
import { instantiateWasm } from 'pal/wasm';
import { ensureWasmModuleReady, instantiateWasm } from 'pal/wasm';

import { sys, logID } from '../../core';

Expand All @@ -36,51 +31,63 @@ import { WebAssemblySupportMode } from '../../misc/webassembly-support';

export const MeshoptDecoder = {} as any;

function initDecoderASM (): Promise<void> {
const Module = meshopt_asm_factory;
return Promise.all([Module.ready]).then(() => {
MeshoptDecoder.supported = true;
function initDecoderASM (asm_factory: any): Promise<void> {
return Promise.all([asm_factory.ready]).then(() => {
MeshoptDecoder.supported = asm_factory.supported;
MeshoptDecoder.ready = Promise.resolve();
MeshoptDecoder.decodeVertexBuffer = Module.decodeVertexBuffer;
MeshoptDecoder.decodeIndexBuffer = Module.decodeIndexBuffer;
MeshoptDecoder.decodeIndexSequence = Module.decodeIndexSequence;
MeshoptDecoder.decodeGltfBuffer = Module.decodeGltfBuffer;
MeshoptDecoder.useWorkers = Module.useWorkers;
MeshoptDecoder.decodeGltfBufferAsync = Module.decodeGltfBufferAsync;
MeshoptDecoder.decodeVertexBuffer = asm_factory.decodeVertexBuffer;
MeshoptDecoder.decodeIndexBuffer = asm_factory.decodeIndexBuffer;
MeshoptDecoder.decodeIndexSequence = asm_factory.decodeIndexSequence;
MeshoptDecoder.decodeGltfBuffer = asm_factory.decodeGltfBuffer;
MeshoptDecoder.useWorkers = asm_factory.useWorkers;
MeshoptDecoder.decodeGltfBufferAsync = asm_factory.decodeGltfBufferAsync;
logID(14202);
});
}

function initDecoderWASM (): Promise<void> {
const Module = meshopt_wasm_factory;
function initDecoderWASM (wasm_factory: any, wasm_url: string): Promise<void> {
function instantiate (importObject: WebAssembly.Imports): any {
return instantiateWasm(meshopt_wasm_url, importObject) as any;
return instantiateWasm(wasm_url, importObject) as any;
}
return Promise.all([Module.ready(instantiate)]).then(() => {
MeshoptDecoder.supported = true;
return Promise.all([wasm_factory.ready(instantiate)]).then(() => {
MeshoptDecoder.supported = wasm_factory.supported;
MeshoptDecoder.ready = Promise.resolve();
MeshoptDecoder.decodeVertexBuffer = Module.decodeVertexBuffer;
MeshoptDecoder.decodeIndexBuffer = Module.decodeIndexBuffer;
MeshoptDecoder.decodeIndexSequence = Module.decodeIndexSequence;
MeshoptDecoder.decodeGltfBuffer = Module.decodeGltfBuffer;
MeshoptDecoder.useWorkers = Module.useWorkers;
MeshoptDecoder.decodeGltfBufferAsync = Module.decodeGltfBufferAsync;
MeshoptDecoder.decodeVertexBuffer = wasm_factory.decodeVertexBuffer;
MeshoptDecoder.decodeIndexBuffer = wasm_factory.decodeIndexBuffer;
MeshoptDecoder.decodeIndexSequence = wasm_factory.decodeIndexSequence;
MeshoptDecoder.decodeGltfBuffer = wasm_factory.decodeGltfBuffer;
MeshoptDecoder.useWorkers = wasm_factory.useWorkers;
MeshoptDecoder.decodeGltfBufferAsync = wasm_factory.decodeGltfBufferAsync;
logID(14203);
});
}

export function InitDecoder (): Promise<void> {
function shouldUseWasmModule (): boolean {
if (WASM_SUPPORT_MODE === (WebAssemblySupportMode.MAYBE_SUPPORT as number)) {
if (sys.hasFeature(sys.Feature.WASM)) {
return initDecoderWASM();
} else {
return initDecoderASM();
}
return sys.hasFeature(sys.Feature.WASM);
} else if (WASM_SUPPORT_MODE === (WebAssemblySupportMode.SUPPORT as number)) {
return initDecoderWASM();
return true;
} else {
return initDecoderASM();
return false;
}
}

export function InitDecoder (): Promise<void> {
return ensureWasmModuleReady().then(() => Promise.all([
import('external:emscripten/meshopt/meshopt_decoder.asm.js'),
import('external:emscripten/meshopt/meshopt_decoder.wasm.js'),
import('external:emscripten/meshopt/meshopt_decoder.wasm.wasm'),
]).then(([
{ default: meshopt_asm_factory },
{ default: meshopt_wasm_factory },
{ default: meshopt_wasm_url },
]) => {
if (shouldUseWasmModule()) {
return initDecoderWASM(meshopt_wasm_factory, meshopt_wasm_url);
} else {
return initDecoderASM(meshopt_asm_factory);
}
}));
}

game.onPostInfrastructureInitDelegate.add(InitDecoder);
30 changes: 28 additions & 2 deletions cocos/rendering/post-process/components/bloom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ccclass, disallowMultiple, executeInEditMode, help, menu, range, rangeMin, serializable, slide, tooltip, type } from '../../../core/data/decorators';
import { CCFloat, CCInteger } from '../../../core/data/utils/attribute';
import { cclegacy } from '../../../core';
import { ccclass, disallowMultiple, executeInEditMode, help, menu, range, rangeMin,
serializable, slide, tooltip, type, visible } from '../../../core/data/decorators';
import { CCBoolean, CCFloat, CCInteger } from '../../../core/data/utils/attribute';
import { Root } from '../../../root';
import { PostProcessSetting } from './post-process-setting';

@ccclass('cc.Bloom')
Expand All @@ -8,13 +11,36 @@ import { PostProcessSetting } from './post-process-setting';
@disallowMultiple
@executeInEditMode
export class Bloom extends PostProcessSetting {
@serializable
protected _enableAlphaMask = false;
@serializable
protected _useHdrIlluminance: boolean = false;
@serializable
protected _threshold = 0.8;
@serializable
protected _iterations = 3;
@serializable
protected _intensity = 2.3;

@tooltip('i18n:bloom.enableAlphaMask')
@type(CCBoolean)
set enableAlphaMask (value: boolean) {
this._enableAlphaMask = value;
}
get enableAlphaMask (): boolean {
return this._enableAlphaMask;
}

@tooltip('i18n:bloom.useHdrIlluminance')
@visible(() => (cclegacy.director.root as Root).pipeline.getMacroBool('CC_USE_FLOAT_OUTPUT'))
@type(CCBoolean)
set useHdrIlluminance (value: boolean) {
this._useHdrIlluminance = value;
}
get useHdrIlluminance (): boolean {
return this._useHdrIlluminance;
}

@tooltip('i18n:bloom.threshold')
@rangeMin(0)
@type(CCFloat)
Expand Down
10 changes: 9 additions & 1 deletion cocos/rendering/post-process/passes/bloom-pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export class BloomPass extends SettingPass {
name = 'BloomPass';
effectName = 'pipeline/post-process/bloom';
outputNames = ['BloomColor'];
private _hdrInputName: string = '';

set hdrInputName (name: string) {
this._hdrInputName = name;
}

public render (camera: Camera, ppl: Pipeline): void {
const cameraID = getCameraUniqueID(camera);
Expand All @@ -44,11 +49,14 @@ export class BloomPass extends SettingPass {
const output = `BLOOM_PREFILTER_COLOR${cameraID}`;
// prefilter pass
let shadingScale = 1 / 2;
passContext.material.setProperty('texSize', new Vec4(0, 0, setting.threshold, 0), 0);
const enableAlphaMask = setting.enableAlphaMask as unknown as number;
const useHDRIntensity = setting.useHdrIlluminance as unknown as number;
passContext.material.setProperty('texSize', new Vec4(useHDRIntensity, 0, setting.threshold, enableAlphaMask), 0);
passContext
.updatePassViewPort(shadingScale)
.addRenderPass('bloom-prefilter', `bloom-prefilter${cameraID}`)
.setPassInput(input, 'outputResultMap')
.setPassInput(this._hdrInputName, 'hdrInputMap')
.addRasterView(output, Format.RGBA8)
.blitScreen(0)
.version();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ export class FloatOutputProcessPass extends SettingPass {
effectName = 'pipeline/float-output-process';
outputNames = ['FloatOutputProcess'];

hdrInputName: string = '';

enableInAllEditorCamera = true;
enable = true;
checkEnable (camera: Camera): boolean {
const ppl = (cclegacy.director.root as Root).pipeline;
return ppl.getMacroBool('CC_USE_FLOAT_OUTPUT');
}
getHDRInputName (): string { return this.hdrInputName; }

onGlobalPipelineStateChanged (): void {
passContext.material = this.material;
Expand Down Expand Up @@ -81,15 +84,15 @@ export class FloatOutputProcessPass extends SettingPass {
}

passIndx = 1;
const input = this.lastPass!.slotName(camera, 0);
this.hdrInputName = this.lastPass!.slotName(camera, 0);
const output = this.slotName(camera, 0);
const layoutName = 'tone-mapping';
const passName = `tone-mapping${cameraID}`;
passContext.clearFlag = ClearFlagBit.COLOR;
Vec4.set(passContext.clearColor, camera.clearColor.x, camera.clearColor.y, camera.clearColor.z, camera.clearColor.w);
passContext.updatePassViewPort()
.addRenderPass(layoutName, passName)
.setPassInput(input, 'u_texSampler')
.setPassInput(this.hdrInputName, 'u_texSampler')
.setPassInput(copyDS, 'DepthTex')
.addRasterView(output, Format.RGBA8)
.blitScreen(passIndx)
Expand Down
1 change: 1 addition & 0 deletions cocos/rendering/post-process/passes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './float-output-process-pass';
export * from './forward-transparency-pass';
export * from './forward-transparency-simple-pass';
export * from './skin-pass';
export * from './post-final-pass';
47 changes: 47 additions & 0 deletions cocos/rendering/post-process/passes/post-final-pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Vec4 } from '../../../core';
import { ClearFlagBit, Format } from '../../../gfx';
import { Camera } from '../../../render-scene/scene';
import { getCameraUniqueID } from '../../custom/define';
import { Pipeline } from '../../custom/pipeline';
import { passContext } from '../utils/pass-context';
import { BasePass } from './base-pass';

export class PostFinalPass extends BasePass {
name = 'PostFinalPass';
outputNames = ['PostFinalColor'];
effectName = 'pipeline/post-process/post-final';

enableInAllEditorCamera = true;

public render (camera: Camera, ppl: Pipeline): void {
if (!this.lastPass) {
return;
}

passContext.clearFlag = camera.clearFlag & ClearFlagBit.COLOR;
Vec4.set(passContext.clearColor, camera.clearColor.x, camera.clearColor.y, camera.clearColor.z, camera.clearColor.w);

passContext.material = this.material;

const cameraID = getCameraUniqueID(camera);

const input0 = this.lastPass.slotName(camera, 0);
const slot0 = this.slotName(camera, 0);

const isOffScreen = false;//director.root!.mainWindow !== camera.window;

const fb = camera.window.framebuffer;
const ct = fb && fb.colorTextures[0];
const format = ct ? ct.format : Format.RGBA8;

const shadingScale = passContext.shadingScale;
passContext
.updatePassViewPort(1 / shadingScale, 1 / shadingScale)
.addRenderPass('post-final', `${this.name}${cameraID}`)
.setPassInput(input0, 'inputTexture')
.addRasterView(slot0, format, isOffScreen)
.blitScreen(0);

this.renderProfiler(camera);
}
}
10 changes: 8 additions & 2 deletions cocos/rendering/post-process/post-process-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { director } from '../../game';

import { Camera as CameraComponent } from '../../misc';
import { BloomPass, ColorGradingPass, FloatOutputProcessPass, ForwardTransparencyPass,
ForwardTransparencySimplePass, FxaaPass, SkinPass } from './passes';
ForwardTransparencySimplePass, FxaaPass, PostFinalPass, SkinPass } from './passes';
import { PipelineEventType } from '../pipeline-event';

export class PostProcessBuilder implements PipelineBuilder {
Expand Down Expand Up @@ -79,7 +79,7 @@ export class PostProcessBuilder implements PipelineBuilder {

// final output
this.addPass(new FSRPass()); // fsr should be final
this.addPass(forwardFinal);
this.addPass(new PostFinalPass());
}

getPass (passClass: typeof BasePass, pipelineName = 'forward'): BasePass | undefined {
Expand Down Expand Up @@ -223,6 +223,8 @@ export class PostProcessBuilder implements PipelineBuilder {
taaPass.updateSample();
}

const floatOutputPass = passes.find((p): boolean => p instanceof FloatOutputProcessPass) as FloatOutputProcessPass;

let lastPass: BasePass | undefined;
for (let i = 0; i < passes.length; i++) {
const pass = passes[i];
Expand All @@ -234,6 +236,10 @@ export class PostProcessBuilder implements PipelineBuilder {
passContext.isFinalPass = true;
}

if (pass.name === 'BloomPass') {
(pass as BloomPass).hdrInputName = floatOutputPass.getHDRInputName();
}

pass.lastPass = lastPass;
pass.render(camera, ppl);

Expand Down
31 changes: 22 additions & 9 deletions editor/assets/effects/pipeline/post-process/bloom.effect
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ CCProgram prefilter-fs %{
precision highp float;
#include <builtin/uniforms/cc-global>
#include <common/color/gamma>
#include <common/common-define>

in vec2 v_uv;

uniform BloomUBO {
mediump vec4 texSize;
mediump vec4 texSize;// x: useHDRIlluminance,z: threshold, w: enableAlphaMask
};
#pragma rate outputResultMap pass
uniform sampler2D outputResultMap;
uniform sampler2D outputResultMap; // ldr input
#pragma rate hdrInputMap pass
uniform sampler2D hdrInputMap; // hdr input

layout(location = 0) out vec4 fragColor;

Expand All @@ -128,13 +131,23 @@ CCProgram prefilter-fs %{
}

void main() {
vec3 color = texture(outputResultMap, v_uv).xyz;

if (luminance(SRGBToLinear(color)) > texSize.z) {
fragColor = vec4(color, 1.0);
} else {
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
#if CC_USE_FLOAT_OUTPUT
if(texSize.x > 0.0) {
color = texture(hdrInputMap, v_uv);
} else {
color = texture(outputResultMap, v_uv);
// color.xyz = SRGBToLinear(color.xyz);
}
#else
color = texture(outputResultMap, v_uv);
// color.xyz = SRGBToLinear(color.xyz);
#endif

float contribute = step(texSize.z, luminance(color.rgb));
contribute *= mix(1.0, step(253.0 / 255.0, color.a), texSize.w);

fragColor = vec4(color.xyz * contribute, 1.0);
}
}%

Expand Down
Loading

0 comments on commit 1e3155b

Please sign in to comment.