4D Datatypes and Vertex Programs

Greetings. I’ve been working on a simple shadow system as of late, and have run up against a bit of an efficiency-related stumbling block:



Presently, the process of extruding vertices from the silhouette edges must be performed in software. As it stands, there are some neat tricks for selectively extruding vertices based upon the content of their w-coordinate. After a bit of hunting through the API References and source code, I’ve been unable to locate a means of building geometry using a homogeneous coordinate system (IE, points specified as {x,y,z,w}). Can anybody point me to information pertaining to feeding 4D Vertices to a vertex program without calling directly to the underlying renderer’s Vertex4f()? Furthermore, is there any possibility of a Vector4f class to complement the com.jme.math.Matrix4f class?



Incidentally, if anyone’s curious, I’m using the Stencil Shadow algorithm with Infinite shadow volumes, as outlined in “Mathematics for 3D Game Programming and Computer Graphics” by Eric Lengyel. Implementation’s not exactly complete at the moment, and probably doesn’t fit into the overall structure of jME, but there are bits of code that can be reused elsewhere should anyone want them. Parts of interest include a method for taking a trimesh and collapsing coincident vertices, and building edge information.



Thanks for any help that you can offer.

Sorry for the lack of response, but I have to admit I’m not sure what exactly you need. What is the forth value of the vector? If you could put up a mockup class of what you desire that would help. MikeT implemented shadows http://jmonkeyengine.com/jmeforum/viewtopic.php?t=1271 and has given me the source code. It’s pretty good, but we simply haven’t implemented it yet. Mostly, because we don’t have a good multipass techinique in place yet, and Mike was forced to work his own in. The shadow code is very clean though.

Apologies for the confusion, and no worres about the response time. What I’m attempting to do is outlined in this Gamasutra article (Free registration may be required):

http://www.gamasutra.com/features/20021011/lengyel_01.htm



What I need to do

Specifically, what I need is the ability to build geometry with 4D coordinates.



Modifications involved

It looks like it would require some modification to preDrawMesh(TriMesh) and prepVBO(Geometry) to call GL11.glVertexPointer with the first argument as “4” when appropriate. It would also require changes to the call to GL15.glBufferData to reflect the additional float being passed. The question lies in how to make the differentiation between 3D and 4D geometry. The simplest way that I can think of would be to create some sort of Geometry4D, CompositeMesh4D, TriMesh4D classes that deal with a Vector4f.





Theory

From a theoretical standpoint, the w coordinate serves several purposes:



First and foremost, it allows for combining scale, rotation, and translation operations into a single 4x4 matrix, removing the need to transform translation matrices for nested transforms.



Secondly, it can be used to distinguish between vectors that represent directions (w = 0), and vectors that represent points (w = 1). This is because points are projected into 3D by dividing by the w coordinate (x/w, y/w, z/w). Direction vectors (w = 0) will extend out to infinity in the direction of (x,y,z), causing them to be unaffected by translation (IE, adding one to infinity is still infinity), but still affected by rotations and nonuniform scaling. Point vectors (w = 1) will naturally remain in their original positions and be affected by all translation, rotation, and scaling operations.





Reason for use

In the context of this implementation of shadows, the w coordinate is used to identify the vertices that get translated away from the light source (it’s a rather elegant trick, actually) and then get projected out to infinity since their w-coordinate is zero. This process can be done entirely on the graphics card.