OGRE 3D 軟體工程與哲學

My OGRE 3D working journal vol.5

Sample_DynTex
The sample is pretty impressive to me, because it generates an elegant scene by simply using dynamic texturing and particle system.

First I need to clarify that particle system is for snowing, dynamic texturing is for the effect that the user wipes the frost off the window pane. And the above two are independent.

# TextureManager::getSingleton().createManual creates a dynamic texture, “thaw”.

# mSceneMgr->createParticleSystem creates a particle system “Snow”, w/ template name “Examples/Snow”, which is in “file media/particle/Examples.particle”.

# mSceneMgr->createEntity creates an entity “Plane”, w/ material “Examples/Frost”, which is in “media/materials/scripts/Examples-DynTex.material”, where there are 2 textures: “frost.png”, “thaw”.

I have a few thoughts from this sample. In many elegant scenes, the base graphics techniques are actually simple, but why can some people use them well to generate beautiful results? First it’s about experience and knowledge. For example, to achieve a required scene I know that I can try “method A” and “method B”, and I can refer to what I did in “case A”. Second it’s about details. Take the sample for example, it does an effect that a user wipes less frost when the frost is far away from the mouse cursor, and this effect makes users feel natural (compared to wiping in a clear track).



Sample_FacialAnimation
The sample uses “facial.mesh”, which has an animation “Speak”, and many prepared poses. The sample also create an  animation “Manual” in run-time. The poses includes:
Expression_neutral
Expression_happy
Expression_sad
Expression_mad
A_ShapeKey
U_ShapeKey
O_ShapeKey
E_ShapeKey
I_ShapeKey
C_ShapeKey
W_ShapeKey
M_ShapeKey
L_ShapeKey
F_ShapeKey
T_ShapeKey

When a user operates the GUI, mManualKeyFrame->updatePoseReference is called to adjust the weighting of each pose.

The animation system in OGRE:
http://www.ogre3d.org/docs/manual/manual_75.html#Animation
The “Manual” animation in this sample should belong to the pose animation in the vertex animation.


Sample_Fresnel
A nice scene. The objects under the water have the effect of refraction; the walls around have the reflection of water.

# create 2 render target textures, w/ names “refraction”, “reflection”.

# create entity “Water”, plane mesh, w/ material “Examples/FresnelReflectionRefraction”, where there are 3 textures: “waves2.dds”, “reflection”, “refraction”.

# create entity “UpperBath”, w/ mesh “RomanBathUpper.mesh”, which is in “media/packs/fresneldemo.zip”. One of the sub-mesh materials is “RomanBath/BlueTile”, which is in “media/packs/fresneldemo/RomanBath.material”, where there is animated texture: “anim_texture caustic.png 32 5“. The reflection of water on the walls is made by this.

# The water surface is made by blending two dynamic textures. Making the reflection dynamic texture needs to change the perspective angle: mCamera->enableReflection(mWaterPlane).

# By http://www.3drender.com/glossary/fresneleffect.htm
Fresnel effect is “the amount of reflectance you see on a surface depends on the viewing angle.”
In “Examples/FresnelReflectionRefraction”, the shader uses Fresnel factor as the proportion of blending reflection and refraction textures.


Sample_ParticleGS
When I ran the sample, a message box popped up:
“Your render system / hardware does not support geometry programs, so you can not run this sample.”
Temporarily leave the problem unsolved.

# create particle system “ParticleGSEntity”, w/ material “Ogre/ParticleGS/Display”, which is in “media/materials/scripts/ParticleGS.material”.

# create and set an Ogre::ManualObject “ParticleSeed”.

# create and set a RenderToVertexBuffer object, w/ material “Ogre/ParticleGS/Generate”, which is in “media/materials/scripts/ParticleGS.material”.

# create and set a bounding box (Ogre::AxisAlignedBox).

