纳金网

标题: 折射效果shader,类似于水珠效果 [打印本页]

作者: 晃晃    时间: 2011-8-26 08:44
标题: 折射效果shader,类似于水珠效果
以下为ImageRefractionEffect.shader代码:

Shader "Image Effects/Refraction"

{

Properties

{

  _SpeedStrength ("Speed (XY), Strength (ZW)", Vector) = (1, 1, 1, 1)

  _RefractTexTiling ("Refraction Tilefac", Float) = 1

  _RefractTex ("Refraction (RG), Colormask (B)", 2D) = "bump" {}

  _Color ("Color (RGB)", Color) = (1, 1, 1, 1)

  _MainTex ("Base (RGB) DON`T TOUCH IT! ", RECT) = "white" {}

}

SubShader

{

  Pass

  {

   ZTest Always Cull Off ZWrite Off

   Fog{Mode off}

   CGPROGRAM

   #pragma vertex vert_img

   #pragma fragment frag

   #pragma fragmentoption ARB_precision_hint_fastest

   #include "UnityCG.cginc"

   uniform samplerRECT _MainTex;

   uniform sampler2D _RefractTex;

   uniform float4 _SpeedStrength;

   uniform float _RefractTexTiling;

   uniform float4 _Color;

   float4 frag (v2f_img i) : COLOR

   {

    float2 refrtc = i.uv*_RefractTexTiling;

    float4 refract = tex2D(_RefractTex, refrtc+_SpeedStrength.xy*_Time.x);

    refract.rg = refract.rg*2.0-1.0;

    float4 original = texRECT(_MainTex, i.uv+refract.rg*_SpeedStrength.zw);

    float4 output = lerp(original, original*_Color, refract.b);

    output.a = original.a;

    return output;

   }

   ENDCG

  }

}

Fallback off

}

以下为C#代码:

using UnityEngine;

[ExecuteInEditMode]

[AddComponentMenu("Image Effects/Image Refraction")]

public class ImageRefractionEffect : SlinImageEffectBase

{

// Called by camera to apply image effect

void OnRenderImage (RenderTexture source, RenderTexture destination)

{

  ImageEffects.BlitWithMaterial(material, source, destination);

}

}
作者: 难骑    时间: 2011-9-3 08:01
提示: 作者被禁止或删除 内容自动屏蔽
作者: C.R.CAN    时间: 2012-2-1 23:28
不错不错,收藏了

作者: 晃晃    时间: 2012-3-17 23:28
既来之,则看之!

作者: 菜刀吻电线    时间: 2012-3-22 23:30
佩服,好多阿 ,哈哈

作者: 晃晃    时间: 2012-3-24 23:18
我无语!

作者: C.R.CAN    时间: 2012-5-11 23:26
路过……

作者: 奇    时间: 2012-6-3 23:19
不错哦,顶一下......

作者: 奇    时间: 2012-6-26 23:21
凡系斑竹滴话要听;凡系朋友滴帖要顶

作者: C.R.CAN    时间: 2012-8-15 23:40
跑着去顶朋友滴铁

作者: C.R.CAN    时间: 2012-9-4 23:26
不错哦,顶一下......

作者: yeu1233    时间: 2012-9-6 09:17
学习了,呵呵!以后或许可以多交流交流
作者: tc    时间: 2013-1-26 23:27
再看一看,再顶楼主

作者: tc    时间: 2013-2-4 23:27
提醒猪猪,千万不能让你看见

作者: tc    时间: 2013-2-8 23:22
顶!学习了!阅!





欢迎光临 纳金网 (http://c-www.narkii.com/club/) Powered by Discuz! X2.5