Ambient Occlusion?

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Fri Aug 28, 2009 10:13 pm

a soft drop shadow with alpha shapes instead of bounding box would be pretty
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Dec 06, 2009 7:45 pm

actually it can be done in 2d, i read up a bit on AO and it seems like it actually wouldnt be too hard to implement using events, but i need a clear example of what exactly ur going for with AO, because in 2d the lightsource can be from the viewsource or from a skylight. and getting the effect to look right largely depends on what you'd be trying to do
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Mon Dec 07, 2009 1:07 pm

The lightsource is surely the skylight. Well, the effect should be small, covering something like 48x48 and 64x64 (or more) size in pixels.. How can it be done using events?
I would like a very soft drop shadow as a post-rendering effect on the entire scene.
B
2
S
1
G
3
Posts: 193
Reputation: 1,486

Post » Mon Dec 07, 2009 8:58 pm

should be a fairly easy effect, although for softness you could run into sampling issues, just like blurs, since you're taking alpha into account you can't just do it with distances.

I can prolly whip it up as a mod of my blur plugins. Will give it a go later.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Dec 08, 2009 5:02 am

I'm hitting arithmetic instruction limits for PS2 when blurring the shadow with a 5x5 kernel.

Blurs should really be done in two passes :)
Since the kernel is symmetric, I'll try storing a quarter of it then doing each op four times.
with less taps it would be useless.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Dec 08, 2009 9:04 am

There's an instruction limit? O.o Wow, I didn't know.. Anyway thanks for your work :D

Edit: Construct needs multi-pass shaders :!:
B
2
S
1
G
3
Posts: 193
Reputation: 1,486

Post » Tue Dec 08, 2009 9:17 am

Couldn't you just use a regular off the shelf method for SSAO (screen space Ambient Occlusion), using copies of objects with depth maps on them (which basically look and behave like height maps), which would effectively make up for the lack of any genuine depth in a 2D world. Since SSAO in 3D games uses a depth map in the same way, which is why it's so much faster than real Ambient Occlusion.

I dunno, in theory it would work, because it's not doing anything that can't already be done.
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Tue Dec 08, 2009 6:20 pm

[quote="Madster":31y9cqxr]I'm hitting arithmetic instruction limits for PS2 when blurring the shadow with a 5x5 kernel.[/quote:31y9cqxr]
You can use PS 2.0a, which raises the instruction limit from, I think, 64 to 512. Just change this line:

[code:31y9cqxr]PixelShader = compile ps_2_0 EffectProcess();[/code:31y9cqxr]
to:

[code:31y9cqxr]PixelShader = compile ps_2_a EffectProcess();[/code:31y9cqxr]
Although, this has downsides, because not all PS 2.0 capable cards support 2.0a.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Wed Dec 09, 2009 3:26 am

I'd like to insist on how SSAO is pointless in 2D.
Allow me to explain:

SSAO is occlusion, independent from light sources, based on the depth difference between each pixel.

Construct is 2D (mostly). What's the depth difference within a sprite? Zero. Always. What if you want to have a heightmap with heights? well, then the depth difference will be always the same, since the normal never changes..... so, the occlusion will always look the same and you're better off baking it, EVEN IF YOU USE NORMAL MAPPING.

And if you layer one sprite on top of another? well that's why I suggest drop shadow.

I'll try upping the pixel shader version and see if it's enough. I'm bumping into a lot of limits there (registers too)
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Wed Dec 09, 2009 4:21 am

[quote="Madster":2fkr9f0o]I'd like to insist on how SSAO is pointless in 2D.
Allow me to explain:

SSAO is occlusion, independent from light sources, based on the depth difference between each pixel.

Construct is 2D (mostly). What's the depth difference within a sprite? Zero. Always. What if you want to have a heightmap with heights? well, then the depth difference will be always the same, since the normal never changes..... so, the occlusion will always look the same and you're better off baking it, EVEN IF YOU USE NORMAL MAPPING.

And if you layer one sprite on top of another? well that's why I suggest drop shadow.

I'll try upping the pixel shader version and see if it's enough. I'm bumping into a lot of limits there (registers too)[/quote:2fkr9f0o]

Wall of text warning ;)

SSAO is a 2D effect using a depth map, it's faster but less accurate than full Ambient Occlusion.

AO is a 3D effect and wont be seen in games for some time. It's faster than global illumination etc. But still too slow to be used in realtime.

Nothing displayed on the screen has depth, doesn't matter what your using, the end result is always going to be 2D. Internally it's 3D. AO is calculated internally and takes into account all the fun light beams and so on and so forth. SSAO doesn't because it can't, it doesn't have access to any of that information. But it does have access to depth maps (I only used height maps as an example of how they look, they're inverted in most programs but the principal is the same). A depth map is the Z-Buffer, it's used to decide what's in front of something and what's behind, and it's very, very useful.

A good use of depth maps is in post production. At that point all your resources are completed and the end results are nothing more than images. Often it's a good idea in post, to do certain effects such as fog, depth of field, or even placing elements in the correct positions in relation to the image. Now if you've just got the single stock image, you're kind of boned unless your elements were against a single color (like green/bluescreen) or using alphas to allow them to be cut out. But even then, to do things properly, a depth map helps. It can then tell the 2D program that a particular effect, lets say fog, should appear heavier where the depth map is pure white, and then falloff as it gets darker. You've just put fog perfectly into an otherwise flat image.

SSAO works the same, and there's a number of plugins available in post production applications which do just that. After Effects and Shake come to mind as two that have them.

-

As for depth within a sprite. Your right, a default sprite in a default 2D world has no depth, being two dimensional.

But what's stopping you from having depth? Consider a parallax effect, 10 layers all scrolling at a different speed. It's 2D, it has no depth. But what if the artwork on each of those layers were given a depth. The artwork in the background layers would be further away than those closer. You couldn't see the difference to look at it. But what if you then applied a DoF shader that takes depth maps into account? You've got visible depth.

Now say you were to create a sprite of a lil guy running, viewed from the side. Shade him however you want, he's just a 2D image. But give him a depth map, where his arm is closer, like an inverted height map. Add an SSAO shader on that, you've got realtime ambient occlusion. You could do this in the same way normal maps are applied at the moment, so effectively doubling everything, or tripling it if you add the normal map required copies too.

Now while this is entirely possible. I'm not saying it's easy. To accurately setup a scene in 2D to make best use of depth maps and SSAO or a DOF shader. You have to plan ahead, either build the scene in pre-rendered 3D, output the required images and depth maps. Or be very good at deciding where things should be in relation to the imagined depth.


So I wouldn't say it's pointless, or impossible. But to set it up without forward planning can break the illusion entirely, and it wouldn't be very useful for everything (retro looking pixely games would have no use for it for example).

Incidentally, you can do Parallax Occlusion Mapping the same way, with a shader coded to change the parallax effect based off of distance and angle from a center point, and using a standard height map for it's input rather than a depth map. Yes that would work just fine in a 2D game as well. But considering you'd be then having four clones of everything, to take into account a depth map for SSAO and DOF (and more accurate motion blur), a normal map, and then a height map for the parallax occlusion effect. You're going to be needing a decent machine just to run it at a sensible framerate. :D

And now you've got me thinking, how cool a remake of Shadow of the Beast would look, with all the above. Oooooh. :)
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

PreviousNext

Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests