Pixel sampler

This forum is currently in read-only mode.
  • I may be blind, however I find myself unable to pick color and opacity values at the given location. Therefore I am requesting the following:

    An expression or object that allows reading the color and opacity values of a given object at specific coordinates.

    For example:

    GetRGB(TiledBackground,200x100) would return the color of pixel at 200x100 within the TiledBackground texture.

    GetOpacity, etc. would be helpful as well.

    The uses are many! In my specific case, height mapping. Make characters appear bigger on darker (higher) places and smaller on lighter (lower) places. But that is not the only use. There is Line of Sight etc.

    If this is an unrealistic feature request, however, my world won't be crushed. There is always another way.

  • That would open up a lot of possibilities, but to make the most of it, I think we'd need that ability to "PAINT" to that specific spot too.

    Sponge.

  • It's doable, but it would be extremely slow. The textures holding the colour and opacity data are on the graphics card. The event engine, which runs expressions and events, runs on the CPU. In order to retrieve a pixel, you'd have to stall the GPU rendering (because it works in parallel), and transfer a pixel from the GPU to CPU over a high latency bridge already bottlenecked with rendering commands. Basically, although it's possible, the system is not at all designed for it. I think there are much better ways to achieve it than relying on pixel data on textures. The expression you want would totally strangle performance and I bet we'd get lots of people complaining that it's slow.

  • I'd like to stress that.

    Painfully.

    Horribly.

    Mind boggingly slow.

    Which is why on 3D this kind of thing is done with shaders only, all on the GPU side.

  • I see your point. Well, in that case I will try a different solution... though a large array object is just as slow, as well.

  • You'd actually get much better performance with an array object even if it used a lot of memory, because it's immediately available to the CPU.

  • Is there anything that can be done with a shader?

  • digging deeper into the topic, what kind of solutions comes to your mind on how to simulate this idea? being able to detect color (even plain black/white) would be great in bulding a procedural generation system. this way the area is covered with two textures - one with the actul graphics and second black and white. so event X would take place only on Black or White part of the screen.

    i dont think a pixel detector is needed - this can be build on grid with pretefined W/H.

    like set grid 50/50 pix each box, and then "IF box is ALL BLACK then -> something.

    being able to set the grid parameters would be cool. imagine i set the grid on 100/100pix per box. thats +/- 10 on x and 7 box on Y at 1024/768 resolution. thats just 70 boxes to check. that would take much less memory usage and would work even better as pixel sampler.

    by being able to change the box w/h users could see for them self how high is the performence impact and adjuct the box parameters till it suits he's needs.

    dang, that would be awesome.

    EDIT:

    oh and sorry for necroposting. i just think this is a great idea and my post/method/idea enhances it greatly

  • You can do that yourself with an array object. Perhaps you don't understand the performance implication of even requesting a single pixel. The graphics card is rendering the last frame while the events of the next tick are processing, for maximum efficiency. If you request a pixel off the GPU, the CPU stops and waits doing absolutely nothing until the GPU completes rendering the entire frame from the previous tick, then you get your pixel, then the GPU waits, doing absolutely nothing, until the CPU finishes the current tick and issues the drawing commands for it. So by requesting a single pixel you've turned a highly efficient parallel execution system in to a slow stop-and-wait. If that nudges you over missing a V-sync point, you could literally see the framerate drop to half. For one pixel!

    It's a cool idea, but it's not technically possible to do it fast because hardware is not designed for that.

  • Ashley you havent understood what i wrote or i have formed my though not clearly.

    my idea is to not detect a singel pixel but a grid box , and each bos is made by many pixels

    for example: a window with resolution of 100 x 100 pixels would have 16 grid box (25/25 pix each)

    like with tiles where you can set the tile width and heigh.

  • I'm not sure I understand. How does that improve performance?

  • my idea is to not detect a singel pixel but a grid box , and each bos is made by many pixels

    for example: a window with resolution of 100 x 100 pixels would have 16 grid box (25/25 pix each)

    like with tiles where you can set the tile width and heigh.

    Grid box or not, you're transferring pixels. Just the act of looking up one pixel creates the slowdown.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't think you can get anything other than a single pixel. Even if you could detect a quadrant, what if there's more than one color within that group?

    You would need some sort of algorithm to get a mean, and that would undoubtedly slow it down even more.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)