A perfect shadow solution for 2.5D games based on ogre

Source: Internet
Author: User

This is a solution I used to upgrade the Ogre engine. I would like to share my experience with you.

Every programmer proficient in ogre will be disappointed with the Shadow solution that comes with ogre. Whether it is a template shadow or a projection shadow, it is a shadow of a fixed rendering pipeline, and the effect is not good.

Changyou "tianlong Babu" has been upgraded to 3, and uses the previous shadow solution, which indicates that it is really difficult to find an ideal solution to replace the previous one.

The tianlong solution is to use a template shadow for a character, and then use a static Paster shadow to paste the shadow. The effect is average. This is the practice of many games in the past. Since the template shadow is based on model vertices, Alpha test cannot be supported.

The shadow of the model with Alpha test, leaf, cannot be used. However, the accuracy of the static lighting image determines that the effect on the tree model is very poor, and does not support self-projection,

The projection shadow has three defects, such as reverse projection, no self-projection, and projection interspersed with terrain. It is not practical and has been abandoned by tianlong for a long time.

The Shadow solution of fixed pipelines will be eliminated sooner or later, while the shadow map Technology Based on shader is a mainstream advanced Shadow technology.

There are too many technical branches of shadow map, and there are dozens of them, but each technology is imperfect and there are various problems. VSM and CSM are used for the next generation of games abroad.

I want to consider the premise efficiency. Efficiency must be the first priority. In China, the development engine has no applicable value for any Nb effect.

I chose the traditional depth shawow map based on the actual situation of my 2.5D lock perspective game.


There are many problems with the traditional shadow, and many technologies are required for improvement to have practical value.

For example, the shadow Accuracy Problem, the edge sawtooth, and some perspective shadow samples.

Methods to Improve quality:

1) The camera focuses on the visible area to improve the shadow accuracy.

2) The Shadow texture size is 1024 or 2048 to improve the accuracy of the shadow.

3) since we can't see a long distance, we can control the shadow distance and improve the shadow precision again. If we can see a long distance in a pure 3D game scenario, we need to replace it with the PSSM technology.

4) 4x4 PCF filters to implement simple Soft Shadows and eliminate stiff edges.

5) gradient-based depth offset is used to reduce self-projection Samples

Methods to Improve efficiency:

1) only the shadow of a single light source is supported, so you do not need to iterate each light source. Instead of adding, you only need to add a texture unit instead of a rendering pass when shadow decals are used.

Because of a pass, the shadow and fog can be perfectly combined.

Other problems to be solved

1) cast and accept shadows of Alpha test models like trees.

Shadow quality is satisfactory, and supports self-projection, Alpha test bamboo, and shadow. The above effects are all tested in my laptop using the terrain editor.

In terms of efficiency, compared with the traditional projection shadow, it is also used to render a shadow. In terms of decimal, no rendering batch is added, and the material script is also simple.

// 2012.12.5 luoyinan // shadow cast material floating point texture material ogre/depthshadowmap/caster/float {technique {scheme shadow_map pass {fog_override true none else ogre/else/castervp {} upload ogre/ depthshadowmap/casterfp {}}}// basic self-projection Material material ogre/depthshadowmap/material {technique {scheme shadow_map pass {// vertex program reference extends ogre/depthshadowmap/release {} // fragment program implements ogre/limits {} texture_unit {content_type shadow extends border limit 1 1 1} texture_unit {limit <basetexture >}} technique {pass {diffuse vertexcolour texture_unit {texture_alias <basetexture >}}// supports Alpha test and double-sided shadow self-projection materials, material ogre/Tables {technique {scheme shadow_map pass {alpha_rejection greater 128cull_hardware NONE // vertex program reference extends ogre/Tables {}// fragment program extends ogre/Tables {} texture_unit {content_type shadow extends border limit 1 1 1} texture_unit {limit <basetexture >}} technique {pass {diffuse extends greater limit none texture_unit {limit <basetexture> }}}}

CG files are currently kept confidential.

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.