Lighting with Read Pixels (Composition by gtoledo3)

Author: gtoledo3
License: (unknown)
Date: 2011.04.11
Compatibility: 10.5, 10.6
Categories:
Required plugins:
(none)

This is a composition that takes the depth buffer from a QC scene, using the GL Read Pixels from GL Tools, and the color buffer, and composites them using a GLSL normal map shader (cwright's Normal Map Demo I). A normal map is derived from the depth image provided by Read Pixels, to create the lighting effect, using a custom CI patch.

One of the cool byproducts (to me at least), of doing this, is that it shows the "flat lighting"/non smoothed version of the QC scene when you read the actual Depth and convert to normals.

It used to be possible to read the color buffer using GL Tools Read Pixels; this broke in SL. So, this also shows how reading the depth buffer can still work, and how one can still get color by employing RII.

It does a pretty good job of painting pixels that should be occluded darkly. It's a sort of fragile setup, and it's possible to break it by changing it (eg. adding extra processing at different points, flipping various non-published params, layers, etc.).

PreviewAttachmentSize
Lighting with Read Pixels.qtz24.76 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cybero's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

Impressive and useful.

Wish I could get 3rd party plugs functioning in 10.7, without getting exception errors when drilling down the macros !

Worked fine in 10.6.7.

franz's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

what ? 3rd part plugin DO NOT work under 10.7 ?

gtoledo3's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

They do, there is a prob w the seed though. I don't remember the first one doing that. Since apple apps actually hinge on loading skanky plugins sometimes I'm going to guess it's a glitch that will get worked out. Good catch though Cybero ( though awkward to talk about as it is pre-release and we really should not).

psonice's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

Nice, but the lighting seems slightly 'blurry'. Would it not be better to generate the normals in a glsl shader?

Also, try adding a few objects, and blurring the normal map before doing the lighting ;)

gtoledo3's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

There's a blur - (did you just look at the picture? It does look kind of blurry I guess). That's only for the edge effect - since you can't really get anti-aliasing. That is an idea I got from GPU gems.

I'm attaching a pic without that blur...a user can turn the blur down to 0, and it looks the same as no blur.

One can make the glsl shader so that it excepts greyscale image, but I've found that making the object that makes the normals available to myself is a better route (imo), because I can post process. I've found bilateral and trilateral filtering to be cool, as well as various other edge aware blur techniques. I used the gaussian in this comp because it was easy, and I only wanted to create a 1~2 pixel halo around the object to smooth the aliasing.

I'm not sure what you mean about adding a few objects and blurring the normal map before doing the lighting, in the context of what's going on... there's a blur there now. Could you clarify what you mean on that, because I'm guessing it's cool/ it seems like that's what it is now, so I'm confused.

The blur gives a kind of marshmellow effect at extremes though (unless you're talking about doing some kind of bokeh blur?).

PreviewAttachmentSize
depth_buffer_.png
depth_buffer_.png147.4 KB

psonice's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

By blurring the normals, you can 'blend' the edges between objects. Do this to a bunch of balls, and you have instant metaballs :) (Of course it's not quite that simple, you have to account for the Z distance in the blur or it blends between objects and the background).

You'd have to write your own blur shader for this unfortunately. But it's mighty powerful :) You can say soften up the teapot, without the nasty artifacts where the edge of the teapot mixes with the background.

Example: http://www.pouet.net/prod.php?which=51114

gtoledo3's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

psonice wrote:
By blurring the normals, you can 'blend' the edges between objects.

I totally follow this.

Do you remember a loooong time back, when I was asking about making normal maps from greyscale? This was because this was exactly the kind of thing I was interested in doing.

Quote:
Do this to a bunch of balls, and you have instant metaballs :)

You know what's kinda funny, is that I made a "from scratch" metaball algorithm that's up here that isn't too far off from that premise... I happened upon the idea when studying the laplacian of gaussian, and medial transform and reconstructing shapes from skeleton (errr, maybe that sounds weird, but it led to the thought).

The idea was basically to take circles, process them to have an appropriately weighted gradient, and blur the "in betweens". With the blurring, and the appropriate gradient, if you feed that to a GLSL extrusion shader setup, you can make a "hull". It's a really "cheap" way of getting that look going, though the metaballs only move and blob together on the x/y axis, not Z. It scales pretty darn well.

Then, I used (in one of the demos at least) an additional procedural normal map as a way of getting some extra texture/roughness onto the metaballs.

Quote:
(Of course it's not quite that simple, you have to account for the Z distance in the blur or it blends between objects and the background).

You'd have to write your own blur shader for this unfortunately. But it's mighty powerful :) You can say soften up the teapot, without the nasty artifacts where the edge of the teapot mixes with the background.

I'm set with that...I think. Thanks for posting the link below, I'll check it.

The only sad thing is that it's (depth dependent blur) not really "cheap" for a really good look, at least with whatever I'm doing. This is qualitative obviously... what I find to be a premium look with a depth dependent blur winds up knocks off at least 10~15fps. Maybe it's lack of really good honing on my part, though I have three different versions of shaders that do that, at differing levels of quality/accuracy for fps trade off. I do have one that works quickly, it just doesn't look as good.

Quote:
Example: http://www.pouet.net/prod.php?which=51114

You know, bringing it back to metaballs reminds me of how lame it is that the volume mesh renderer doesn't work in QC even though it is part of a stock patch. Poking around, I see there is a 3D image format in SL too. Oh well.

gtoledo3's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

BTW, I had seen that clip and admired it before. I look at pouet, and surf for these type of vids as well.

That look seems totally doable in QC. I made a patch that would be ideal for the sphere structure snakes, but I don't know if I can release it or not :-s

gtoledo3's picture
Re: Lighting with Read Pixels (Composition by gtoledo3)

I had a go at the metaball snake thing...

It works pretty well. The thing that hurts it (with the way I am doing it at the moment), is that the depth image doesn't draw synchronously with the texture image because of the way I'm getting the texture vs. the depth pixels. Since the metaball stuff is typically fast motion, doing it this way is not ideal from the standpoint of visual artifacts.

I didn't really spend much time tweaking the look because of that... I think the look could be glossier, I probably just don't have the sweetest lighting settings. I need to abandon the kineme plugin and do something that outputs depth and texture at exactly the same frame, if one wanted to do that really well, I think.