纳金网
标题:
折射实时环境反射的半透明BRDF模型shader
[打印本页]
作者:
会飞的鱼
时间:
2012-2-24 14:14
标题:
折射实时环境反射的半透明BRDF模型shader
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
作者:
书忘尘
时间:
2017-3-27 11:24
是什么效果啊,可以放个效果图吗
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5