<p>As a way to estimate screenspace density of a set of particles, I'm trying to do some splatting: render a circle of fixed radius around each particle, accumulating, to get a count of how many particles are within that radius of each point. If I could be confident that my count stayed under 256 then I could easily use the stencil buffer for this, but unfortunately it could be larger. My approach was to render to texture, using <code>R32UI</code> as the format for my buffer (since that's ostensibly guaranteed to be renderable), <code>UNSIGNED_INT</code> as the format, etc., then turn on blending with a blendfunc of (<code>ONE</code>, <code>ONE</code>) and render the value 1 to every pixel for each circle to try to accumulate. I assumed this would work because the spec seems to suggest that the integer values should be treated as 1/(2^32-1) for blending purposes, then converted back to integers for storage, but unfortunately the buffer doesn't seem to count past 1; even with multiple circles layered that's the value that shows up when I try to read the accumulated pixels. Is there another way of doing this counting, or am I barking up the wrong tree entirely?</p>

CC BY-SA 4.0
2024-09-12T11:14:19.350Z
There can be implicit conversions when reading and writing buffers so the details of how the reads and writes are being done matter.
pmw1234
CC BY-SA 4.0
2024-09-12T17:12:22.967Z
@pmw1234 What additional specific details would help here?
Steven Stadnicki
CC BY-SA 4.0
2024-09-12T18:55:51.783Z
Can you add code of the texture creation, the texture read (back to CPU), the fragment shader and texture binding to shader
Thomas
CC BY-SA 4.0
2024-09-16T08:10:33.500Z
Can you use blending in floating point buffers?
Dmitri Urbanowicz
<opengl><webgl><frame-buffer><stencil-buffer>
How can I accumulate past 256 in a framebuffer texture?
Steven Stadnicki
# How can I accumulate past 256 in a framebuffer texture?

(Asked by: username_0 on 2024-09-10)

As a way to estimate screenspace density of a set of particles, I'm trying to do some splatting: render a circle of fixed radius around each particle, accumulating, to get a count of how many particles are within that radius of each point. If I could be confident that my count stayed under 256 then I could easily use the stencil buffer for this, but unfortunately it could be larger. My approach was to render to texture, using `R32UI` as the format for my buffer (since that's ostensibly guaranteed to be renderable), `UNSIGNED_INT` as the format, etc., then turn on blending with a blendfunc of (`ONE`, `ONE`) and render the value 1 to every pixel for each circle to try to accumulate. I assumed this would work because the spec seems to suggest that the integer values should be treated as 1/(2^32-1) for blending purposes, then converted back to integers for storage, but unfortunately the buffer doesn't seem to count past 1; even with multiple circles layered that's the value that shows up when I try to read the accumulated pixels. Is there another way of doing this counting, or am I barking up the wrong tree entirely?

**Tags:** opengl, webgl, frame-buffer, stencil-buffer

> **Comments:**
> **username_1**: There can be implicit conversions when reading and writing buffers so the details of how the reads and writes are being done matter.  
> **username_0**: @username_1 What additional specific details would help here?  
> **username_2**: Can you add code of the texture creation, the texture read (back to CPU), the fragment shader and texture binding to shader  
> **username_3**: Can you use blending in floating point buffers?  

---

## 0 answers

