Pixel sampler

New releases and general discussions.

Post » Wed Mar 04, 2009 6:46 pm

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. ;)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Mar 04, 2009 7:14 pm

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.
B
2
S
1
G
3
Posts: 105
Reputation: 1,310

Post » Wed Mar 04, 2009 8:23 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Thu Mar 05, 2009 3:44 am

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.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Thu Mar 05, 2009 8:08 am

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.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Mar 05, 2009 1:09 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Thu Mar 05, 2009 1:54 pm

Is there anything that can be done with a shader?
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Nov 23, 2010 2:42 pm

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
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Post » Tue Nov 23, 2010 2:56 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Tue Nov 23, 2010 8:37 pm

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.
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 0 guests