Demo: Green Dragon

Articles with the tag: Shaders

CharSim: release and summary

System architecture for version 001

What I planned in the spec is now complete and ready for release. The GLSL shaders now work at version level 120 (compatible with OpenGL 2.2) in order to support older graphics cards.

What has been the point of the project?

  • Am familiarised with 3D APIs and shaders.
  • Have explored and incorporated third-party libraries.
  • Learn and apply knowledge of mathematics and algorithms for a technical animation framework and basic game engine.
  • Handle debugging using exception handling and gdb.
  • Designed an object-oriented framework model.
  • Used C++ standard library tools (smart pointers to automatically refcount resource objects, lambda functions and their relation to STL algorithms, vectors, lists, maps, iterators).
  • Explored C++ design patterns (abstract classes used as interfaces, compositing and inheritance patterns).
  • Have worked with the distributed version control system Git for revisions and distribution.

Of course there are many features I still want to explore ...

Read More »

Facial expressions: shader-based vertex morphing

Blending normals and positions with linear interpolation (LERP). It seems to look good.

LERP: (startPos + factor*(endPos - startPos));

GLSL Vertex Shader example:

vec3 morphPosition = vertexPosition;
morphPosition = (morphPosition + morphWeight0 * (morphPosition0 - morphPosition));
morphPosition = (morphPosition + morphWeight1 * (morphPosition1 - morphPosition));

To reduce shader computation, the (endPos - startPos) calculation can be performed on the morph target vertices before they are transferred to the device.

Vertex Shader example after optimisation:

vec3 morphPosition = vertexPosition;
morphPosition += morphWeight0 * morphPosition0;
morphPosition += morphWeight1 * morphPosition1;

Rough animation test mixing blend shapes (the mouth movement) with pre-animated armature animation (the bobbing), both interpolated using smoothstep interpolation:

And with skeletal IK animation:

Read More »

Character animation: vertex morph targets

For animation purposes, the ModelNode for the dragon character will contain a set of morph weight factors relating to the number of possible morph targets (key shapes) that have been generated for the character's expressions.


std::map<std::string, float> _keyFac;
_keyFac["MouthOpen"] = 0.5f;

The shader has a limited number of morph targets it can use (currently 2, but it can be increased to 5) so it is up to the animation update logic to choose which expressions to send to the Renderer.

If 5 expressions are used, a fair amount of artistic control can be provided. For example, three morph targets can be used for broad facial movement such as "Smile", "Frown", and "Blink" while the two remaining slots can be used to blend phoneme movement for speech animation.


std::map<std::string, uint> _keyId;
// The key's ID relates the morph mesh ...

Read More »

Character animation: facial expressions

While idle motion based on armature animation can be done, other idle motions such as blinking and mouth movement depend on mesh morphing and blending.

Blending the three: IK, armature animation and face morphing should just be a matter of combining transformation matrices and providing the necessary arrays of data to the shaders (providing this data is discussed below).

Because the dragon character's face is not warped by the armature motion, it shouldn't matter whether the mesh is warped before or after the other animations.

On face morphing:

(Assuming three meshes are generated for the dragon representing its (currently) two morph targets (what Blender calls "Shape Keys") plus a base mesh: BasisMesh, BlinkMesh and MouthOpenMesh.)

The meshes could be interpolated on the CPU (the host) and the resulting vertex array be uploaded to the GPU (the device) each frame. This would be computationally expensive for a game scenario ...

Read More »

Lighting and shading the character model

Cool, but not what I want (using the geometry shader)

Aaand success: the shader-based skinning is complete: vertices and normals are transformed.

[09/06/14 12:25]

Let's try a simple (e.g. Lambert + Phong) shader.

Fantastic. Now let's add UV texturing, then the CameraNode can be set up.

[09/06/14 15:59]

Seeing if armature animation code still works with dragon mesh - it may need updating.

Creating a small looping idle animation for the dragon character rig in Blender:

Playing the test animation in game engine:

It works!

Now it just needs to be made blendable with simulated motion for more realistic idle dragon motion (such as swaying) while the player interacts with the character.

Some interpolation (such as smoothstep) should be used to make the looping animation smooth as it bounces between keyframes.

Read More »

Shaders and lighting

Shadow maps should only be used on dynamic objects and lights.

[05/02/14 14:10]

Can draw arbitrary points using glDrawArrays(GL_POINTS, 0, 1); which could be useful for a raytracer. Then again, it'd be better to manipulate a texture buffer and display that.

This is, however, good for graphing: draw points, but don't clear.

Material inputs

[05/02/14 15:16]

From above link:

"With traditional lighting model, there is often a RGB diffuse texture, RGB specular texture, specular mask texture, constant specular power and normal map."

"For advanced material you can add specular power texture, Fresnel intensity texture, Fresnel scale texture, reflection mask texture..."

[05/02/14 15:29]

Shader requires a diffuse texture.

  • Node -> Contains object-specific textures.
  • Material -> Contains shader.

[05/02/14 21:54]

It would appear that one uses the uniform keyword for standard inputs to shaders such as time. Should this ...

Read More »

Page 1 / 2 Older »