Canvas/Image Manipulator problem

For questions about using Classic.

Post » Sat Jun 23, 2012 11:20 pm

Slightly related to my previous issue...

I have a Sprite from which I need to sample four color values from four different locations and paste them into an Array in the same cycle. To do that, I create a very small "capture" Canvas and loop through all the locations, moving the small canvas, pasting the Sprite onto it, copying the Canvas into an Image Manipulator and finally getting the Array value using Get R/G/B form the manipulator...

The problem is, Image Manipulator only seems to catch the last color value. All the other steps execute properly, except for this particular one... Does anyone have any idea why this is happening? And is there a workaround?

Here's a .cap that shows the problem:

http://www.sendspace.com/file/b636gt

Thanks in advance.
B
8
S
2
G
2
Posts: 85
Reputation: 1,218

Post » Sun Jun 24, 2012 12:42 am

Transferring from the graphics card's VRAM to RAM needs 1 tick. So you have to delay the copying to the image manipulator by 1 tick each.

Here's your changed cap: ImgManip_Canvas.cap

You could also work with functions and call them delayed. I decided not to use them, because you can only delay a function in milliseconds, but you never know exactly how long a tick lasts. To avoid future issues with a function call coming too early or too late, I made it tickbased.

EDIT: Wrong file linked. Corrected.tulamide2012-06-24 00:54:31
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Jun 24, 2012 2:18 pm

Thanks for the sample file.
I was affraid it was the GPU-CPU data transfer...

Unfortunately, I can't delay the color data collection by a tick, as the number of points to be sampled varies and the sampled data is used to construct just a portion of the final rendered frame.

To give a bit more info, the colors are sampled from a depth pass of a scene and determine if a "light locator" (just a uniformly colored Sprite) is occluded by other objects - if the sample indicates it's not - draw a lens flare, if it is - do nothing and iterate to the next locator.

Since I've posted, I came up with a more crude way of getting this "occlusion" data - the Capture Canvas still gets a part of the depth pass at the Light Locator coordinates, the lens flare is always drawn, but then the Capture Canvas gets stretched to fit the entire screen and is multiplied over the flare - non-occluded Capture Canvasses will be white, giving no change, while occluded ones will be black - blacking out the flare.
It's an extra set of drawing and pasting instrucions, but so far performance doesn't suffer. I just waste 2MB of VRAM for the fullscreen flare Canvas.

Thanks for your help.
B
8
S
2
G
2
Posts: 85
Reputation: 1,218

Post » Sun Jun 24, 2012 8:00 pm

Here is a way to check to see if a sprite is occluded by using only collisions.
http://dl.dropbox.com/u/5426011/examples12/lensflare.cap

- The flare has a point collision and is used to check every pixel of the det sprite to see if it's visible using ZIndex and collision.
- The Sprite events can be replaced by a family to handle more objects.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon Jun 25, 2012 7:18 pm

Thank you for the example file - yes, I know of point/per-pixel overlap tests.

What I failed to mention is that I'm detecting occlusion in an environment comprising of 3dObjects and Sprites with displacement - overlap tests won't work on these, due to the collision masks not being accurate/updated...

The Image Manipulator color picking was supposed to allow me to skip the flare drawing routine in case of occlusion, instead of drawing it and masking it over...
B
8
S
2
G
2
Posts: 85
Reputation: 1,218


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests