Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Added] new pipeline setter's light interface #175

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 186 additions & 27 deletions cocos/rendering/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@
const block: string = this._currBlock;
const nodeId = this._lg.locateChild(0xFFFFFFFF, this._currStage);
const ppl = this._lg.getLayout(nodeId);
const layout = ppl.descriptorSets.get(UpdateFrequency.PER_PASS)!.descriptorSetLayoutData;
const layout = ppl.descriptorSets.get(this._currFrequency)!.descriptorSetLayoutData;
const nameID: number = this._lg.attributeIndex.get(block)!;
return layout.uniformBlocks.get(nameID);
}

protected _getCurrDescSetLayoutData (): DescriptorSetLayoutData {
const nodeId = this._lg.locateChild(0xFFFFFFFF, this._currStage);
const ppl = this._lg.getLayout(nodeId);
const layout = ppl.descriptorSets.get(UpdateFrequency.PER_PASS)!.descriptorSetLayoutData;
const layout = ppl.descriptorSets.get(this._currFrequency)!.descriptorSetLayoutData;
return layout;
}

Expand All @@ -249,9 +249,10 @@
return -1;
}

setCurrConstant (block: string, stage = 'default'): boolean {
setCurrConstant (block: string, stage = 'default', frequency: UpdateFrequency = UpdateFrequency.PER_PASS): boolean {
this._currBlock = block;
this._currStage = stage;
this._currFrequency = frequency;
const nameID: number = this._lg.attributeIndex.get(block)!;
this._currCount = 0;
const currBlock = this._getCurrUniformBlock();
Expand All @@ -267,9 +268,10 @@
return this._currConstant;
}

public addConstant (block: string, stage = 'default'): boolean {
public addConstant (block: string, stage = 'default', frequency: UpdateFrequency = UpdateFrequency.PER_PASS): boolean {
this._currBlock = block;
this._currStage = stage;
this._currFrequency = frequency;
const num = this._lg.attributeIndex.get(block)!;
this._currCount = 0;
const currBlock = this._getCurrUniformBlock();
Expand Down Expand Up @@ -347,32 +349,195 @@
const num = this._lg.attributeIndex.get(name)!;
this._data.samplers.set(num, sampler);
}

public getParentLayout (): string {
const director = cclegacy.director;
const root = director.root;
const pipeline = root.pipeline as WebPipeline;
const parId = pipeline.renderGraph!.getParent(this._vertID);
const layoutName = pipeline.renderGraph!.getLayout(parId);
return layoutName;
}

public getCurrentLayout (): string {
const director = cclegacy.director;
const root = director.root;
const pipeline = root.pipeline as WebPipeline;
const layoutName = pipeline.renderGraph!.getLayout(this._vertID);
return layoutName;
}

public setBuiltinCameraConstants (camera: Camera): void {
// TODO
const director = cclegacy.director;
const root = director.root;
const pipeline = root.pipeline as WebPipeline;
const layoutName = this.getParentLayout();
setCameraUBOValues(this, camera, pipeline.pipelineSceneData, camera.scene, layoutName);
}
public setBuiltinShadowMapConstants (light: Light, numLevels?: number): void {
// TODO
setShadowUBOView(this, null, this.getParentLayout());
}
public setBuiltinDirectionalLightFrustumConstants (camera: Camera, light: DirectionalLight, csmLevel = 0): void {
setShadowUBOLightView(this, camera, light, csmLevel);
}
public setBuiltinSpotLightFrustumConstants (light: SpotLight): void {
// TODO
setShadowUBOLightView(this, null, light, 0);
}
public setBuiltinDirectionalLightConstants (light: DirectionalLight, camera: Camera): void {
// TODO
}
public setBuiltinSphereLightConstants (light: SphereLight, camera: Camera): void {
// TODO
const director = cclegacy.director;
const pipeline = (director.root as Root).pipeline;
const sceneData = pipeline.pipelineSceneData;
if (!this.addConstant('CCForwardLight', this.getParentLayout(), UpdateFrequency.PER_BATCH)) return;
uniformOffset = this.getUniformOffset('cc_lightPos', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.position.x, light.position.y, light.position.z, LightType.SPHERE);
this.offsetVec4(_uboVec, uniformOffset);
}
uniformOffset = this.getUniformOffset('cc_lightSizeRangeAngle', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.size, light.range, 0.0, 0.0);
this.offsetVec4(_uboVec, uniformOffset);
}
const isHDR = sceneData.isHDR;
const lightMeterScale = 10000.0;
uniformOffset = this.getUniformOffset('cc_lightColor', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.color.x, light.color.y, light.color.z, 0);
if (light.useColorTemperature) {
const finalColor = light.finalColor;
_uboVec.x = finalColor.x;
_uboVec.y = finalColor.y;
_uboVec.z = finalColor.z;
}
if (isHDR) {
_uboVec.w = (light).luminance * camera.exposure * lightMeterScale;
} else {
_uboVec.w = (light).luminance;
}
this.offsetVec4(_uboVec, uniformOffset);
}
}
public setBuiltinSpotLightConstants (light: SpotLight, camera: Camera): void {
// TODO
const director = cclegacy.director;
const pipeline = (director.root as Root).pipeline;
const sceneData = pipeline.pipelineSceneData;

const shadowInfo = sceneData.shadows;
if (!this.addConstant('CCForwardLight', this.getParentLayout(), UpdateFrequency.PER_BATCH)) return;
uniformOffset = this.getUniformOffset('cc_lightPos', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.position.x, light.position.y, light.position.z, LightType.SPOT);
this.offsetVec4(_uboVec, uniformOffset);
}
uniformOffset = this.getUniformOffset('cc_lightSizeRangeAngle', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.size, light.range, light.spotAngle, (shadowInfo.enabled && light.shadowEnabled && shadowInfo.type === ShadowType.ShadowMap) ? 1 : 0);
this.offsetVec4(_uboVec, uniformOffset);
}
uniformOffset = this.getUniformOffset('cc_lightDir', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.direction.x, light.direction.y, light.direction.z, 0);
this.offsetVec4(_uboVec, uniformOffset);
}
const isHDR = sceneData.isHDR;
const lightMeterScale = 10000.0;
uniformOffset = this.getUniformOffset('cc_lightColor', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.color.x, light.color.y, light.color.z, 0);
if (light.useColorTemperature) {
const finalColor = light.finalColor;
_uboVec.x = finalColor.x;
_uboVec.y = finalColor.y;
_uboVec.z = finalColor.z;
}
if (isHDR) {
_uboVec.w = (light).luminance * camera.exposure * lightMeterScale;
} else {
_uboVec.w = (light).luminance;
}
this.offsetVec4(_uboVec, uniformOffset);
}
}
public setBuiltinPointLightConstants (light: PointLight, camera: Camera): void {
// TODO
const director = cclegacy.director;
const pipeline = (director.root as Root).pipeline;
const sceneData = pipeline.pipelineSceneData;
if (!this.addConstant('CCForwardLight', this.getParentLayout(), UpdateFrequency.PER_BATCH)) return;
uniformOffset = this.getUniformOffset('cc_lightPos', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.position.x, light.position.y, light.position.z, LightType.POINT);
this.offsetVec4(_uboVec, uniformOffset);
}
uniformOffset = this.getUniformOffset('cc_lightSizeRangeAngle', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(0.0, light.range, 0.0, 0.0);
this.offsetVec4(_uboVec, uniformOffset);
}
const isHDR = sceneData.isHDR;
const lightMeterScale = 10000.0;
uniformOffset = this.getUniformOffset('cc_lightColor', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.color.x, light.color.y, light.color.z, 0);
if (light.useColorTemperature) {
const finalColor = light.finalColor;
_uboVec.x = finalColor.x;
_uboVec.y = finalColor.y;
_uboVec.z = finalColor.z;
}
if (isHDR) {
_uboVec.w = (light).luminance * camera.exposure * lightMeterScale;
} else {
_uboVec.w = (light).luminance;
}
this.offsetVec4(_uboVec, uniformOffset);
}
}
public setBuiltinRangedDirectionalLightConstants (light: RangedDirectionalLight, camera: Camera): void {
// TODO
const director = cclegacy.director;
const pipeline = (director.root as Root).pipeline;
const sceneData = pipeline.pipelineSceneData;
if (!this.addConstant('CCForwardLight', this.getParentLayout(), UpdateFrequency.PER_BATCH)) return;
uniformOffset = this.getUniformOffset('cc_lightPos', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.position.x, light.position.y, light.position.z, LightType.RANGED_DIRECTIONAL);
this.offsetVec4(_uboVec, uniformOffset);
}
uniformOffset = this.getUniformOffset('cc_lightSizeRangeAngle', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.right.x, light.right.y, light.right.z, 0.0);
this.offsetVec4(_uboVec, uniformOffset);
}
uniformOffset = this.getUniformOffset('cc_lightDir', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.direction.x, light.direction.y, light.direction.z, 0);
this.offsetVec4(_uboVec, uniformOffset);
}
uniformOffset = this.getUniformOffset('cc_lightBoundingSizeVS', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
const scale = light.scale;
_uboVec.set(scale.x * 0.5, scale.y * 0.5, scale.z * 0.5, 0);
this.offsetVec4(_uboVec, uniformOffset);
}
const isHDR = sceneData.isHDR;
uniformOffset = this.getUniformOffset('cc_lightColor', Type.FLOAT4);
if (this.hasUniform(uniformOffset)) {
_uboVec.set(light.color.x, light.color.y, light.color.z, 0);
if (light.useColorTemperature) {
const finalColor = light.finalColor;
_uboVec.x = finalColor.x;
_uboVec.y = finalColor.y;
_uboVec.z = finalColor.z;
}
if (isHDR) {
_uboVec.w = light.illuminance * camera.exposure;
} else {
_uboVec.w = light.illuminance;
}
this.offsetVec4(_uboVec, uniformOffset);
}
}
public hasSampler (name: string): boolean {
const id = this._lg.attributeIndex.get(name);
Expand All @@ -395,15 +560,17 @@
// protected
protected _data: RenderData;
protected _lg: LayoutGraphData;
protected _vertID: number = -1;
protected _currBlock;
protected _currStage: string = '';
protected _currFrequency: UpdateFrequency = UpdateFrequency.PER_PASS;
protected _currCount;
protected _currConstant: number[] = [];
}

