Halloween Pumpkin Carving

6837d514b487de395be51432d9cdd078
0
TheNut 179 Oct 17, 2011 at 09:00

11-10-16.jpg

Description
[](http://www.nutty.ca/webgl/pumpkinCarve/)

Pumpkin Carving
pumpkins.jpg
Click to Play

It’s that time of year again. Dressing up, worshipping demons, shooting zombies, running away from said zombies, and of course pumpkin carving! While no substitute for live carving competitions (or pumpkin pie, nom nom nom..), here’s a fun little WebGL app to decorate your desktop.

Anti-Aliasing
On the technical side, the app uses a modified WebGL friendly FXAA shader originally from Timothy Lottes blog. The results so far are good, especially since MSAA is not yet available in every browser. I have another demo posted here that demonstrates an older version of the FXAA shader. If you look closely at the edges in the heightmap, you can spot the difference as you toggle antialiasing.

Drawing
I went through several drawing algorithms before I settled on this one. I originally wanted to cut and tessellate the polygons, but the amount of work involved was more than I bargained for (I only had the weekend to make this!). The pumpkin is planar mapped, so I settled on finding the triangle the mouse cursor was over, interpolated the UV coordinates, and apply an alpha value in the texture. The result is what you see. The glow effect is pretty standard. I render the back-facing polygons to a texture. Next I draw the front-facing polygons as black, covering up any back-facing polygons where the alpha is opaque. I then do a standard blur and enhance. The glow texture is rendered into the framebuffer at a later stage.

Procedural Mesh Generation
Rather than rely on a high quality pumpkin mesh that would prolong the download, I decided to procedurally generate one instead. I also had plans to randomize the pumpkin shape to add diversity, but lack of time prevented me from completing this. Here’s a screenshot of the 3-step process.

proceduralPumpkin.jpg

You start off with a sphere. Next, proportionately sink the poles and surrounding vertices towards the centre of the sphere. If you want to see what this looks like in real-time, open up Blender 3D, create a UV sphere, and proportionally move the polls inward. You will see how the effect plays out. This will give you the top and bottom of the pumpkin. To generate the curves, navigate along the longitude of the sphere and sink every nth segment. You could use bumpmaps, yes, but that’s cheating :)

Procedural Texture Generator
The texture of the pumpkin was generated using my TexGen tool.

pumpkinTex1.jpgpumpkinTex2.jpgpumpkinTex3.jpg
It starts off with a lua script sin wave generator with turbulence. I used circular 4D simplex noise to make the texture seamless. I then applied Perlin noise and generated a normal map. The final result is then shaded and repeated along the x-axis 10 times. Voila.

That’s pretty much it. Feel free to post any questions or comments.

3 Replies

Please log in or register to post a reply.

6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Oct 17, 2011 at 10:25

Works great! And a nice coincidence, as I was just asked to carve a pumpkin this afternoon a few minutes ago :)

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 104 Oct 17, 2011 at 10:38

good nut! the artisticness is flowing.

A638aa42130293f319eda7fa4ba121f4
0
fireside 141 Oct 19, 2011 at 02:50

Nice job!