Skip to content

Commit

Permalink
Add ->(geometry, profiler, planarShadow) and update shadowmap (#45) (#…
Browse files Browse the repository at this point in the history
…12129)

Co-authored-by: GengineJS <476393671@qq.com>
  • Loading branch information
star-e and GengineJS committed Jul 21, 2022
1 parent fc4f024 commit f76a30d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
15 changes: 10 additions & 5 deletions cocos/core/pipeline/custom/builtin-pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export function buildShadowPasses (cameraName: string, camera: Camera, ppl: Pipe
buildShadowPass(cameraInfo.mainLightShadowNames[0], ppl,
camera, mainLight, 0, mapWidth, mapHeight);
} else {
for (let i = 0; i < mainLight.csmLevel; i++) {
const csmLevel = pipeline.pipelineSceneData.csmSupported ? mainLight.csmLevel : 1;
for (let i = 0; i < csmLevel; i++) {
cameraInfo.mainLightShadowNames[i] = `MainLightShadow${cameraName}`;
buildShadowPass(cameraInfo.mainLightShadowNames[i], ppl,
camera, mainLight, i, mapWidth, mapHeight);
Expand Down Expand Up @@ -209,10 +210,12 @@ export class ForwardPipelineBuilder extends PipelineBuilder {
forwardPass.addRasterView(forwardPassDSName, passDSView);
forwardPass
.addQueue(QueueHint.RENDER_OPAQUE)
.addSceneOfCamera(camera, new LightInfo(), SceneFlags.OPAQUE_OBJECT | SceneFlags.CUTOUT_OBJECT | SceneFlags.DEFAULT_LIGHTING);
.addSceneOfCamera(camera, new LightInfo(),
SceneFlags.OPAQUE_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.CUTOUT_OBJECT
| SceneFlags.PLANAR_SHADOW | SceneFlags.DEFAULT_LIGHTING);
forwardPass
.addQueue(QueueHint.RENDER_TRANSPARENT)
.addSceneOfCamera(camera, new LightInfo(), SceneFlags.TRANSPARENT_OBJECT | SceneFlags.UI);
.addSceneOfCamera(camera, new LightInfo(), SceneFlags.TRANSPARENT_OBJECT | SceneFlags.UI | SceneFlags.GEOMETRY | SceneFlags.PROFILER);
}
}
}
Expand Down Expand Up @@ -406,7 +409,8 @@ export class DeferredPipelineBuilder extends PipelineBuilder {
camera, this._deferredData._deferredLightingMaterial,
SceneFlags.VOLUMETRIC_LIGHTING,
);
lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(), SceneFlags.TRANSPARENT_OBJECT);
lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(),
SceneFlags.TRANSPARENT_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.GEOMETRY);
// Postprocess
const postprocessPassRTName = `postprocessPassRTName${cameraID}`;
const postprocessPassDS = `postprocessPassDS${cameraID}`;
Expand Down Expand Up @@ -441,7 +445,8 @@ export class DeferredPipelineBuilder extends PipelineBuilder {
postprocessPass.addRasterView(postprocessPassRTName, postprocessPassView);
postprocessPass.addRasterView(postprocessPassDS, postprocessPassDSView);
postprocessPass.addQueue(QueueHint.NONE).addFullscreenQuad(this._deferredData._deferredPostMaterial, SceneFlags.NONE);
postprocessPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(), SceneFlags.UI);
postprocessPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(),
SceneFlags.UI | SceneFlags.PROFILER);
}
}
readonly _deferredData = new DeferredData();
Expand Down
33 changes: 31 additions & 2 deletions cocos/core/pipeline/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import { WebSceneVisitor } from './web-scene-visitor';
import { stringify, parse } from './utils';
import { RenderAdditiveLightQueue } from '../render-additive-light-queue';
import { RenderShadowMapBatchedQueue } from '../render-shadow-map-batched-queue';
import { renderProfiler } from '../pipeline-funcs';
import { PlanarShadowQueue } from '../planar-shadow-queue';

