Real Time Phong Shading Demo
I haven’t posted in a while so I thought I’d share the result of today’s coding. It’s the real time Phong shading engine for a pool game I’m gunna start working on. At the current stage, you can place multiple light sources in 3-space each of which can have a unique color, as well as an ambient, diffuse and specular aspect to them. The balls have a texture associated with them as well as a material which has the same properties as a light but also a shine element which gives it the glare. The texturing of the balls is anti-aliased, though I still have to incorperate anti-aliasing to the outside edge of the balls.
One of the more challenging aspects of the texturing was mapping each drawn pixel to a pixel in the square texture. The rotation of the ball is represented by 3 perpendicular unit vectors. One vector is points to the center of the texture, another helps determine the polar angle from the first vector to the point that is being drawn, and the third vector aids in figuring out whether or not the angle is greater than 180 degrees since a dot product alone cannot tell you this.
With this outta the way all I need to do is write the physics engine. For the most part this shouldn’t too difficult as I’ve written a tutorial on perfect circle-circle collision detection as well as understand the physics of 2D and (for the most part) 3D collision reaction. The only thing that I have yet to study is the effect of applying a spin on the ball (ie not striking the cue ball perfectly in the centre with the cue stick). I want this game to be fairly realistic physics wise as well as visually. I’m thinking of adding RPG elements to the game where you start off as a noobie and as you play your shot becomes more accurate over time. If you tend to shoot more long balls, your long shot will improve faster than your short shot etc.. I’m still thinking about the design of the game so no code has been written yet. I’d be glad to hear any suggestions as how to enhance the gameplay.
In the task bar of your browser, the applet should display what kind of load it is experiencing. I have manage to optimize it to the point where it only loads the applet 36% when all the balls are on the screen. When the physics and further drawing is added, this should stay below 50% for my 2 year old laptop. At the moment this applet also takes up 25% of the processor. I was hoping you guys could let me know the numbers you are seeing so I could do more optimization if necessary.
View Phong Shading Demo.
Source will become available when the game is released.