In front of me three ogre2.x article, the first roughly said the next Hlms, the second said the next and OpenGL combined with a relatively tight rendering, this article is used to say hlms how to affect the rendering process, because some concepts have been mentioned in the previous two, this article no longer mention, Finally, this is a detailed explanation of the Ogre2.1 rendering process.
passscene Simple ProcessThe first is all scene updates, and the scenario update contains the following content.
- Scene Animation _applysceneanimations
- All node Data update_all_transforms
- Skeletal animation update_all_animations
- Aabb of all models. (Objectdata) Update_all_bounds
- Aabb of all light sources. Update_all_bounds
- Generate a list of lights. Build_light_list
then the scene corresponds to the workspace-> synthesizer node (passscene)->rendertarget. Mainly cull the current model into the render channel.
- Update all models of the current scene (Objectdata) update_all_lods
- Sets the current scene shadow node.
- Cull (CULLPHASE01) of the current camera for the current scene. Cull_frustum, if the model is visible, is added to the render channel.
instead of starting normal rendering directly, you start rendering the shadow node. Because
- Get the projected shadow of the light source with the corresponding RTT. (The PSSM directional light source can correspond to a RTT greater than 1, typically with 3 RTT).
- Render each RTT. (before swapping the normal cull node, all shadow RTT rendering is complete before swapping back).
The whole process is almost like a paragraph in the note above Compositorshadownode.
This : Normal,_cullphase01 (), saveculledobjects (normal,Getscenemanager ()); Shadownode->setupshadowcamera (normal->getvisibleboundsinfo ()); Shadownode, _cullphase01 (); Shadownode,_renderphase02 (); Restoreculledobjects (normal,Getscenemanager ()); normal ->_renderphase02 ();
a normal renderingafter the shadow node renders, normal rendering takes the data above cull to start rendering (RENDERPHASE02).
- Mautoparamdatasource information fill This I remember is ogre1.x and RTSS need, Ogre2.1 should not need this.
- The FORWARD3D generated in the previous article, the global multi-source.
- Starts rendering to the render channel.
Hlms How to insert the rendering process
Hlms do in this process, first we first look at the relevant concepts.
in front of Ogre2.0 new features to create a new 3D engine, a brief introduction to the next Hlms, with macroblocks blocks, blendblocks blocks, and DataBlock blocks, is equivalent to a modular material.
Hlms backstage There are a lot of related such as (pbs,unit) template, corresponding to Ogremain in the Hlms class contains a lot of methods are used to parse the HLMS syntax rules of the function, related HLMS syntax see the previous link Ogre2.1 in the move value manual, such as @property, @end, @ foreach, @counter, @value, @set [Add,sub,mul,div,mod,min,max], @piece, etc. These grammars form the Hlms shader template code with common shader algorithms.
Renderablecache: There is a renderable, but not directly related to RENDERABL, in fact, there are two fields, a Hlmspropertyvec holds the value of the material attribute combination (if there is no tangent, the number of UV coordinates, normal map , illumination map, etc.), also a field piecesmap, simple point, Hlmspropertyvec to save the property and corresponding int value, int used to denote bool, the number of what, corresponding Hlms syntax is like @property, @foreach, @ Counter and so on, and Piecesmap used to save the property and the corresponding string value, simply speaking, is the above Hlms syntax @piece, can be said to be code snippets, Please refer to the above mentioned Ogre2.1 transplant document, and renderable of the hidden relationship is hlms to renderable Hlmsdatablock and Hlmspropertyvec to generate PIECESMAP, so specifically, should be Hlmsdatablo CK's cache.
Hlmscache before the Ogre2.1 efficient rendering, Renderablecache saved the template variable that generated the shader code, and Hlmscache saved the color code generated by the Renderablecache, where the hash is not just renderable rendering properties Combination, and also contains a combination of render attributes for the current Hlms type.
a Hlms resource is created.
As with ogre1.x, after creating the initialization window, we start to load the resources, but the difference is that we first need to register several hlms types like Hlmsmanager, such as Pbs,unit. Then load the resource file, encountered such as Hlms Rocks pbs{}, first began to parse the hlmsmacroblock,hlmsblendlock of these data, and then composed Hlmsdatablock, this can be understood, The original material is Material->technique->pass, now except the shader code part, such as the depth of the test what the full integration into a hlmsdatablock, Then it generates a hash of the hlmspbsdatablock corresponding to the HLMSPBS, and then adds it to Hlmsmanager.
second, when creating the scene, add the model into the scene.
Similar to ogre1.x, create entiy (renderable), set material, change this to create item (renderable), and then set Hlmsdatablock, Different original direct renderable under the association material finished, In Ogre2.1, Hlms need to put the current renderable into the Hlms call calculatehashfor calculation, the process can be seen as the first is based on Hlmsdatablock all the rendering settings added to Hlms, and then according to the MS Etproperties calls Addrenderablecache to generate the above mentioned Renderablecache and adds it to the list of Hlms and returns the current Hlms type (assuming PBS) A hash value that consists of the position of the current Renderablecache in the list, and then the Renderablecache and hash value that corresponds to the shadow RTT generated above, and returns two hashes of normal rendering and shadow RTT.
three frames per frame rendering.
This paragraph because and Ogre2.1 combined opengl3+ efficient rendering in the more repetitive logic, there is no more explanation, if you do not understand here, please go to this article has a more detailed description of the place.
First the camera performs cull, such as the above cullPhase01 this step, check whether the current model is visible, if visible, add into the render channel, in the channel wrapped into queuedrenderable[see above link], here to copy one paragraph, the following description, Retrieves all visible renderable. Depending on the renderable material (in this is Hlmsdatablock, the pass in the non-ogre1.x) generates a fragment number hash (for sorting, where the first material, then mesh), and the related renderable, Fragment number hash, the corresponding movableobject wrapped into queuedrenderable added to the thread render channel, merging all the current thread render channels into the current channel.
As in the previous rendering process renderPhase02 this step, before rendering the concrete model, for each hlms type (pbs,unit, etc.) to initialize a hlmscache, including whether to use forward rendering, if used, Then the current FORWARD3D in the properties of the corresponding hlmscache in the Hlmspropertyvec, as well as the number of light sources, directional lights, spotlights, the number of point light source is written in Hlmspropertyvec respectively.
The specific model queuedrenderable in the render channel is then started, with the above Hlmscache (Hlms type setting) based on Hlms::createshadercacheentry to generate the current renderable Hlmscache. Specifically, according to renderablehash[see above link] find the corresponding Renderablecache, the Renderablecache and Hlmscache (hlms type settings) in the Hlmspropertyvec combination together, and the corresponding piecesmap into the corresponding template (such as the PBS shader template) to generate the corresponding shader code, all the shader code into the final Hlmscache, and according to the corresponding hash[in the second step of the generated hash] into the Hlms list, when the same hash came in later , take the corresponding hlmscache directly, without having to generate the shader code again.
the commandlist in Ogre
Finally, let's see what Renderqueue::rendergl3 did, help us clarify the internal commandlist display composition, our example is to select the link in the example, the rendering mode with PBS, and remove the effects of light and shadows.
Simply put, there is a 4*4 model, where one diagonal is all spherical, and the rest is all cubes, where even rows use material rocks, odd lines use marble. Call Gldraw ... (Drawcall) The number of times only need two or four times, look at the hardware support, how to do, in Ogre2.1, as the 16 models added to the render channel, according to the material, model, etc. to generate the sort ID, such as the order is roughly rocks[sphere0-0, Sphere2-2,cube0-1,cube0-2,cube0-3,cube2-1 ...], marble[sphere1-1,sphere3-3,cube1-2,cube1-3 ...]. Then they commandlist the order and the command meanings.
The Hlms materials used are rocks and marble.
hlms Rocks pbs{ roughness 0.4 Fresnel 1.33 diffuse_ Map rocks_diffuse.tga normal_map rocks_normal.tga roughness_map rocks_spec.tga Specular_map rocks_diffuse.tga} hlms Marble pbs{ Roughness1.0 Detail_ Map0 mramor6x6.jpg detail_offset_scale0 0055 roughness_map mramor-bump.jpg}
Hlms Material
In general, the Commandlist list is in the following order, special cases are not discussed here, the rendering mode with PBS, and the effect of removing lights and shadows.
The Cb_set_macroblock setting includes a depth check in a piecemeal process, as well as a culling model and display mode.
Cb_set_blendblock settings such as alpha blending operations in piecemeal processing.
The cb_set_hlms_block corresponds to the above hlmscache, bound vertices, subdivisions, geometries, fragment shaders.
- Each of the following models enters the Fillbuffersfor, first, if you switch from another rendering mode to PBS rendering mode, it is good to understand each frame, because each frame renders a pattern before it starts rendering another. All commands from this to cb_set_texture are generally only in the first model into the fillbuffersfor call, and the rest of the models just update the data in the WORLDMATBUF.
Cb_set_constant_buffer_vs U0 Set the Passbuffer in the vertex and shader code as follows. Camera matrix p, view Matrix v.
//uniforms that change per passLayout (binding =0) Uniform passbuffer{//Vertex Shader (common to both receiver and casters)mat4 viewproj; //Vertex ShaderMAT4 View; //------------------------------------------------------------------------- //Pixel ShaderMAT3 Invviewmatcubemap; VEC4 Ambientupperhemi; VEC4 Ambientlowerhemi; VEC4 Ambienthemispheredir; Light lights[1]; } Pass;View Code
cb_set_constant_buffer_ps U0 set Passbuffer, code ibid.
Cb_set_texture_buffer_vs T0 Adds a tbo that is used to save the model matrix.
0) uniform samplerbuffer worldmatbuf;
Worldmatbuf
- Set Worldmatbuf, simply, save enough model matrix, in general, each frame, worldmatbuf only need one set, the subsequent Drawcall share this TBO, Each instance in each DRAWCLL is positioned by baseinstance and divisor.
- Baseinstance: As above example 16 models, the model of baseinstance that is from 0-15, wherein the rocks material, the first two balls of the same instance, a ball baseinstance 0, the back of a ball only need parameters of the instance plus 1 for 2, Then 6 cubes of the same instance, re-add a parameter, the first cube of baseinstance starting from 2, the back of the cube only need to update the instance parameter is 2 to 7. Then the marble material, such as the first two balls the same instance, baseinstace starting from 8, the back of the ball is instance 2, then the cube baseinstace from 10, the back of the cube only need to update the instance parameter 2 to 7.
cb_set_constant_buffer_ps U1 Set Materialbuffer, the PBS rendering properties for each model, such as Fresnel (Fresnel coefficient), roughness (roughness), etc. This ubo saved a list of the properties of the PBS, combined with the class Constbufferpooluser to see the corresponding source code.
//uniforms The change per item/entity, but the change very infrequentlystructmaterial{/*KD is already divided by PI to make it energy conserving. (Formula is Finaldiffuse = Ndotl * surfacediffuse/pi)*/VEC4 KD;//KD.W is Alpha_test_thresholdVEC4 KS;//KS.W is roughness//Fresnel coefficient, may be per colour component (VEC3) or scalar (float)//F0.W is transparencyVEC4 F0; VEC4 normalweights; VEC4 cdetailweights; VEC4 detailoffsetscaled[4]; VEC4 detailoffsetscalen[4]; UVEC4 Indices0_3; //uintbitstofloat (INDICES4_7.W) contains mnormalmapweight.uvec4 indices4_7;}; Layout (Binding=1) uniform materialbuf{Material m[273];} Materialarray;Materialbuf
Cb_set_constant_buffer_vs U2 Instancebuffer, a common indication of the index in Materialbuffer.
//uniforms that change per item/entityLayout (binding =2) Uniform instancebuffer{//. x =//The lower 9 bits contain the material ' s start index. //The higher bits contain the world Matrix start index. // //. y =//Shadowconstantbias. Send the bias directly to avoid an//unnecessary indirection During the shadow mapping pass. //must is loaded with UintbitstofloatUVEC4 worldmaterialidx[4096];} instance;Instancebuffer
Cb_set_constant_buffer_ps U2 Instancebuffer, code as above. Each model updates the data in Instancebuffer, which is usually updated in PS.
Cb_set_texture_buffer_vs T0 because you want to add data for the current model matrix, check if you need to reapply for a TBO, the first time each frame comes in need to call this.
- When the material changes, in general, these are to be reset
Cb_set_texture setting textures such as rocks_diffuse.tga above the material
Cb_set_texture setting textures such as rocks_normal.tga above the material
Cb_set_texture setting textures such as rocks_spec.tga above the material
Cb_texture_disable_from setting the current activation texture to 0
Cb_set_vao vertex data, position, normal, index, etc.
Cb_set_indirect_buffer Drawcall parameter, as in the example above, there are 8 models with a material, then this parameter records the Drawcall parameters of these 8 models.
- Below, draw eight models at a time above the rocks material
cb_draw_call_indexed_emulated Well, this computer does not support indirect DRAW, so choose this drawcall function, as in this example, the rocks material has eight models, two of which are balls, 6 are cubes, If indirect draw is supported, this command is cb_draw_call_indexed, which contains only one drawcall, but not the cb_draw_call_indexed_emulated under skill indirect, It contains two times drawcall.
- Start drawing eight models under the marble material.
The cb_set_hlms_block corresponds to the above hlmscache, bound vertices, subdivisions, geometries, fragment shaders.
Cb_set_texture setting textures such as mramor6x6.jpg above the material
Cb_set_texture setting textures such as mramor-bump.jpg above the material
Cb_texture_disable_from setting the current activation texture to 0
Cb_set_vao vertex data, position, normal, index, etc.
Cb_set_indirect_buffer Drawcall Parameters
- With the above, one at a time to draw eight models under the marble material above
cb_draw_call_indexed_emulated
To put it simply, each frame goes into PBS rendering, only the first model calls Fillbuffersfor to initialize the corresponding Ubo and TBO, and the subsequent model call fillbuffersfor generally only updates the data stored in the TBO of the model matrix and the Ubo that holds the material index, When the material is switched, it is generally only re-binding texture, vbo,drawcall parameters, the corresponding state switch, such as macroblock,blendblock in this example only did not happen to switch.
The new synthesizer looked under, although the introduction of some new concepts, but the basic concept of the pass, and the use of Hlms, or the use of old materials to do special effects, this part with Hlms also meaningless, because the full-screen effect is a pass, no hlms integration of multi-pass efficient meaning. More important such as Passquad and Passscene or the same, a RTT, an RW, added such as passdepthcopy can use some pre-depth effects. The rest are some combination, also do not re-say, interested classmates can see me write Ogre1.9 synthesizer analysis.
Ogre2.1 Hlms and rendering process