树叶边缘渲染
来源:互联网 发布:macbook卸载软件失败 编辑:程序博客网 时间:2024/04/27 21:53
树叶边缘渲染一般的做法就是使用alpha test,但这样做在边缘上会出现一些很“碎”的效果,特别是离摄像机远的时候。
如果要边缘效果好,就要采用alpha blend的方式,但这种方法有排序的问题,会造成前后错乱。
之前看斗战神的草,发现边缘是用blend的效果,但没有排序问题。当时有美术同事问如何做到的,一时我也答不出来。
后来翻译unity3d官方文档的时候,发现有个例子提供了解决方案:只在边缘进行alpha blend,其它部位仍然使用alpha test来渲染。这样既保证了边缘的柔和,也没有渲染顺序的问题,因为边缘只是很小的部分,边缘本身的排序问题几乎不会被发现。
以下是原文:
When rendering plants and trees, many games have the hard edges typical of alpha testing. A way around that is to render the object twice. In the first pass, we use alpha testing to only render pixels that are more than 50% opaque. In the second pass, we alpha-blend the graphic in the parts that were cut away, without recording the depth of the pixel. We might get a bit of confusion as further away branches overwrite the nearby ones, but in practice, that is hard to see as leaves have a lot of visual detail in them.
当渲染植物和树木的时候,许多游戏都由于alpha测试的问题产生了硬边。解决这个问题的一个方法是将对象渲染两遍。第一遍,我们使用alpha测试的方式来渲染,但只是渲染那些不透明度大于50%的像素。第二遍,我们反过来将一遍没有渲染的像素进行alpha混合方式的渲染,并不进行深度写操作。理论上,我们也许会看到远距离的像素覆盖近距离的像素,但实际上,我们很难在大量叶子的细节上发现这个问题。
Shader "Vegetation" { Properties { _Color ("Main Color", Color) = (.5, .5, .5, .5) _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {} _Cutoff ("Base Alpha cutoff", Range (0,.9)) = .5 } SubShader { // Set up basic lighting Material { Diffuse [_Color] Ambient [_Color] } Lighting On // Render both front and back facing polygons. Cull Off // first pass: // render any pixels that are more than [_Cutoff] opaque Pass { AlphaTest Greater [_Cutoff] SetTexture [_MainTex] { combine texture * primary, texture } } // Second pass: // render in the semitransparent details. Pass { // Dont write to the depth buffer ZWrite off // Don't write pixels we have already written. ZTest Less // Only render pixels less or equal to the value AlphaTest LEqual [_Cutoff] // Set up alpha blending Blend SrcAlpha OneMinusSrcAlpha SetTexture [_MainTex] { combine texture * primary, texture } } }}
- 树叶边缘渲染
- 提升树叶渲染性能
- 如何处理max透明树叶贴图渲染白边问题
- 延迟渲染的边缘检测(Edge-Detection)抗锯齿算法
- 树叶飘落
- 边缘
- 边缘
- 边缘
- 扫树叶的小和尚
- 扫树叶的小和尚
- 用coreldraw设计树叶
- 【搜索】【RQNOJ】拾树叶
- 二叉树叶子数
- 二叉树叶子数
- 一片假树叶
- 下落的树叶
- ps树叶的雕刻
- 【JSOI2016】独特的树叶
- NGUI对游戏里各种常见UI效果的实现总结
- 【微信公众平台开发】微信刮刮乐,解决三星兼容性问题
- Javascript 正确使用方法 二
- 黑马程序员——面试题——1.交通灯管理系统
- hdu1556 color the ball 树状数组区间更新单点查询(附线段树做法)与二维扩展
- 树叶边缘渲染
- java多态的重新认识
- Swift 自动引用计数(十四)
- MyEclipse6.5 重启后注册码失效
- sqlite使用记录
- Android应用程序开发以及背后的设计思想深度剖析
- 利用ajax异步处理POST表单中的数据
- 黑马程序员-流程控制
- Linux 内核链表使用举例