function setShadowUBOLightView (
setter: WebSetter,
camera: Camera,
camera: Camera | null,
light: Light,
csmLevel: number,
layout = 'default',
Expand All @@ -426,8 +593,8 @@
if (shadowInfo.enabled) {
if (shadowInfo.type === ShadowType.ShadowMap) {
// update CSM layers
if (light && light.node) {
csmLayers.update(sceneData, camera);
if (light && light.node && light.type === LightType.DIRECTIONAL) {
csmLayers.update(sceneData, camera!);
}
}
}
Expand Down Expand Up @@ -997,7 +1164,7 @@
const queueId = this._renderGraph.getParent(this._sceneId);
const passId = this._renderGraph.getParent(queueId);
const layoutName = this._renderGraph.getLayout(passId);
setShadowUBOLightView(this, this._scene.camera!, light, csmLevel, layoutName);
setShadowUBOLightView(this, this._scene.camera, light, csmLevel, layoutName);
}
private _renderGraph: RenderGraph;
private _scene: SceneData;
Expand Down Expand Up @@ -1031,16 +1198,10 @@
this._renderGraph.setName(this._vertID, name);
}

getLayoutName (): string {
const parId = this._renderGraph.getParent(this._vertID);
const layoutName = this._renderGraph.getLayout(parId);
return layoutName;
}

