shared vertex problems

Blitz3D Forums/Blitz3D Programming/shared vertex problems

Damien Sturdy(Posted 2004) [#1]
Hello. Im trying to create a REAL CreateMirror function in blitz.. in theory it works, but practically, it failed bigtime. Until i learn more, i cant do it....

What it was going to do:
All entire triangles below Min_y are removed
all triangles with at least one vertice above Min_y are cropped to min_y, Then, when this is complete, create a copy of the mesh below min_y which is flipped in the Y direction.. a plane is then placed at min_y and is returned from the function.
the mirrored mesh is child to the plane

Problem now is:

some triangles share vertices... which means it ends up distorting rather than working proberly.. Shame

Does anyone have any ideas for a fix for this? i believe this function would bean excelent function and will make mirroring feasible in blitz games :)


Cheers all


Rob(Posted 2004) [#2]
I think the best kind of mirror is texture based. Even Doom3 uses this kind of mirror.

Polygon mirrors are too much trouble.


jfk EO-11110(Posted 2004) [#3]
Well, I think when you only remove some tris, you still have those Tris that are intersecting the mirror surface, and this may look wrong.
What I would suggest to do, if you realy want to remake the CreateMirror command this way, is the following:

Create a clone of the mesh with all tris that are above the mirror. There shouldn't be a problem with shared vertices if you use the Trianglevertex Function together with the CountTriangles Command etc.

You would create the meshes from scratch, by adding the Surfaces and Triangles one by one, ignoring those you don't want to be part of the clone mesh.

Then you create an additional mesh that contains all Tris that ARE INTERSECTING the mirror, means one or two Vertices of each Triangle are below and the other one or two are above the mirror.

Then you take the Fast CSG Functions in the code archive (guess by Markus Rauch) and cut off the part of the INTERSECTION mesh that is below the mirror. The reason why you create a seperate Mesh for the intersecting parts is: Speed.

THen you flip both, intersection mesh and above-part mesh. There is still one tiny but hard problem: After cutting the intersection mesh, you need to set the UV Coords for the new Tris created by the CSG operation. Now this seems to be the most tricky part. Some 3D Gurus may be able to do it easily, but personally I couldn't do it.

Maybe you should think about to make a CreateMirrorRect(x,y,z,w,h,d,p,y,r) command instead, that will allow to use cubic enviroment mapping with any beloved rectangular quad mesh of whatever size and orientation.

At least all Mirrors in the Level would require only one Cubic-6-Render pass alltogether - and you could also use it for other things (chrome FX etc.) too.


Damien Sturdy(Posted 2004) [#4]
Bloodlocust: I have made two versions of the function, the first being texture based but it isnt very clear.. i tried only texturing a smaller area of the mirror (where the camera is) but i cant get the maths right.

JFK:
I will look into cubic mapping, i never thought of it
Also, something else you said might fix my problem.. by making the intersected triangles a seperate mesh, i should be able to split the vertices... this would sort the issue out, i think!


jfk EO-11110(Posted 2004) [#5]
for the cubemapping you may download fredborgs "bathroom" demo from http://www.frecle.net/giles, it includes a working example of a mirroring towel (well, water in that case, but anyway).


Damien Sturdy(Posted 2004) [#6]
cool, i shall go and take a look :D


big10p(Posted 2004) [#7]
Another problem with doing a mesh mirror is the lighting - it'll be wrong for the 'reflection' mesh. e.g.


     /\         <-- lighting shining straight down

    (  )        <-- sphere

-------------   <-- mirror plane

    (  )        <-- reflected sphere mesh

Here, the top of the sphere will be illuminated while the bottom half will be in shadow. This will also be the case for the reflected sphere mesh but it should be the other way around, as it's supposed to represent a reflection.

Anyway, I've managed to come up with a way of cutting a mesh in half (or, whatever) on a given plane. An effect I mentioned to Cygnus in another thread and wondered how it was done. The effect also manages to maintain correct UVs and vert normals for the clipped tris. My brain is throbbing somewhat, now. :)

So, it is possible - and pretty fast, too. ;)

Here's a pic of it in action. You'll just have to trust me that this is being done in blitz and not with a modeller. :)




sswift(Posted 2004) [#8]
I hate you tell you this, but while clipping tris will work, it is unlikely to be near fast enough to use in any real situations. Throw one high poly character at it, and your framerate is kaputski.

If you pre-clipped the level itself to the mirror, then you MIGHT be able to handle clipping if you only clipped those characters which intersected the mirror, and those characters had less than say... 64K polygons total.

But consider this. You can't really clip an animated character to the mirror. You have no way of knowing where the bones have moved the vertices in a particular frame, and the only way in Blitz to apply bones to a new mesh is to create a file and then reload the mesh, which is going to cause stuttering and again, kill the framerate.

If all you wanted to do was mirror some spheres or cubes or something in water, and allow them to intersect with it, then you might be able to do that at realtime framerates. You might even get away with doing some simple car models intersecting with a reflective mud puddle. But humanoid animated characters with bones aren't likely to be possible.


jfk EO-11110(Posted 2004) [#9]
big10p - looks nice. well, with the csg function from the archives this would be pretty easy :) Anyway, if you use lightmapping, the light problem would not arise.

But I agree with sswift. there is a problem with animated meshes an moving stuff, as well as with anything in motion such as particle emitters etc.

Maybe it's easier to use the CEM method. As I mentioned earlier, if you once have rendered the cubemap, you can use it for an unlimited number of meshes (eg. Mirrors and chrome parts in the WC etc.)


big10p(Posted 2004) [#10]
I hate you tell you this, but while clipping tris will work, it is unlikely to be near fast enough to use in any real situations. Throw one high poly character at it, and your framerate is kaputski.

True, for a mirror effect but I'm using this technique for something else - a per-entity effect to clip the mesh at a given plane. It's easily fast enough for what I want. :)

[edit]
Infact, one of the biggest speed bottlenecks I've found is making an exact copy of the mesh to be clipped. I can use CopyMesh for single surface meshes, and then repaint it with a brush extracted from the mesh being copied. However, CopyMesh seems to combine surfaces unless they are using different textures. I need to maintain the exact same structure in the copied mesh as exists in the original one. I can, of course, read vert info one at a time and then apply to it the new mesh but this seems to be slow(ish). Any ideas how I can do this more quickly?
[/edit]

big10p - looks nice. well, with the csg function from the archives this would be pretty easy :)

Maybe, but, where's the fun in using someone elses code?! I've learnt quite a bit working this stuff out. :)

But I agree with sswift. there is a problem with animated meshes an moving stuff, as well as with anything in motion such as particle emitters etc.

Well, the effect I have in mind isn't for animated meshes, really. However, I haven't found a problem with meshes in motion - that sphere in that screenie above is actually rotating as the clipping plane gradually moves up, erasing it.


ashmantle(Posted 2004) [#11]
Someone mentioned Doom3... have you noticed how they don't mirror you at all? Its a whole other thing going on behind the mirror.. do this test:
Grab your flashlight and shine it at the wall while standing parallell to the mirror.. (so that you see the lighted wall both through the mirror and otherwise..) ^^











Spoiler ^^
The light in the mirror moves around alot and doesn't look at all like yours.. perhaps its a demon of hell who's playing a joke on me? *shudder*


Damien Sturdy(Posted 2004) [#12]
@ Sswift:

Im only doing the clipping once.. and with my games i tend to keep the polycount well low, because i can get more gameplay in (like supernova can now handle 80 ships at any time onscreen with no slowdown)

For character reflections, i just have a copy of the entity rotated around.

@Big10p: Nice effect! any chance we could see a demo of this in action?


big10p(Posted 2004) [#13]
OK, I'll try and get a demo up this weekend, maybe Monday. :)


Damien Sturdy(Posted 2004) [#14]
very, very nice stuff. of course, the next pit stop for this kinda thing is a maplet clone! That would require a bit more maths though!


big10p(Posted 2004) [#15]
OK, the demo's up - grab it here:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1143


Damien Sturdy(Posted 2004) [#16]
woohoo! cheers :D and nice work!