Triangle sorting / blending question

Blitz3D Forums/Blitz3D Programming/Triangle sorting / blending question

Roland(Posted 2008) [#1]
Hey all,

strange question for ya. If I create a mesh that has additive blending (entityblend,3) is there any way anyone can think of that I can control how the triangles are sorted? I need to try to eliminate pieces of the mesh by having black triangles overlap the other pieces of the mesh (and black blended additively is transparent). But it doesn't work.

End goal is to be able to cut chunks out of a flat surface using other chunks of a mesh without doing any fancy intersection math.

Any ideas?

thanks,
roland


Stevie G(Posted 2008) [#2]
Fancy intersection math may be unavoidable.

Can you explain more about what you're trying to do - in a gameplay context? e.g Are you trying to do landscape deformation?


Roland(Posted 2008) [#3]
Thanks, Stevie.

Not doing landscape stuff -- it's actually for a 2d light effect that is used in a puzzle-style game. Currently the implementation that I have (which works ok) is to raycast out from a point source along an arc of a fixed width to determine if there is an intersection with a line that would block the light. If such an intersection is found, I mark it and construct a mesh based on all of these intersections.

The problem is that as the number of lights grows, in order to have a smooth effect, I need to cast a vast number of rays.... Imagine a scenario where I have 5 lights, and each casts 100 rays... If there are 5 cubic objects that block those rays, each has 4 sides, or 4 lines. So in order to properly build my mesh, I'm now looking at 5*100*20 iterations per frame. that's 10,000 intersection checks per frame.

Granted, I've done all sorts of optimizations to try to limit this, but it is still possible to create scenarios that can bring everything to its knees.

This is why I'm trying to seek out a new approach. If, for example, I could simply draw a mesh that represented the light (without any intersection), then draw on top of that a mesh that represented all of the shadows from every line that the light would generate and have it knock out the light mesh were they overlapped, it would accomplish my goal without any complicated iteration at all. But I haven't been able to come up with a system that does that, short of rendering the entire screen to a huge texture every frame and using that as a texture. Again, though, if I have 9 lights, this becomes too expensive as well, and has a tendency to look crappy.

i'm open to any creative ideas!


Stevie G(Posted 2008) [#4]
Ok, I think I get you ...

Assume MAINcamera is the main cam you use to show your visible level.
Set up a LIGHTcamera and position it far away from the main scene.
Set cameraclsmode to false, true
Create your shadow mesh
Set entityfx to 1
Colour it black
Set it's entityorder to be drawn last
Parent it to the LIGHTcamera
Position it the same as the visible level, but relative to the LIGHTcamera, rather than the MAINcamera.
Parent all your light cone meshes to the LIGHTcamera

Then do a 2 pass render ....

;render main camera
cameraprojmode MAINcamera, 2
cameraprojmode LIGHTcamera, 0
renderworld()

;render light camera over the top
cameraprojmode MAINcamera, 0
cameraprojmode LIGHTcamera, 2
renderworld()


Stevie


Roland(Posted 2008) [#5]
Hi Stevie,

Looks like this approach is for simple shadowmapping, right? I've implemented this as a test before and unfortunately found that it wouldn't be fast enough. Here's why:

1) The lights can each be of different colors, which is part of the puzzle-gameplay of the game. which means that I can't just render 1 pass for all the lights

2) In truth, I actually need to be able to determine which light is responsible for contributing to the solution of the puzzle, so I might even need to be able to separate ALL of the lights. That would be a maximum of 9 lights, meaning 10 render passes per frame... That would be asking a lot, I think!

But I should probably give this some more thought. Even if I could keep it down to 3 passes, it might still be faster than my existing solution.

Thanks for the tip, and let me know if you have any other thoughts!


Stevie G(Posted 2008) [#6]
Can you post some mock screenshots to show the effect you're looking for or maybe even what you have just now 'cos I'm none the wiser. Plus,
are you actually using hardware lights?


Roland(Posted 2008) [#7]
Well, here's a mockup of the effect in photoshop. You can see there are 3 lights here, each of a different color. The grey squares are the shadow casters. You can see that the effect is pretty much just 2d.

What's not shown here is that in-game, I need to know exactly what is being illuminated in order to use the lights to solve puzzles. Currently, I just use the mesh to do that (calculating whether or not points are in the triangles of the mesh), but I'm sure there are other ways that could be accomplished as well.

If you refer back to my description before, hopefully it will make more sense now. Using the white circles as the origin of the lights, i would cast my rays out starting at the far left of the light beam, and go until the end of the right, testing each ray for intersection with a shadow caster...

Does this help?



Roland(Posted 2008) [#8]
oh yeah -- in answer to your second question. no hardware lights are needed for it. it's all just done using additive mesh.