# Both “Ogre/ParticleGS/Display” and “Ogre/ParticleGS/Generate” refer to the shaders in “media/materials/programs/ParticleGS.cg”, where the geometry shader “DisplayParticles_GS” is for display. This is a nice technique of sprite rendering (compared to computing the positions of N sprites in CPU, and drawing them one by one). Besides, the geometry shader “GenerateParticles_GS” is for particle splitting. When I was in school, I did a project about designing the splitting of particles to achieve the effect of smoke, but the computation was in CPU. The geometry shader way is more advanced.

# Another point of the sample: Ogre::RenderToVertexBuffer and Ogre::ManualObject do 2 pass rendering.

The class diagram of Sample_ParticleGS:



Sample_Grass
# create entity “Ground”, w/ plane mesh, material “Examples/GrassFloor”, which is in “media/materials/scripts/Examples.material”. A simple decal texturing material.

# create mesh “grass”, w/ material “Examples/GrassBlades”, and then entity “Grass”. The way of writing vertex/index can be referred to in createGrassMesh. “Examples/GrassBlades” uses “Grass.cg”, and the effect of grass waving is achieved here in the vertex shader.

# create Ogre::StaticGeometry, w/ name “Field”. About Ogre::StaticGeometry:
http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Intermediate+Tutorial+5

# The effect of fireflies in the grass is achieved by sprite (in OGRE, it’s billboard and flare material). The moving track is spline animation track (see the sample of Camera Tracking). Another point is to use a controller to dynamically adjust the lightness and sizes of the billboards. This is about taking care of details to achieve a beautiful scene.


Sample_Instancing
The sample uses Geometry Instancing to render a large amount of objects, and also compares Instanced Geometry, Static Geometry, with Entity Geometry (directly draw N entities).

The remarks of Ogre::StaticGeometry:
http://www.ogre3d.org/docs/api/html/classOgre_1_1StaticGeometry.html#details

The remarks of Ogre::InstancedGeometry:
http://www.ogre3d.org/docs/api/html/classOgre_1_1InstancedGeometry.html#details


Sample_Isosurf
The metaball effect using vertex / geometry shaders.


Sample_Lighting
A nice sample. It uses render priority and hardware occlusion query to adjust the lightness of the light flares when they are partially/fully occluded.

An introduction of hardware occlusion query:
http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter06.html


Sample_NewInstancing
Demonstrates how to use Ogre::InstancedManager, which is supposed to be an advanced way compared to the methods in Sample_Instancing.

In Sample_NewInstancing::switchInstancingTechnique,
– create mCurrentManager (Ogre::InstanceManager), w/ name “InstanceMgr0”, mesh name = “robot.mesh”, technique = InstanceManager::ShaderBased.

Sample_NewInstancing::createInstancedEntities calls mCurrentManager->createInstancedEntity 50×50 times, which creates 50×50 Ogre::InstancedEntity(s).

The sample can switch materials. One set of the materials:
static const char *c_materialsTechniques[] =
{
    “Examples/Instancing/ShaderBased/Robot”,
“Examples/Instancing/VTF/Robot”,
“Examples/Instancing/HWBasic/Robot”,
“Examples/Instancing/VTF/HW/Robot”,
“Examples/Instancing/VTF/HW/LUT/Robot”,
“Examples/Instancing/ShaderBased/Robot”
};

mapped to (c_materialsTechniques[3] and c_materialsTechniques[4] are both mapped to HWInstancingVTF)
enum InstancingTechnique
{
  ShaderBased,           //Any SM 2.0+ @See InstanceBatchShader
TextureVTF,            //Needs Vertex Texture Fetch & SM 3.0+ @See InstanceBatchVTF
HWInstancingBasic, //Needs SM 3.0+ and HW instancing support @See InstanceBatchHW
HWInstancingVTF, //Needs SM 3.0+, HW instancing support & VTF @See
                                     //InstanceBatchHW_VTF
InstancingTechniquesCount
};

The official article about Ogre::InstancedManager:
http://www.ogre3d.org/forums/viewtopic.php?f=4&t=59902

Vertex Texture Fetch (VTF) related:
http://www.ogre3d.org/docs/manual/manual_24.html

The implementation and meaning of each technique/material pair are not investigated here. Leave them for future research.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。