Archive

Author Archive

Another year, another blog

I have just created a new blog for my GSoC 2011 project, regarding “Real-Time Volumetric Shadows for Dynamic Objects”. At the end of this project I should be able to obtain a more realistic hair rendering as well, by using self-shadowing.

You can check it out at: http://volumetricshadows.wordpress.com/

Advertisements

GSoC YouTube channel video

I recently made a video for the GSoC YouTube channel.

I included all the main features the fur plugin support:

  • Colliders
  • Enabling / Disabling physics
  • LOD
  • Geometric properties
  • Materials
  • Diffuse Type
  • Alpha / Color

Here is the video (hopefully you will be able to see it on the GSoC YouTube channel in no time):

Diffuse reflection

I managed to include diffuse reflection in the fur plugin, and now the lighting model is similar to Phong shading and the specular highlights are done either using Kajiya and Kay or Marschner shading models.

Here is a video of the results:

Fur rendering

Even though GSoC 2010 has ended, I still wanted to add some features to further improve the fur plugin, such as support for animating fur, and rendering fur with Kajiya and Kay shading model.

Presenting was once again Frankie the squirrel:

Categories: Crystal Space Tags: , ,

GSoC final deadline

The final GSoC deadline is tomorrow, or rather the firm ‘pencils down’ date, so I have decided to make a really short self-evaluation of the features I’ve managed to implement.

Done :

  • Generate geometry – iFurMaterial (until the midterm)
  • Animate geometry – iFurPhysicsControl (until the midterm)
  • Write specific shaders – iFurStrandGenerator (until the midterm)
  • External parameters – density and height maps, 3D textures, etc.
  • LOD system and optimizations – iFurMesh inherits from iMeshObject
  • Extend from hair to fur – thanks to Frankie the squirrel

There is still some code rearranging to be done, but nothing much, really: deciding what classes should inherit from what interfaces, making loaders and savers for the mesh, just better organizing the code.

I leave you with this footage of the CS fur plugin as it is now (the FPS is actually double than in the video and above 60 on release settings and ~30 FPS on debug):

Categories: Crystal Space Tags: , , ,

Textures

In order to obtain really nice visuals adding texture support to the hair plugin was a must do.

However if we think about it, a hair mesh texture might have up to three dimensions, rather than just two. This is because hair strands can vary from root to tip (especially if you dye your hair) and can vary from strand to strand (like hair stripes). But having in mind that it is much easier to specify just a 2D texture (UV map of the base mesh) and extremely useful for fur, which don’t tend to vary from root to tip at all, I made two ways of defining textures for the fur plugin.

  • 2D textures

For this type of textures only a UV map is needed, so fur strands will have the same color for the whole length of the strand. The color is of course equal to the value of the RGB pixel specified by the UV coordinates. Here is an example in CS of such a 2D texture used for Frankie (from Yo Frankie!):

  • 3D textures

This is not a usage of 3D textures per se, but rather a simulation of using such textures. In order to keep things simple for the user, only two 2D textures have to be specified. A grayscale UV map that will be scaled from (0, 255) to (0, 1) and whose value will be used as the X coordinate of the second texture, while the Y coordinate is the length of the hair. An example of such textures for Krystal are:

Having the following result:

LOD

As you have probably seen from my previous YouTube videos, the FPS in the fur plugin isn’t quite real-time, but about ~10 FPS.

After doing some manual profiling (i.e. not using any profiling tool, but just commenting code and analyzing the average FPS in various situations), I came out with the following findings regarding the fur mesh plugin:

  • Hair simulation
Number of Guide Hairs 0 50 100 200 367
Average FPS 46.07 37.70 32.63 24.76 18.76

Because I used Bullet ropes in order to simulate the physical model for guide hairs, I couldn’t really optimize the code to get better performance, so the only option was to generate as few Bullet ropes as possible, for the lowest LOD and also, not to many for the highest LOD setting.

This is why I made two types of guide hairs: pure guide hairs and LOD guide hairs. The pure guide hairs always have a Bullet rope attached, they represent the lowest LOD setting and grow on each vertex of the base mesh. On the other hand, LOD guide hairs are only synchronized with ropes at higher LOD, otherwise their position is updated just like for normal hair strands, using interpolation and barycentric coefficients.

So in order to have really good results, having a low poly mesh on which to grow fur is essential, and this can be done either by having a fake low poly mesh specified in the model file, or better yet, by obtaining a low poly mesh using the LOD system from another CS GSoC 2010 project, by Eduardo Poyart.

  • Hair modeling
Number of Hair Strands 0 500 1000 2000 3670
Average FPS 49.34 31.56 23.12 15.41 10.53

When I collected this data for hair modeling I was using a genmesh to represent the fur geometry. The problem was that when I called functions to compute normals, tangents or binormals followed by a call to Invalidate() the FPS was really low for thousands of hair strands. However, I realized that I can easily compute all this data having in mind that the hair strands are created so they always face the camera. Furthermore, doing some C/C++ optimizations by increasing pointers, instead of iterating through vectors, gave some performance boost as well.

And of course, when the camera is situated further away from the fur mesh, having a low LOD setting, which draws fewer, thicker hair strands seemed a good idea. The only trick was to generate the hair strands in such a way that they always cover the base mesh (skull) and as they grow in number they give the impression of more dense hair.

  • Hair rendering
Number of Hair Strands 0 500 1000 2000 3670
Average FPS 49.12 47.34 45.82 44.06 40.26

After testing the hair rendering data with both the Marschner implementation and a simple default CS Phong shader, I realized that the hair rendering didn’t need any more optimizations nor various LOD versions. The optimizations done by using lookup textures, as described in the Marschner Shader Part III post, provide good results by themselves.

  • Overall
Number of Guide Hairs 0 50 100 200 367
Number of Hair Strands 0 500 1000 2000 3670
Average FPS (1024×768) 47.62 26.07 17.96 11.15 7.56
Average FPS (1440×900) 49.12 26.82 18.62 11.24 7.66

So, by making all of these optimizations and various LOD settings I managed to run the hairtest demo at a constant ~28 FPS at the lowest LOD and at ~15 FPS at the highest LOD setting.

Also, I realized that although sometimes a hair simulation will not be needed, animating the hair would still be a good idea, so I wrote an implementation of the iFurPhysicsControl that only updates guide hairs based on the base mesh movement, and also added the possibility to switch between various iFurPhysicsControl implementations on the fly. Not having Bullet ropes at all made the application run at ~37 FPS for the lowest LOD setting.

Categories: Crystal Space Tags: , ,