Glow + Outline 轮廓描边,并做Blur处理

原连接:http://www.cnblogs.com/dosomething/archive/2012/08/04/2622488.html

根据上面链接,写出的代码。

轮廓描边是游戏中的细节  但是一个有特色的效果还是会让人眼前一亮

Glow + Outline 的效果就像求生之路2和暗黑3的轮廓描边界一样  对轮廓描边后再进行模糊处理

如图: 求生之路2

 

暗黑3

  

一种思路为:

1、在RTT中绘制单一像素

2、对1绘制后的RTT进行blur处理

3、对2处理后的RTT与原始场景进行叠加

4、绘制原始模型

 

另一种思路:

1、绘制原始模型到RTT

2、对1绘制的RTT中原始模型进行Sobel描边

3、对2描边后的RenderTexture进行blur处理

4、叠加1和3的RenderTexture

5、4与场景进行叠加

 

在unity3d中的实现

1、场景图像渲染之前

 void OnPreRender

{

  ......

   另外添加一个摄像机A

  这里必须将GlowOutlineCamera摄像机关闭

  并且清除标识为纯色

  制定其渲染目标为RTT 

  清空其背景

  摄像机A在主摄像机渲染之前通过Shader去绘制指定渲染类型的GameObject   也就是需要描边的GameObject

  (即摄像机A.RenderWithShader(RTT, "XXXX");)

  ...... 

}

 

2、场景图像渲染之后 

void OnRenderImage(RenderTexture source, RenderTexture destination)

{

  ......

  将摄像机A所渲染的目标纹理进行blur处理

  将blur后的RTT与场景图像渲染后的RTT进行合成叠加

  拷贝到目的渲染纹理上

  ......

}

 

效果1  未被遮挡

效果2 被遮挡

效果3 描边相交  未被遮挡

效果4 描边相交  被遮挡

 

最后附上一张火炬之光2的轮廓描边效果  

unity实现起来要简单的多 不属于postprocess  

只需要对需要描边的物体写一个Rimlight边缘高光的shader即可  

国内好像有个unity制作的网页游戏也是用的这种方式描边

一下就是代码:

首先是主相机中的代码:

using UnityEngine;

public class GlowEffect : MonoBehaviour {
	
	public Material glowMaterial;
	public Shader glowReplaceShader;
	
	// Toggle between using the object's alpha channel for glow. This setting is good for mobile devices - 
	// it uses less memory and doesn't cause as many draw calls though it uses the object's alpha channel.
	public bool useAlphaChannelForGlow = false;
	
	// Toggle between using the simple glow effect. This setting is good for older mobile devices. 
	// sIt further reduces the amount of memory required and the number of draw calls.
	public bool useSimpleGlow = false;
	
	// The number of times the glow texture should be blurred. The more blur iterations the wider the glow. This value is only used if useSimpleGlow is false.
	public int blurIterations = 4;
	
	// The distance of the samples taken for the blurred glow. Too big of a value will cause noise in the blur. This value is only used if useSimpleGlow is false. 
	public float blurSpread = 1.0f;
	
	// Multiplies the glow color by this value.
	public float glowMultiplier = 1.2f;

    // Multiplies the glow color by this color.
    public Color glowColorMultiplier = Color.white;
	
	[HideInInspector]
	public RenderTexture postEffectsRenderTexture;
	
	private RenderTexture cameraRenderTexture;
	private Camera shaderCamera;
	private RenderTexture replaceRenderTexture;
	private RenderTexture blurA;
	private RenderTexture blurB;
	
	public void OnEnable()
	{
		if (!useAlphaChannelForGlow) {
			replaceRenderTexture = new RenderTexture(Screen.width, Screen.height, 16, RenderTextureFormat.ARGB32);
			replaceRenderTexture.wrapMode = TextureWrapMode.Clamp;
			replaceRenderTexture.useMipMap = false;
			replaceRenderTexture.isPowerOfTwo = true;
			replaceRenderTexture.filterMode = FilterMode.Bilinear;
			replaceRenderTexture.Create();
			
			glowMaterial.SetTexture("_Glow", replaceRenderTexture);
						
			shaderCamera = new GameObject("Glow Effect", typeof(Camera)).GetComponent<Camera>();
			shaderCamera.gameO
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值