-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathforward-pass.ts
More file actions
94 lines (82 loc) · 3.92 KB
/
Copy pathforward-pass.ts
File metadata and controls
94 lines (82 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Vec4 } from '../../../core';
import { ClearFlagBit, Format } from '../../../gfx';
import { Camera, ShadowType, SkyBoxFlagValue } from '../../../render-scene/scene';
import { LightInfo, QueueHint, SceneFlags } from '../../custom/types';
import { getCameraUniqueID } from '../../custom/define';
import { Pipeline } from '../../custom/pipeline';
import { passContext } from '../utils/pass-context';
import { BasePass, getRTFormatBeforeToneMapping, getShadowMapSampler } from './base-pass';
import { ShadowPass } from './shadow-pass';
export class ForwardPass extends BasePass {
name = 'ForwardPass';
outputNames = ['ForwardColor', 'ForwardDS'];
enableInAllEditorCamera = true;
depthBufferShadingScale = 1;
calcDepthSlot (camera: Camera): void {
const depthSlotName = !!passContext.depthSlotName;
let canUsePrevDepth = !(camera.clearFlag & ClearFlagBit.DEPTH_STENCIL);
canUsePrevDepth = canUsePrevDepth && passContext.shadingScale === this.depthBufferShadingScale;
if (canUsePrevDepth) {
if (!depthSlotName) passContext.depthSlotName = super.slotName(camera, 1);
return;
}
this.depthBufferShadingScale = passContext.shadingScale;
passContext.depthSlotName = super.slotName(camera, 1);
}
slotName (camera: Camera, index = 0): string {
if (index === 1) {
return passContext.depthSlotName;
}
return super.slotName(camera, index);
}
public render (camera: Camera, ppl: Pipeline): void {
passContext.clearFlag = ClearFlagBit.COLOR | (camera.clearFlag & ClearFlagBit.DEPTH_STENCIL) | (camera.clearFlag & SkyBoxFlagValue.VALUE);
Vec4.set(passContext.clearColor, 0, 0, 0, 0);
Vec4.set(passContext.clearDepthColor, camera.clearDepth, camera.clearStencil, 0, 0);
this.calcDepthSlot(camera);
const slot0 = this.slotName(camera, 0);
const slot1 = this.slotName(camera, 1);
const cameraID = getCameraUniqueID(camera);
const isOffScreen = true;
passContext
.updatePassViewPort()
.addRenderPass('default', `${this.name}_${cameraID}`)
.addRasterView(slot0, getRTFormatBeforeToneMapping(ppl), isOffScreen)
.addRasterView(slot1, Format.DEPTH_STENCIL, isOffScreen)
.version();
const pass = passContext.pass!;
const shadowPass = passContext.shadowPass as ShadowPass;
if (shadowPass) {
for (const dirShadowName of shadowPass.mainLightShadows) {
if (ppl.containsResource(dirShadowName)) {
pass.addTexture(dirShadowName, 'cc_shadowMap', getShadowMapSampler());
}
}
for (const spotShadowName of shadowPass.spotLightShadows) {
if (ppl.containsResource(spotShadowName)) {
pass.addTexture(spotShadowName, 'cc_spotShadowMap', getShadowMapSampler());
}
}
}
const forwardQueue = pass.addQueue(QueueHint.RENDER_OPAQUE);
forwardQueue.addSceneOfCamera(
camera,
new LightInfo(),
SceneFlags.OPAQUE_OBJECT | SceneFlags.CUTOUT_OBJECT
| SceneFlags.GEOMETRY,
);
const forwardAddQueue = pass.addQueue(QueueHint.RENDER_TRANSPARENT, 'forward-add');
passContext.addSceneLights(forwardAddQueue, camera);
const shadowInfo = ppl.pipelineSceneData.shadows;
if (camera.scene?.mainLight && shadowInfo.enabled && shadowInfo.type === ShadowType.Planar) {
pass.addQueue(QueueHint.RENDER_OPAQUE, 'planar-shadow')
.addSceneOfCamera(
camera,
new LightInfo(camera.scene?.mainLight),
SceneFlags.SHADOW_CASTER | SceneFlags.PLANAR_SHADOW
| SceneFlags.OPAQUE_OBJECT | SceneFlags.CUTOUT_OBJECT,
);
}
passContext.forwardPass = this;
}
}