Chapter 1 Dynamic shadow of book notes in Pro Ogre 3D Programming

Source: Internet
Author: User

Shadow technology
Ogre supports two mainstream dynamic shadow technologies: stencel shadow and texture shadow, each of which has two variants: modulative and additive. These four technologies are fully compatible with fixed function graphics pipelines and therefore do not require programmable GPU support. However, the GPU program can be used for acceleration. Only one Shadow technology is used in the scenario. You should set the Shadow technology before rendering the scene (preferably between the scenario manager creation ). You can call SceneManager: setShadowTechnique () to set the technology. Parameters specify the specific type of the technology. Shadow is disabled by default. For objects, the projection and receiving shadows can be controlled in the material, or the objects can be controlled to project themselves. Because of the essential features of the template shadow algorithm, transparent and translucent objects either completely cast solid shadows or do not projection shadows at all, and do not obtain translucent shadows. The texture Shadow technology can be used. The light cannot be used to cast shadows.
Template shadow Algorithm
The template shadow algorithm is relatively simple in principle: From the Perspective of the light source, an object that can cast shadows can see the outermost contour of the object.
Shape, extending the contour along the direction of light to form a space body, called shadow volume. Obviously, if
An object is surrounded by this shadow cone, so this object is in the shadow projected by the previous object. Since the shadow cone grows by means of extension, you can control the extension range of the cone in the extension direction. In the direction of extension, one end cannot be extended, and the other end can be extended according to the following two rules. First, if programmable graphics hardware is used, the vertex program can extend the vertex infinitely. Second, if a fixed function graphic pipeline is used, the extended range is set by light attenuation (point light source and spotlight) or used
SceneManager: setShadowDirectionalLightExtrusionDistance () to control. When no accelerated graphics hardware is used, we should try to avoid an object from being too close to the light source. This will produce a shadow cone that is too wide, leading to incorrect shadow effects. According to the algorithm principle, the shadow boundary is very obvious: a pixel is either in the shadow or not. The advantage of this is that the accuracy is not affected even if the shadow Cone has a long extended distance. It can be said that the shadow produced by this technology is a "hard shadow ". Texture Shadow technology can "soften" shadows. Edge lists is required to use the template Shadow technology. The standard conversion tool creates an edge list when generating a binary mesh file. If no edge list is available, the following Mesh can be used in the program :: buildEdgeList. Sometimes, we use code to generate the mesh. If we want to use the template Shadow technology, we need to ensure that the edge list data is generated. If the edge list data does not exist, ogre will think that you do not want this object to cast a shadow.
Template shadow Optimization
Ogre can be optimized in general. For example, you can use hardware acceleration to check whether the optical head is intercepted by the direction and range of the light.
(Frustum) has an impact, avoiding Calculation of unnecessary shadow Ry from the surface. Ogre supports dual-sided templates and stencel-wrapping extensions,
These can prevent unnecessary prototype setup and driver overhead ). Ogre uses a relatively cheap Z-pass algorithm to replace the Z-Fail algorithm (when the Z-Fail algorithm is not necessary, if the camera is in a shadow cone, there will be problems using the Z-pass algorithm, in this case, use the Z-fail algorithm ).
The Shadow cone is not affected by the closed ry. In,

Guards are projected onto the floor and within the projection range there is a closed box (in this example, the box is set not to cast a shadow ). Based on the experience of the real world, there will be a guard shadow on the box, as shown in. But the light should not move forward after it passes through the box, that is to say, the shadow cone should not be extended after it passes through the box, as a result, no guard shadow should appear on the floor behind the box (the shadow of the box appears in the real world, but in this example, no shadow is set for the box ). The shadow cast by guard appears on the floor, which means that the shadow will not be affected by objects on the Extended Direction.
Objects that cannot be seen on the screen can also be projected into a visual frustum. These objects are invisible.
They must also be rendered to obtain shadow-related data. When hardware acceleration is not used, try to avoid the close of the object to the light source.
Texture shadow
The basic principle of the texture shadow algorithm is: first, observe the scene from the perspective of the light source and render the observed result to a texture. Only the texture is saved.
Depth value (Value in the depth buffer ). In this way, the shortest distance between the object and the light source in the scene is saved in the texture. Then, the normal Rendering scenario is performed from the camera's perspective, the distance between each pixel and the light source is calculated, and the value corresponding to the texture is compared. If the value is greater, it means that it is not the closest to the light source in the direction of light, and there will be shadows. /* It may be a bit confusing. How can each pixel to be tested correspond to one-to-one pixels in the texture? Based on the principle of generating a texture chart, we need to convert the coordinates of the test vertex to the space where the light source is the viewpoint. That is to say, from the light source perspective, we can see where the vertex should be. In this way, we can compare them one by one. Of course, this is only for the purpose of comparison. During real rendering, the vertices must be first converted to the video space (from the camera's perspective )*/.
The texture shadow speed is faster than the template shadow algorithm, but because the shadow is rendered to the texture, the texture has a definite resolution. Therefore, when the shadow is extended and stretched, the effect will be poor, such as generating a sawtooth edge.
Because the texture memory is used, its size determines the maximum number of texture shadows. In ogre, you can manage the number of shadow textures that can be used in a frame: SceneManager: setShadowTextureCount (). Each light source requires a texture. If the number of specified textures is less than the number of light sources, ogre uses the "first come first served" principle to allocate textures. If you cannot increase the texture size to improve the visual effect, it is best to reduce the distance of the projection shadow. The shadow does not end suddenly. ogre fades out the edge of the texture shadow to prevent the violent transition between shadow and shadow. The fading radius can be controlled.
Modulative shadow Hybrid
In normal scenarios, the rendered color is multiplied by the shadow color to create a dark color that represents the shadow. This method removes the effect of illumination from the rendered scene. The shadow area is dimmed, regardless of the number of light that enters the shadow area. When multiple light sources generate a shadow area
When overlapping, the shadow is very dark and the visual effect is poor.
Additive Shadow Masking
The Modulative method is implemented by affecting the shadow area. The Additive method only affects the area in the light, but does not affect the shadow area.
There is an impact. In this way, the shadow area is slightly brightened by other light sources, and the overlapping shadow area is not darker.
Ogre divides a channel into three channels.
Ambietn, the application environment light in the scene, in this channel no texture is rendered.
Diffuse and specular: This channel renders each lamp once, and the shadow area of the current lamp is not affected. Other regions and scenarios are mixed. Similarly, no sticker texture is used.
Decal. The texture is applied to the accumulated color.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.