Texture splatting - 2 Textures (Alpha / Color)

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
J-Fox
Posts: 15
Joined: Wed Sep 26, 2007 12:25 am
Location: Hannover, Germany

Texture splatting - 2 Textures (Alpha / Color)

Post by J-Fox »

I would like to use a grayscale image (r=g=b, GU_PSM_5650) as alpha for another image (GU_PSM_5650).

So basicly I m trying this:

- I render my scene to a rendertarget, works
- Blur that rendertarget, works
- Get zbuffer to rendertarget, works

and now I would like to render the sharp scene, and then put the blurred scene with the zbuffer as alpha above (depth of field effect)

How could I do that?

---

My idea was to subtract the zbuffer from the blurred scene (which will make stuff far away from the camera darker), then rendering the sharp/original scene and use additive blending to blend the blurred scene. I m not sure which blend functions to use then though...
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Well, though your idea is nice, it won't work out. The problem is that the additively blended scene would change the color effects of the output image in a non-realistic way. You really need alpha blending for it to work. You could achieve that by using DST*SRC blend and DST*(1-SRC), then adding those together, but that would cost too much pixelrate to be practical.

Here's how I'd do it:
- render depthbuffer (downsampled) into a 565 rendertarget
- render original scene (downsampled) into the same rendertarget, but this time as 4444 with disabled stencil (hence leaving the upper most 4 bits from the depth buffer as alpha channel)
- render the rendertarget with alphablending onto original scene (upsampled)

If you do several more downsampled (2x,4x,8x, etc.) versions and use a good palette for the depthbuffer reads (T16) to distribute the depth, then add the results together you can get a very smooth depth of field effect. Also, the rendercost shouldn't increase dramatically with more steps, since the rendertarget becomes smaller and smaller - so throughput becomes less of an issue.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Post Reply