Skip to content

Commit

Permalink
change picking to use floats (#6747)
Browse files Browse the repository at this point in the history
floats can have up to 16.7M unique integers which is enough for encoding
an Entity. 
This change will help a later one that adds support for ES2
  • Loading branch information
pixelflinger committed Apr 19, 2023
1 parent 29d5ae6 commit ebb0752
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEW_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**]
2 changes: 1 addition & 1 deletion filament/src/PostProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions filament/src/details/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FPickingQuery*>(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
Expand Down
6 changes: 3 additions & 3 deletions shaders/src/depth_main.fs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ebb0752

Please sign in to comment.