8000 In Cocos Creator with CRP, is it possible to render specific objects into a RenderTexture after the forward pass but before post-processing? · Issue #18711 · cocos/cocos-engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

In Cocos Creator with CRP, is it possible to render specific objects into a RenderTexture after the forward pass but before post-processing? #18711

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

Open
whaqzhzd opened this issue May 13, 2025 · 0 comments

Comments

@whaqzhzd
Copy link
Contributor
whaqzhzd commented May 13, 2025

I have previously discussed this topic with Hyde Zhou on the Cocos forum, but I’d like to document it more formally here for future reference and potential feature consideration.

First, I have already implemented the following code:

 windowResize(
        ppl: rendering.BasicPipeline,
        pplConfigs: Readonly<PipelineConfigs>,
        cameraConfigs: Readonly<CameraConfigs & PickPassConfigs>,
        window: renderer.RenderWindow): void {
        const id = window.renderWindowId;
        if (cameraConfigs.enablePickOutliner) {
            const rtColorName = `PickRT${id}`;
            const rtDepthStencilName = `PickDS${id}`;

            ppl.addRenderTarget(rtColorName,
                cameraConfigs.radianceFormat,
                cameraConfigs.width,
                cameraConfigs.height);

            ppl.addDepthStencil(rtDepthStencilName,
                Format.DEPTH_STENCIL,
                cameraConfigs.width,
                cameraConfigs.height);
        }
    }
    setup(
        ppl: rendering.BasicPipeline,
        pplConfigs: Readonly<PipelineConfigs>,
        cameraConfigs: CameraConfigs & Readonly<PickPassConfigs>,
        camera: renderer.scene.Camera,
        context: PipelineContext,
        prevRenderPass?: rendering.BasicRenderPassBuilder): rendering.BasicRenderPassBuilder | undefined {
        if (!cameraConfigs.enablePickOutliner) {
            return prevRenderPass;
        }
        --cameraConfigs.remainingPasses;

        assert(!!this._material);

        const id = camera.window.renderWindowId;
        const rtColorName = `PickRT${id}`; 
        const rtDepthStencilName = `PickDS${id}`; 

        const renderPass = ppl.addRenderPass(cameraConfigs.width, cameraConfigs.height, "default");
        renderPass.name = "PickRTPass";
        renderPass.addRenderTarget(rtColorName, LoadOp.CLEAR, StoreOp.STORE, sClearColorTransparentBlack); 
        renderPass.addDepthStencil(
            rtDepthStencilName, 
            LoadOp.CLEAR,       
            StoreOp.DISCARD,      
            camera.clearDepth,
            camera.clearStencil,
            ClearFlagBit.DEPTH_STENCIL,
        );

        renderPass
            .addQueue(QueueHint.OPAQUE)
            .addScene(camera, SceneFlags.OPAQUE);

        const copyPass = ppl.addRenderPass(cameraConfigs.width, cameraConfigs.height, 'pick-pass');
        copyPass.addRenderTarget(cameraConfigs.colorName, LoadOp.CLEAR, StoreOp.STORE, sClearColorTransparentBlack);
        copyPass.addTexture(context.colorName, 'mainTexture');
        copyPass.addTexture(rtColorName, 'inputTexture');
        copyPass.setVec4('g_platform', pplConfigs.platform);
        copyPass
            .addQueue(rendering.QueueHint.OPAQUE)
            .addCameraQuad(camera, this._material!, 0);

        return copyPass; 
    }

But the problem is, I don't know how to use filtering to render only the objects I want! All of my objects use the same uber shader. I select them in the scene and get a list of them. So what should I do next?

It would be ideal if there were an API like ppl.addRenderPass(cameraConfigs.width, cameraConfigs.height, array<model>, passName); or something similar, because I already have the list of models. I don't need to loop through them again using a filter like:

for (const model of scene.models) {
    // do something or filter
}

Or something like:

renderPass
    .addQueue(QueueHint.OPAQUE)
    .addScene(camera, SceneFlags.OPAQUE)
    .addModel(array<model>, passId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0