查看: 2488|回复: 0
打印 上一主题 下一主题

[Unity 组件参考手册]着色器参考之高级ShaderLab主题:特定平台的渲染差异

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-26 17:35:32 |只看该作者 |倒序浏览
Unity&nbsp***ns on various platforms, and in some cases there are differences in how things behave. Most of the time Unity hides the differences from you, but sometimes you can still bump into them.Unity运行在不同平台上,并在某些情况下某些物体会出现不同的表现形式。在大部分时间Unity为你隐藏了这些差异,但有时侯你仍然可以撞到它们。
Render Texture Coordinates 渲染纹理坐标Vertical texture coordinate conventions differ between Direct3D, OpenGL and OpenGL ES:垂直纹理坐标在Direct3D, OpenGL 和OpenGL ES之间有所不同:    In Direct3D, the coordinate is zero at the top, and increases downwards.
    在Direct3D中,坐标在顶部为0,并向下增加。
    In OpenGL and OpenGL ES, the coordiante is zero at the bottom, and increases upwards.
    在OpenGL和OpenGL ES中,坐标在底部为0,并向上增加。 Most of the time this does not really matter, except when rendering into a RenderTexture. In that case, Unity internally flips rendering upside down when rendering into a texture on Direct3D, so that the conventions match between the platforms.这大部分的时间内其实并不重要,除非我们需要渲染一张RenderTexture。在这种情况下,当需要在Direct3D中渲染一张纹理时,Unity会自上而下地翻转渲染次序,从而使纹理坐标可以在各项平台之间进行匹配。One case where this does not happen, is when Image Effects and Anti-Aliasing is used. In this case, Unity renders to screen to get anti-aliasing, and then "resolves" rendering into a RenderTexture for further processing with an Image Effect. The resulting source texture for an image effect is not flipped upside down on Direct3D (unlike all other Render Textures).在使用图像特效和反走样时将不会出现上述情况。Unity渲染到屏幕并获得反走样效果,然后"解析"渲染到 RenderTexture并通过图像特效来进行进一步的处理。针对一种图像特效来生成的源纹理在Direct3D上并不需要颠倒翻转(不同于所有其他渲染的纹理)。If your Image Effect is a simple one (processes one texture at a time), this does not really matter, because Graphics.Blit takes care of that.如果你的图像后处理特效是的一个简单的操作 (一次处理一个纹理),那么渲染坐标纹理的次序其实并不重要,因为 Graphics.Blit 会来进行管理。However, if you're processing more than one RenderTexture together in your Image Effect, most likely they will come out at different vertical orientations (only in Direct3D, and only when anti-aliasing is used). You need to manually "flip" the screen texture upside down in your vertex shader, like this:但是,如果你在图像特效中同时处理多个RenderTexture,最有可能它们的纹理坐标拥有不同的垂直方向(只在 Direct3D,和只在使用反走样效果时会出现这种情况)。这时,你需要在你的顶点着色器中手动"翻转"屏幕纹理,像这样:// On D3D when AA is used, the main texture & scene depth texture
// will come out in different vertical orientations.
// So flip sampling of the texture when that is the case (main texture
// ***l size will have negative Y).
#if SHADER_API_D3D9
if (_MainTex_***lSize.y < 0)
        uv.y = 1-uv.y;
#endifCheck out Edge Detection scene in Shader Replacement sample project for an example of this. Edge detection there uses both screen texture and Camera&#39;s Depth+Normals texture.对于这种例子,可以查看着色器变更项目中的边检测场景。边检测特效既使用屏幕纹理,又使用照相机的深度+法线纹理。
Using OpenGL Shading Language (GLSL) shaders with OpenGL ES 2.0
在OpenGL ES 2.0中使用GLSL编写的着色器OpenGL ES 2.0 provides only limited native support for OpenGL Shading Language (GLSL), for instance OpenGL ES 2.0 layer provides no built-in parameters to the shader.OpenGL ES 2.0仅本地支持OpenGL着色语言 (GLSL),例如 OpenGL ES 2.0 层为着色器没有提供内置参数。Unity implements built-in parameters for you exactly in the same way as OpenGL does, however following built-in parameters are missing:Unity完全以OpenGL相同的方式为你实现内置参数,但是以下的内置参数将会缺失:    gl_ClipVertex
    gl_SecondaryColor
    gl_DepthRange
    halfVector property of the gl_LightSourceParameters s***cture
    gl_FrontFacing
    gl_FrontLightModelProduct
    gl_BackLightModelProduct
    gl_BackMaterial
    gl_Point
    gl_PointSize
    gl_ClipPlane
    gl_EyePlaneR, gl_EyePlaneS, gl_EyePlaneT, gl_EyePlaneQ
    gl_ObjectPlaneR, gl_ObjectPlaneS, gl_ObjectPlaneT, gl_ObjectPlaneQ
    gl_Fog iPad2 and MSAA and alpha-blended geometry
iPad2、MSAA和alpha混合几何There is a bug in apple driver resulting in artifacts when MSAA is enabled and alpha-blended geometry is drawn with non RGBA colorMask. To prevent artifacts we force RGBA colorMask when this configuration is encountered, though it will render built-in Glow FX unusable (as it needs DST_ALPHA for intensity value). Also, please update your shaders if you wrote them yourself (see "Render Setup -> ColorMask" in Pass Docs). 、在苹果驱动程序中,当启用MSAA,并使用非RGBA colorMask进行alpha混合几何渲染时,会出现一个bug。为了防止发生这种bug,我们在遇到此种配置时强制使用RGBA colorMask,但这样做的后果会使内置Glow FX 无法使用 (因为它用到了DST_ALPHA 所需要的强度值)。另外,如果是你自己写的着色器,请一定不要忘记更新它们(请参阅Pass Docs中的" Render Setup -> ColorMask"文档)。
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-24 01:26 , Processed in 0.098609 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部