Deferred shading in flash with stage3d

Source: Internet
Author: User

Not long ago, we got a beta version of Flash Player 11.6, with many new features added, such as good support for MRT. With the most direct advantage of MRT, you can achieve the popular deferred shading on stage3d. Not long ago, I made some attempts and finally implemented them. The results were good.

Set the device-related functions of the MRT:

Context3d. setrendertotexture (texture: texturebase, enabledepthandstencel: Boolean = false, antialias: Int = 0, surfaceselector: Int = 0, coloroutputindex: Int = 0): void

The difference is that the last parameter coloroutputindex is used to set the color output channel of render texture in the MRT (the number of available channels is the same as that obtained in d3d or OGL, that is, the number of hardware supported ).

It also supports floating point textures while supporting MRT, or it cannot be used to obtain the corresponding G-buffer. To create a float texture, you only need to use

Context3dtextureformat. rgba_float

As the format description of the texture (or rgba_half_float), the storage and compression of the specific G-buffer in two floating point textures can be appropriate according to the actual situation.

The final implementation effect is as follows:


Here are some precautions for using the MRT:

  1. Use agalminiassembler. assemble2 to assemble the shader;
  2. Use stage3d requestcontext3dBaseline_extendedAttribute;
  3. After setrendertotexture is used to set the corresponding render target, call setrendertotexture (null,..., 1) in time to close the corresponding MRT output and set the output to backbuffer in time;
  4. The texture in the rgba_float format can only be accessed in the shader. Otherwise, the texture in the bitmap format will still be processed when the traditional pipeline is used by default, resulting in incorrect rendering;
  5. In beta, the corresponding depthstencel buffer cannot be set for the corresponding rendertarget;
  6. For the texture input in stage3d, it must be read from the agal shader; otherwise, the final rendering result (subsequent shader) is incorrect;
  7. After rendering, settextureat (index, null) should be used to reset the texture channel;
However, there are still a lot of bugs and pitfalls in the current beta version. I believe that the official version that will be fixed soon will be released soon.

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.