- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
Shader "Sbin/Glass" {
properties{
_Color("Color",color)=(1,1,1,1)
_Scale("Scale", range(-0.5,0.5))=0.15
_Cube("Cube",cube)="white"{}
_c("C",range(0,1))=0.5
_Specular("Specular",color)=(1,1,1,1)
_Shininess("Shininess",range(0,16))=8
_LightPos("LightPos",vector)=(2,10,10,1)
}
SubShader {
tags{"rendertype"="transparent" "queue"="transparent"}
colormask RGBA
grabpass{ }
pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "unitycg.cginc"
#pragma target 3.0 //SM3.0
sampler2D _GrabTexture;
float _Scale;
float4 _Color;
samplerCUBE _Cube;
float _c;
float4 _LightPos;
float _Shininess;
float4 _Specular;
s***ct v2f
{
float4 position: POSITION;
float4 uv_grab:TEXCOORD;
float2 uvoff:TEXCOORD1;
float4 worldPosition:COLOR;//world space
float3 viewDir:TEXCOORD2;//world space
float3 normal:TEXCOORD3;//world space
float3 lightDir:TEXCOORD4;//world space
};
v2f vert(appdata_base v)
{
v2f o;
o.position=mul(UNITY_MATRIX_MVP,v.vertex);
o.uv_grab=ComputeGrabScreenPos(o.position);
o.worldPosition= mul(_Object2World, v.vertex);
o.lightDir=(_LightPos-o.worldPosition).xyz;
float dx=dot(normalize((float3)UNITY_MATRIX_IT_MV[0]),normalize(v.normal));
float dy=dot(normalize((float3)UNITY_MATRIX_IT_MV[1]),normalize(v.normal));
float angle= dot( normalize(ObjSpaceViewDir(v.vertex)), normalize(v.normal) );
o.uvoff.x= -dx * saturate(angle)* _Scale;
o.uvoff.y= dy * saturate(angle) *_Scale;
o.viewDir= (_WorldSpaceCameraPos- mul(_Object2World,v.vertex)).xyz;
o.normal= mul(v.normal, (float3x3)_World2Object);
return o;
}
float4 frag(v2f i):COLOR
{
float3 N= normalize(i.normal);
float3 V= normalize(i.viewDir);
float3 L= normalize(i.lightDir);
//grab screen color
i.uv_grab.xy /= i.uv_grab.w;
i.uv_grab.xy += i.uvoff.xy;
float4 grabColor=tex2D(_GrabTexture, i.uv_grab.xy );
float3 R= reflect(-V, N );
float4 reflColor=texCUBE(_Cube,R);
float4 C= lerp(grabColor, reflColor,_c )*_Color;
//calculate BRDF
float4 specularColor;
float3 T= normalize(cross(N,V));
float a=dot(L,T);
float b=dot(V,T);
float c= sqrt(1-pow(a,2.0)) * sqrt(1-pow(b,2.0)) -a*b;
float brdf= pow(c, _Shininess);
specularColor= brdf * float4(1,1,1,1)* max(0,dot(L,N)) *_Specular;
C=lerp(C,specularColor,dot(V,N));
return C;
}
ENDCG
}
}
fallback off
}
///////////////////////////////////////////////
需要本贴的附件脚本文件 加到物体上 在脚本上加入光源
来自unity3d8.com |
|