2 pass renders and blending

Blitz3D Forums/Blitz3D Programming/2 pass renders and blending

MadJack(Posted 2004) [#1]
I know that you can set a camera to render without clearing the last render's image (colour).

However, what if you want to blend a camera's render with the last rendered frame?

Do you have to resort to copying to a texture applied to a quad covering the canera? Is that the only way?


MadJack(Posted 2004) [#2]
Hmm - either I've asked a blindingly obvious question or nobody knows (which is unlikely)?

Rob, Sswift? Anyone?


JoshK(Posted 2004) [#3]
Define "blend".


fredborg(Posted 2004) [#4]
Yes, you need to copy it to a texture and apply it to a quad.


sswift(Posted 2004) [#5]
"However, what if you want to blend a camera's render with the last rendered frame?"

If you want to blend with the previous camera view, you may also want to clear the zbuffer, but that depends on whether you're doing something like lightmapping, in which case you don't.

As for how to blend... well, you just set the blend mode for all the entities to something other than alpha, since you obviousyl don't have any alpha maps enabled or you'd be blending already. :-)

For lightmaps, like if you render the lightmap first, you'll want multiply or multiply x2 for the entities.

Keep in mind that blended entities don't write to the zbuffer. But so long as your lightmap pass has laid down the right z values you should be okay. But if you're not doing lightmapping then you might find it hard to get whatever effect you're going for.


MadJack(Posted 2004) [#6]
Ok, forgive my programming dodginess, what I want is the following;

I want to display my level geometry with essentially three texture layers using three different UV sets. Basically the level texturing (e.g. wall textures), a lightmap (say from Giles), and then for quick and (very) dirty lighting effects (avert your eyes Halo), a planar mapped bitmap onto which light circle's can be drawn to give brilliant 'flashes of light'.

I thought a possibility would be to render the level proper (with wall textures and lightmap) and then do a second pass rendering a copy of the level showing only the planar mapped light circle, and then blending the two renders.

Is this possible?


AntonyWells(Posted 2004) [#7]
You'll want to disable color buffer clearing, cameraClsMode,0,true.

also, disable z buffer if you want following renders to 'integrate' into the already rendered 3d scene properly(Good for multi-pass fx.)

to blend in the light..i'd suggest mod5 on the second render mesh, and then setting the second pass to entityblend mesh,3(add) so you'll render in over the top rather than replacing it. alpha's no good 'cos then you'll get all the unseen polys showing up.


MadJack(Posted 2004) [#8]
Otacon

Thanks for the tips - I'll give that a go this evening.


MadJack(Posted 2004) [#9]
I guess the other issue is that using a planar mapped lightmap will mean that vertical walls will be lit by only one pixel in the y axis (from the lightmap), and that a light on the floor would also light the ceiling above with the same intensity, no matter how high that ceiling.

And I guess the solution is to use a non planar lightmap, get the polys affected by the light, calculate their UV's and draw appropriate shading onto the lightmap so that the appropriate polys light up within the level?

Am I on the right track?


sswift(Posted 2004) [#10]
No.

I considered makign such a system, but be warned. I have come to the conclusion that even with advanced culling methods, it's likely to be too slow to do in a real scenario. You might get away with two lights.

Here's what you do though:

Create one light texture which is a circle of light. Turn on UV clamping. Texture should be black all around edge.

Copy middle row of pixels to a second texture. Set this to have UV clamping as well.

Now find the polygons that fall within the region of light, and create a new mesh. Set the first set of UV coordinates to the XY planar projection from that location. Place the first texture in the first texture unit and set it to multiply. (Textures are multiply by default, so you don't actually have to set it.) Then project the Z coordinate as well and set that to the second set of UV coordinates. Then place the second texture in the second texture channel of your mesh. This will also be multiply blended.

Finally, set the mesh to add with the lightmaps behind it.

All done!

What you're basically doing is projectcing a cylynder of light perpendicular to the XY plane that falls off towards the outside of the cylynder from the center. But you are then multiplying the brightness of that cylynder by the falloff on the Z axis as well. This results in a spherical region of light.

With two 2D maps, you might even be able to create a cone of light so you have something more akin to a spotlight. But I'll leave that as an exercise fo rthe reader.


JoshK(Posted 2004) [#11]
It can be done pretty easily if you are using brush geometry. I just use a version of CShop's UV mapper to do these kinds of lights. I wouldn't use any more than about 5 at a time, but they work fine, and are fast as long as there aren't too many.

You don't even have to calculate tex coords for each vertex. Just UV-map them at load time and then you only need to adjust the texture offset to "map" them during the loop.


MadJack(Posted 2004) [#12]
Sswift/Halo

Thanks for the info guys. I've set things up in the following way;

The level geometry is vertex lit for static lights, with occluded vertices not being lit.

Entities (within a short range) are dynamically vertex lit (3 lights max). Beyond range, they're set to DX shading.

For bright 'flashes', planar mapped coloured light circles can be drawn onto the level geometry. These can blend into one another and don't require building a mesh. They're pretty fast - the downside is that being planar, they'll cover a vertical wall with one colour, regardless of how high it is.

However, by using a simple top-down wall mask over the light circle image and repeated re-rendering, I can 'smear' the mask outwards over the light circle image, achieving a simple shadow fx.

Also by fading the light circles by their distance from camera and by their height above level geometry, I hope to mitigate problems.