addSceneOfCamera (camera: Camera, light: LightInfo, sceneFlags = SceneFlags.NONE, name = 'Camera'): void {
const sceneData = renderGraphPool.createSceneData(camera.scene, camera, sceneFlags, CullingFlags.NONE, light.light);
this._renderGraph.addVertex<RenderGraphValue.Scene>(RenderGraphValue.Scene, sceneData, name, '', renderGraphPool.createRenderData(), false, this._vertID);
const layoutName = this.getLayoutName();
const layoutName = this.getParentLayout();
const scene: Scene = cclegacy.director.getScene();
setCameraUBOValues(
this,
Expand All @@ -1065,7 +1226,7 @@
const renderData = renderGraphPool.createRenderData();
const sceneId = this._renderGraph.addVertex<RenderGraphValue.Scene>(RenderGraphValue.Scene, sceneData, 'Scene', '', renderData, false, this._vertID);
if (!(sceneFlags & SceneFlags.NON_BUILTIN)) {
const layoutName = this.getLayoutName();
const layoutName = this.getParentLayout();
setCameraUBOValues(
this,
camera,
Expand All @@ -1091,7 +1252,7 @@
false,
this._vertID,
);
const layoutName = this.getLayoutName();
const layoutName = this.getParentLayout();
const scene: Scene | null = cclegacy.director.getScene();
setCameraUBOValues(
this,
Expand All @@ -1118,7 +1279,7 @@
false,
this._vertID,
);
const layoutName = this.getLayoutName();
const layoutName = this.getParentLayout();
const scene: Scene = cclegacy.director.getScene();
setCameraUBOValues(
this,
Expand Down Expand Up @@ -1156,12 +1317,11 @@
throw new Error('Method not implemented.');
}
private _renderGraph: RenderGraph;
private _vertID: number;
private _queue: RenderQueue;
private _pipeline: PipelineSceneData;
}

export class WebRenderSubpassBuilder extends WebSetter implements RenderSubpassBuilder {

Check failure on line 1324 in cocos/rendering/custom/web-pipeline.ts

View workflow job for this annotation

GitHub Actions / npm_test

Class 'WebRenderSubpassBuilder' incorrectly extends base class 'WebSetter'.
constructor (
data: RenderData,
renderGraph: RenderGraph,
Expand Down Expand Up @@ -1246,7 +1406,6 @@
set showStatistics (enable: boolean) {
this._subpass.showStatistics = enable;
}

private _renderGraph: RenderGraph;
private _vertID: number;
private _layoutID: number;
Expand All @@ -1254,7 +1413,7 @@
private _pipeline: PipelineSceneData;
}

export class WebRenderPassBuilder extends WebSetter implements BasicMultisampleRenderPassBuilder {

Check failure on line 1416 in cocos/rendering/custom/web-pipeline.ts

View workflow job for this annotation

GitHub Actions / npm_test

Class 'WebRenderPassBuilder' incorrectly extends base class 'WebSetter'.
constructor (data: RenderData, renderGraph: RenderGraph, layoutGraph: LayoutGraphData, resourceGraph: ResourceGraph, vertID: number, pass: RasterPass, pipeline: PipelineSceneData) {
super(data, layoutGraph);
this._renderGraph = renderGraph;
Expand Down Expand Up @@ -1453,7 +1612,7 @@
private _resourceGraph: ResourceGraph;
}

export class WebComputeQueueBuilder extends WebSetter implements ComputeQueueBuilder {

Check failure on line 1615 in cocos/rendering/custom/web-pipeline.ts

View workflow job for this annotation

GitHub Actions / npm_test

Class 'WebComputeQueueBuilder' incorrectly extends base class 'WebSetter'.
constructor (data: RenderData, renderGraph: RenderGraph, layoutGraph: LayoutGraphData, vertID: number, queue: RenderQueue, pipeline: PipelineSceneData) {
super(data, layoutGraph);
this._renderGraph = renderGraph;
Expand Down Expand Up @@ -1506,7 +1665,7 @@
private _pipeline: PipelineSceneData;
}

export class WebComputePassBuilder extends WebSetter implements ComputePassBuilder {

Check failure on line 1668 in cocos/rendering/custom/web-pipeline.ts

View workflow job for this annotation

GitHub Actions / npm_test

Class 'WebComputePassBuilder' incorrectly extends base class 'WebSetter'.
constructor (data: RenderData, renderGraph: RenderGraph, layoutGraph: LayoutGraphData, resourceGraph: ResourceGraph, vertID: number, pass: ComputePass, pipeline: PipelineSceneData) {
super(data, layoutGraph);
this._renderGraph = renderGraph;
Expand Down Expand Up @@ -1833,7 +1992,7 @@
const vertID = this._renderGraph!.addVertex<RenderGraphValue.Compute>(RenderGraphValue.Compute, pass, name, passName, data, false);
const result = pipelinePool.computePassBuilder.add();
result.update(data, this._renderGraph!, this._layoutGraph, this._resourceGraph, vertID, pass, this._pipelineSceneData);
setComputeConstants(result, passName);

Check failure on line 1995 in cocos/rendering/custom/web-pipeline.ts

View workflow job for this annotation

GitHub Actions / npm_test

Argument of type 'WebComputePassBuilder' is not assignable to parameter of type 'WebSetter'.
initGlobalDescBinding(data, passName);
return result;
}
Expand Down Expand Up @@ -2325,7 +2484,7 @@
const vertID = this._renderGraph!.addVertex<RenderGraphValue.RasterPass>(RenderGraphValue.RasterPass, pass, name, layoutName, data, false);
const result = pipelinePool.renderPassBuilder.add();
result.update(data, this._renderGraph!, this._layoutGraph, this._resourceGraph, vertID, pass, this._pipelineSceneData);
this._updateRasterPassConstants(result, width, height, layoutName);

Check failure on line 2487 in cocos/rendering/custom/web-pipeline.ts

View workflow job for this annotation

GitHub Actions / npm_test

Argument of type 'WebRenderPassBuilder' is not assignable to parameter of type 'WebSetter'.
initGlobalDescBinding(data, layoutName);
return result;
}
Expand Down
Loading
Loading