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:
- Use agalminiassembler. assemble2 to assemble the shader;
- Use stage3d requestcontext3dBaseline_extendedAttribute;
- 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;
- 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;
- In beta, the corresponding depthstencel buffer cannot be set for the corresponding rendertarget;
- For the texture input in stage3d, it must be read from the agal shader; otherwise, the final rendering result (subsequent shader) is incorrect;
- 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.