0

i wander how code a shader that output a texture T1 in which each texel store the coordinate of all pixels that are (for example) not black of a given texture T0.

oceanGermanique
  • 336
  • 3
  • 16
  • It's not clear what you're asking. It would be very trivial to build texture0 from texture1 using [this example code](https://webglfundamentals.org/webgl/lessons/webgl-2d-drawimage.html) and [rendering to a texture](https://webglfundamentals.org/webgl/lessons/webgl-render-to-texture.html) instead of the canvas as just one example of a way to do this. – gman Mar 07 '19 at 01:55
  • I still can't figure out what you're trying to do. If you want to use T1 to access T0 then `vec2 pixelCoord = texture2D(t1, someInput)).xy; vec4 colorFromT0 = texture2D(t0, (pixelCoord + .5) / t0Dimensions);` Of course in that case t1 needs to be a texture format that can store values > 1.0 or else you need to multiply by t1Dimensions; Note this is really just a variation of [this answer](https://stackoverflow.com/a/19719654/128511). Using data from one texture to look up data in another – gman Mar 07 '19 at 14:33
  • @gman, I would like to store the coordinates of pixels from tex0 in texture 1. The texture1 will serve as a data structure. In fact I have a particle engine that reads an image and turns it into animated points. This is done in webgl .... except the initialization phase ... – oceanGermanique Mar 08 '19 at 01:22

1 Answers1

0

It's a bit difficult to know if A,B,C in your question represent pixels or sub images. If you are trying to locate pixels with values and group them together. You can implement that as a variation of a pixel sort algorithm. There are many ways to do this but you can see e.g.

https://bl.ocks.org/zz85/cafa1b8b3098b5a40e918487422d47f6

or

https://timseverien.com/posts/2017-08-17-sorting-pixels-with-webgl/

which uses per frame odd-even pair-wise comparison.

visibleman
  • 3,175
  • 1
  • 14
  • 27