class DeviceResource {
protected _context: ExecutorContext;
Expand Down Expand Up @@ -451,6 +453,7 @@ class SubmitInfo {
public batches = new Set<BatchedBuffer>();
public opaqueList: RenderInfo[] = [];
public transparentList: RenderInfo[] = [];
public planarQueue: PlanarShadowQueue | null = null;
public shadowMap: RenderShadowMapBatchedQueue | null = null;
public additiveLight: RenderAdditiveLightQueue | null = null;
}
Expand Down Expand Up @@ -826,11 +829,15 @@ class DevicePreSceneTask extends WebSceneTask {
}
}
}
const pipeline = this._currentQueue.devicePass.context.pipeline;
if (sceneFlag & SceneFlags.DEFAULT_LIGHTING) {
const pipeline = this._currentQueue.devicePass.context.pipeline;
this._submitInfo.additiveLight = new RenderAdditiveLightQueue(pipeline);
this._submitInfo.additiveLight.gatherLightPasses(this.camera, this._cmdBuff);
}
if (sceneFlag & SceneFlags.PLANAR_SHADOW) {
this._submitInfo.planarQueue = new PlanarShadowQueue(pipeline);
this._submitInfo.planarQueue.gatherShadowPasses(this.camera, this._cmdBuff);
}
this._submitInfo.opaqueList.sort(this._opaqueCompareFn);
this._submitInfo.transparentList.sort(this._transparentCompareFn);
}
Expand Down Expand Up @@ -1125,8 +1132,20 @@ class DeviceSceneTask extends WebSceneTask {
this._renderPass,
devicePass.context.commandBuffer);
}

private _recordPlanarShadows () {
const devicePass = this._currentQueue.devicePass;
const submitMap = devicePass.submitMap;
const context = devicePass.context;
submitMap.get(this.camera!)?.planarQueue?.recordCommandBuffer(context.device,
this._renderPass,
devicePass.context.commandBuffer);
}

public submit () {
const area = this._generateRenderArea();
const devicePass = this._currentQueue.devicePass;
const context = devicePass.context;
if (!this._currentQueue.devicePass.viewport) {
this.visitor.setViewport(new Viewport(area.x, area.y, area.width, area.height));
this.visitor.setScissor(area);
Expand All @@ -1140,14 +1159,24 @@ class DeviceSceneTask extends WebSceneTask {
this._recordShadowMap();
return;
}
const graphSceneData = this.graphScene.scene!;
this._recordOpaqueList();
this._recordInstences();
this._recordBatches();
this._recordAdditiveLights();
this._recordPlanarShadows();
this._recordTransparentList();
if (this.graphScene.scene!.flags & SceneFlags.UI) {
if (graphSceneData.flags & SceneFlags.GEOMETRY) {
this.camera!.geometryRenderer?.render(devicePass.renderPass,
context.commandBuffer, context.pipeline.pipelineSceneData);
}
if (graphSceneData.flags & SceneFlags.UI) {
this._recordUI();
}
if (graphSceneData.flags & SceneFlags.PROFILER) {
renderProfiler(context.device, devicePass.renderPass,
context.commandBuffer, context.pipeline.profiler, this.camera!);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions cocos/core/pipeline/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { GeometryRenderer } from '../geometry-renderer';
import { Material } from '../../assets';
import { DeferredPipelineBuilder, ForwardPipelineBuilder } from './builtin-pipelines';
import { RenderGraphPrintVisitor } from './debug';
import { decideProfilerCamera } from '../pipeline-funcs';

export class WebSetter {
constructor (data: RenderData) {
Expand Down Expand Up @@ -427,6 +428,12 @@ export class WebPipeline extends Pipeline {
// 0: SHADOWMAP_LINER_DEPTH_OFF, 1: SHADOWMAP_LINER_DEPTH_ON.
const isLinear = this._device.gfxAPI === API.WEBGL ? 1 : 0;
this.setMacroInt('CC_SHADOWMAP_USE_LINEAR_DEPTH', isLinear);

// 0: UNIFORM_VECTORS_LESS_EQUAL_64, 1: UNIFORM_VECTORS_GREATER_EQUAL_125.
this.pipelineSceneData.csmSupported = this.device.capabilities.maxFragmentUniformVectors
>= (WebPipeline.CSM_UNIFORM_VECTORS + WebPipeline.GLOBAL_UNIFORM_VECTORS);
this.setMacroBool('CC_SUPPORT_CASCADED_SHADOW_MAP', this.pipelineSceneData.csmSupported);

const root = legacyCC.director.root;
// enable the deferred pipeline
if (root.useDeferredPipeline) {
Expand Down Expand Up @@ -638,6 +645,7 @@ export class WebPipeline extends Pipeline {
return;
}
this._applySize(cameras);
decideProfilerCamera(cameras);
// build graph
this.beginFrame();
if (this.builder) {
Expand Down Expand Up @@ -715,4 +723,8 @@ export class WebPipeline extends Pipeline {
private _forward!: ForwardPipelineBuilder;
private _deferred!: DeferredPipelineBuilder;
public builder: PipelineBuilder | null = null;
// csm uniform used vectors count
public static CSM_UNIFORM_VECTORS = 61;
// all global uniform used vectors count
public static GLOBAL_UNIFORM_VECTORS = 64;
}

0 comments on commit f76a30d

Please sign in to comment.