1

我想知道是否可以从 Qt3D 中的 FBO 读取数据?我有 2 个渲染通道,一个保存在纹理中,另一个渲染在屏幕上。我想从纹理中读取像素,但到目前为止我还没有运气。

将不胜感激任何输入!

编辑:这是阴影贴图示例中的 RenderSettings 对象的一些代码。我要做的是在 pass 之后读取 shadowmapTexture 的某个位置。例如,在某个 x,y 位置上单击鼠标后,读取同一 x,y 位置上的 Texture2D 的数据。

property alias viewCamera: viewCameraSelector.camera
property alias lightCamera: lightCameraSelector.camera
readonly property Texture2D shadowTexture: depthTexture

activeFrameGraph: Viewport {
    normalizedRect: Qt.rect(0.0, 0.0, 1.0, 1.0)

    RenderSurfaceSelector {
        RenderPassFilter {
            matchAny: [ FilterKey { name: "pass"; value: "shadowmap" } ]

           RenderTargetSelector {
                target: RenderTarget {
                    attachments: [
                        RenderTargetOutput {
                            objectName: "depth"
                            attachmentPoint: RenderTargetOutput.Depth
                            texture: Texture2D {
                                id: depthTexture
                                width: 1024
                                height: 1024
                                format: Texture.DepthFormat
                                generateMipMaps: false
                                magnificationFilter: Texture.Linear
                                minificationFilter: Texture.Linear
                                wrapMode {
                                    x: WrapMode.ClampToEdge
                                    y: WrapMode.ClampToEdge
                                }
                                comparisonFunction: Texture.CompareLessEqual
                                comparisonMode: Texture.CompareRefToTexture
                            }
                        }
                    ]
                }

                ClearBuffers {
                    buffers: ClearBuffers.DepthBuffer

                    CameraSelector {
                        id: lightCameraSelector
                    }
                }
            }
        }

        RenderPassFilter {
            matchAny: [ FilterKey { name: "pass"; value: "forward" } ]

            ClearBuffers {
                clearColor: Qt.rgba(0.0, 0.4, 0.7, 1.0)
                buffers: ClearBuffers.ColorDepthBuffer

                CameraSelector {
                    id: viewCameraSelector
                }
            }
        }
    }
}
4

1 回答 1

1

使用RayCasterScreenRayCaster 它为您提供本地位置和世界位置以及屏幕 x ,您可以 从 kdab 及其示例中查看此站点

RenderSettings{
    
    //all components that you need like viewport , InputSettings ,...
    
    ScreenRayCaster {
        id: screenRayCaster
        
        onHitsChanged: printHits("Screen hits", hits)
    }
}

MouseHandler {
    id: mouseHandler
    sourceDevice:  MouseDevice {}
    onReleased: { screenRayCaster.trigger(Qt.point(mouse.x, mouse.y)) }
}

function printHits(desc, hits) {
    console.log(desc, hits.length)
    for (var i=0; i<hits.length; i++) {
        console.log("  " + hits[i].entity.objectName, hits[i].distance,
                    hits[i].worldIntersection.x, hits[i].worldIntersection.y, hits[i].worldIntersection.z)
    }
}
于 2021-06-14T16:33:08.033 回答