Masking out reflected objects

Blitz3D Forums/Blitz3D Programming/Masking out reflected objects

Dock(Posted 2005) [#1]
I'm currently working on a project which involves a lot of puddles marked out on the floor, which I want to be reflective. I think I will try to use a cubemap for the environment, but I was going to try to mirror my character and render her upside-down to create her 'reflection'.


Imagine the salami-esque circles on the floor were puddles.

I'm using RenderOrder to get my character to be drawn early (after the ground, but before everything else). Is it at all possible to 'mask out' this render? How could I mask out everything except the puddle areas?

Also, how do I 'mirror' a mesh, as in convert it to be flipped on one axis? Flipmesh is something entirely different, and rotation isn't ideal either.

I could use an updated cubemap, but I feel this would be incompatible on older hardware and also might not line up precisely with the character.


Beaker(Posted 2005) [#2]
I would try and use Tom Speeds (Scouse on IRC) stencils to do this.

The procedure would look something like this:

1) render reflected world.
2) turn on stencil writing.
3) render puddle salamis.
4) turn off stencil writing.
5) render rest of world.

You can possibly mirror an entity by negative scaling on the Y axis: ScaleEntity thing,1,-1,1

Nice gfx btw.


Dock(Posted 2005) [#3]
Will the stencils work on older hardware? Is there any links to the stencil code?

Scaleentity 1,-1,1 seems to work... sort-of. I'm having horrible UV/normal problems but I think this may be due to the B3Dpipeline code.


Beaker(Posted 2005) [#4]
I would do a few tests but they should work fine on most hardware.

More info:
http://www.blitzbasic.co.nz/Community/posts.php?topic=40097
http://www.blitzbasic.com/Community/posts.php?topic=40770
some code (and demo):
http://www.tomspeed.com/stencil_mirror/

To give you a better clue as to how it might work, do a search in the stencils mirror code for this line:
m\entity=CreateQuad()
and replace it with:
m\entity=CreateMesh()
	ball1=CreateSphere(8,m\entity)
	PositionMesh ball1,2,0,0
	AddMesh ball1,m\entity
	ball2=CreateSphere(8,m\entity)
	AddMesh ball2,m\entity
	FreeEntity ball1
	FreeEntity ball2



GfK(Posted 2005) [#5]
Scaleentity 1,-1,1 seems to work... sort-of. I'm having horrible UV/normal problems but I think this may be due to the B3Dpipeline code.
If you're using negative scaling like that on one axis only, then the model will be inside out. Use FlipMesh to rectify.