- 最后登录
- 2018-6-29
- 注册时间
- 2011-7-1
- 阅读权限
- 20
- 积分
- 359
![Rank: 2](static/image/common//star_level2.gif)
- 纳金币
- 335582
- 精华
- 0
|
在unity3d中实现一个完美的水面下效果还是有很大难度的,下面是一个简单的shader效果,大家可以试试看!代码未经测试!
Shader "Hidden/Wiggle" {
Properties {
_MainTex ("Base (RGB)", 2D) = "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 sampler2D _MainTex;
float4 frag (v2f_img i) : COLOR {
i.uv.x += sin(_Time.y+i.uv.x*10)*0.01;
i.uv.y += cos(_Time.y+i.uv.y*10)*0.01;
float4 c = tex2D(_MainTex, i.uv);
return c;
}
ENDCG
}
}
Fallback off
}
//====c# code for camera:
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("Image Effects/Wiggle")]
public class Wiggle : ImageEffectBase {
// Called by camera to apply image effect
void OnRenderImage (RenderTexture source, RenderTexture destination) {
Graphics.Blit (source, destination, material);
}
} |
|