# Vertex Programs!

Here’s a quick preview of what I’m working on:

It uses a vertex program and a one-dimensional luminance texture to do cel shading on a torus. The test encompasses things like passing parameters to vertex programs, and multiple pass rendering using the jME scenegraph. More to come soon, including fragment programs! (Which I’ll be completely unable to test, as my poor GeForce3 doesn’t support them. :P)

Very cool!

I’m looking forward to seeing this in action.

Gregg

Update!

Well, ARB_vertex_program and lwjgl appear to be unhappy with life, incorrectly reporting that my card doesn’t support the extension. No worries, though, as I went ahead and rewrote the vertex program using the original sadistically cryptic NVidia syntax. Oh yeah, I’m a sucker for punishment! Take a look, if you’re curious:

``` !!VP1.0 # c[0]-c[3] modelview projection matrix # c[4]-c[7] inverse modelview projection matrix # c[8] light position in object space # compute the vertex's position DP4 o[HPOS].x, c[0], v[OPOS]; DP4 o[HPOS].y, c[1], v[OPOS]; DP4 o[HPOS].z, c[2], v[OPOS]; DP4 o[HPOS].w, c[3], v[OPOS]; # output the color MOV o[COL0], v[COL0]; # transform normal vector by the modelview matrix DP3 R0.x, v[NRML], c[4]; DP3 R0.y, v[NRML], c[5]; DP3 R0.z, v[NRML], c[6]; # R1 = normalize R0 DP3 R1.w, R0, R0; RSQ R1.w, R1.w; MUL R1.xyz, R0, R1.w; # calculate our shade value DP3 R2.x, R1, c[8]; # use the shade value as our texture coordinate MOV o[TEX0].x, R2.x; END ```

But all is well! The lighting is no longer static. Using a NodeController, you can use the mouse to rotate the torus and the lighting adjusts itself correctly. It looks pretty cool, if I do say so myself. Now to remove the remaining raw OpenGL calls...

Progress continues!

I’ve now eliminated virtually all the raw OpenGL calls, except glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); and GL11.glPopAttrib(); These have proven to be rather stubborn. Ideas, anyone?

Weirdness continues with ARB_vertex_program. Would somebody please put

``` if (GLContext.GL_ARB_vertex_program) {     System.out.println("Supported");     java.nio.IntBuffer id = BufferUtils.createIntBuffer(1);     ARBVertexProgram.glGenProgramsARB(id); } ```

in the initGame() method of any jME test and tell me if it runs correctly? I get a hard environment crash on glGenProgramsARB! Erk. I'm beginning to believe this may be an anomaly limited to my computer alone, but I'd like confirmation.

Thanks.

It appears to work with my card. It doesn’t crash.

I have an ATI Mobility Radeon 9600.

Gregg

I finally tracked down the weirdness to a bug in the lwjgl native code. Hopefully it will be resolved for the official 0.9 release of the lwjgl.

I’m now faced with a decision: whether or not to fully support NV_vertex_program. Most of the implementation work is complete, excluding glTrackMatrixNV which requires the enumeration of a lot of constants and requires that the class maintain a lot of state information. In addition, the extension works only on NVidia cards and has now been completely replaced by ARB_vertex_program. As far as I can see, it’s not worth the effort to complete, but before I abandon it I’d like know what the other developers have to say. (Alternatively, I could commit it in its current state and complete the implementation only if someone specifically asks for it. Otherwise it’s the ever-wonderful NotYetImplementedException!)

The cel shading demo is now complete, and is now properly scenegraph-ified. Pretty impressive that it takes about half the code in jME to do the same thing in Xith3D. More demos coming soon, I hope!

it would be cool If I could play cel shading, cause I use ATI 9200!

How about you upload the current implementation (tests too?), when 0.9 is out (round easter time), you could reimplement it using ARB_vertex_program?

PS, this looks AWSOME!

Initial implementation of ARB_vertex_program is now committed to CVS! It’s mostly done, but environmental parameters have yet to be completed, and some optimizations are not yet complete. TestVertexProgramState demonstrates a celshaded torus using vertex programs.

NOTE: There is a nasty bug in the ARB_vertex_program intialization in the 0.89 build of lwjgl. Because of it, I’m unable to verify that any of the stuff I’ve committed actually works. Especially the vertex program itself, as I’m still shaky with the syntax. So, while I hope everything works correctly, it may not. Just gimme a detailed error report and I’ll fix it ASAP.

(For curiosity’s sake, I’ve left in the old NV_vertex_program code, which I’m certain works. If you have an nvidia card and you feel like messing around, just uncomment all of the NV-specific code in LWJGLVertexProgram and comment the ARB stuff. Also, change the shader to celshaderNV.vp in the test. If nothing else, I’m sure that this configuration works correctly!)

Fantastic! This is going to add a lot of wow factor to jME. I am not seeing the shading when I run the demo though. ATI Radeon 9700.

You should see it using PQTorus. Oh, btw, after some playing yesterday, eric and I altered the vp file to make shading work properly. I don’t know if he wanted me to check that in though…

vertex doesn’t work on mine…crashes out! Radeon 9200! :’(

I’ve already committed the changes I made to the vertex program. I also made further alterations to the updated version I sent renanse which should allow you to fiddle with the light position by altering the lightPosition array.

One thing to note: I can’t find a way to remove the calls to GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); and GL11.glPopAttrib(); without screwing up the demo. Is there a way to emulate this behaviour in jME, or are we stuck with these raw calls?

DarkProphet:

Most likely your system doesn’t support ARB_fragment_program, which causes lwjgl 0.89 to crash when ARB programs are initialized on the native side. A known issue that’s corrected in CVS, but I don’t have access to a newer library version.

darn niggets!

I’m going to make an AttributeState that will set attribute bits for you. I’ll get that done today. I’ll keep you posted.

Ok, I added Attribute state. You now create a state, set the mask (ALL_ATTRIB_BIT) in your case, then add it to the node where you want the state saved (scene).

I modified and checked in the vertex program test using the new state, however, my laptop is unable to handle shaders so I was unable to test. Please update and make sure this addition works. If not let me know ASAP and we can figure it out.

Hey Eric, I was just curious if you could give an update with regard to the Vertex Program interface. Are you still having issues with LWJGL? Just like to know where we are at with it.

afaik, he is - because he requested a newer build…

http://matzon.dk/brian/lwjgl/builds/lwjgl-2004-03-31.rar

That new build works just fine. Thank you!

What’s the plan with this? Do you think you’ll have it to a state where it can be advertised for 0.6 or would you prefer it stay quiet until 0.7 or so? Just let me know. 0.6 would be great, but later would be understandable.

VertexPrograms are set for 0.6! One final commit to perform a bit of clean up and revise the documentation, and we can consider them complete. I’ll also clean up and document test so it’ll serve as a tutorial of sorts for vertex programs in jME.

FragmentPrograms are next!