diff --git a/NEW_RELEASE_NOTES.md b/NEW_RELEASE_NOTES.md index 4a1a9c7fa7..a4fbaa42e7 100644 --- a/NEW_RELEASE_NOTES.md +++ b/NEW_RELEASE_NOTES.md @@ -7,3 +7,5 @@ for next branch cut* header. appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md). ## Release notes for next branch cut + +- materials: picking is done in float (prepare for ES2) [⚠️ **New Material Version**] diff --git a/filament/src/PostProcessManager.cpp b/filament/src/PostProcessManager.cpp index 5a62ca68b5..477e494971 100644 --- a/filament/src/PostProcessManager.cpp +++ b/filament/src/PostProcessManager.cpp @@ -381,7 +381,7 @@ PostProcessManager::StructurePassOutput PostProcessManager::structure(FrameGraph if (config.picking) { data.picking = builder.createTexture("Picking Buffer", { .width = width, .height = height, - .format = TextureFormat::RG32UI }); + .format = TextureFormat::RG32F }); data.picking = builder.write(data.picking, FrameGraphTexture::Usage::COLOR_ATTACHMENT); diff --git a/filament/src/details/View.cpp b/filament/src/details/View.cpp index deb49e11f6..068cc8702e 100644 --- a/filament/src/details/View.cpp +++ b/filament/src/details/View.cpp @@ -968,13 +968,14 @@ void FView::executePickingQueries(backend::DriverApi& driver, const uint32_t x = uint32_t(float(pQuery->x) * (scale * mScale.x)); const uint32_t y = uint32_t(float(pQuery->y) * (scale * mScale.y)); driver.readPixels(handle, x, y, 1, 1, { - &pQuery->result.renderable, 4 * 4, // 4*uint - // FIXME: RGBA_INTEGER is guaranteed to work. R_INTEGER must be queried. - backend::PixelDataFormat::RG_INTEGER, backend::PixelDataType::UINT, + &pQuery->result.renderable, 4u * 4u, // 4*float + backend::PixelDataFormat::RG, backend::PixelDataType::FLOAT, pQuery->handler, [](void*, size_t, void* user) { FPickingQuery* pQuery = static_cast(user); + float const identity = *((float*)((char*)&pQuery->result.renderable)); + pQuery->result.renderable = Entity::import(identity); pQuery->result.fragCoords = { - pQuery->x, pQuery->y,float(1.0 - pQuery->result.depth) }; + pQuery->x, pQuery->y, float(1.0 - pQuery->result.depth) }; pQuery->callback(pQuery->result, pQuery); FPickingQuery::put(pQuery); }, pQuery diff --git a/shaders/src/depth_main.fs b/shaders/src/depth_main.fs index 5ed20a1efe..4b07679a32 100644 --- a/shaders/src/depth_main.fs +++ b/shaders/src/depth_main.fs @@ -1,7 +1,7 @@ #if defined(VARIANT_HAS_VSM) layout(location = 0) out vec4 fragColor; #elif defined(VARIANT_HAS_PICKING) -layout(location = 0) out highp uint2 outPicking; +layout(location = 0) out highp vec2 outPicking; #else // not color output #endif @@ -49,8 +49,8 @@ void main() { fragColor.xy = computeDepthMomentsVSM(depth); fragColor.zw = computeDepthMomentsVSM(-1.0 / depth); // requires at least RGBA16F #elif defined(VARIANT_HAS_PICKING) - outPicking.x = uint(object_uniforms.objectId); - outPicking.y = floatBitsToUint(vertex_position.z / vertex_position.w); + outPicking.x = float(object_uniforms.objectId); + outPicking.y = vertex_position.z / vertex_position.w; #else // that's it #endif