纳金网

标题: 室外玻璃幕墙Shader [打印本页]

作者: 王者再临    时间: 2014-4-30 22:15
标题: 室外玻璃幕墙Shader
老外分享的一个shader,做建筑虚拟可以用下
  1. Shader "Building/Glass" {
  2. Properties {

  3. _Lightmap ("Lightmap (RGB) Reflectiveness (A)", 2D) = "black" {}

  4. _Color ("Main Color", Color) = (1,1,1,1)

  5. _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }

  6. }

  7. Category {

  8. Tags { "Queue" = "Transparent-110" }

  9. Blend SrcAlpha OneMinusSrcAlpha

  10. Lighting Off

  11. Colormask RGB

  12. // ---- fragment program cards

  13. SubShader {

  14. Pass {

  15. CGPROGRAM

  16. #pragma vertex vert

  17. #pragma fragment frag

  18. #pragma fragmentoption ARB_fog_exp2

  19. #pragma fragmentoption ARB_precision_hint_fastest

  20. #include "UnityCG.cginc"

  21. struct v2f {

  22. V2F_POS_FOG;

  23. float3 normal;

  24. float3 viewDir;

  25. float3 rotNormal;

  26. float2 uv;

  27. };

  28. uniform float4x4 _RotMatrix;

  29. uniform float4 _Lightmap_ST;

  30. v2f vert (appdata_tan v)

  31. {

  32. v2f o;

  33. PositionFog( v.vertex, o.pos, o.fog );

  34. o.normal = mul( (float3x3)_Object2World, v.normal );

  35. o.rotNormal = mul( (float3x3)_RotMatrix, o.normal );

  36. o.viewDir = mul( (float3x3)_Object2World, ObjSpaceViewDir(v.vertex) );

  37. o.uv = TRANSFORM_TEX(v.texcoord, _Lightmap);

  38. return o;

  39. }

  40. uniform samplerCUBE _Cube;

  41. uniform float4 _Color;

  42. uniform sampler2D _Lightmap;

  43. float4 frag (v2f i) : COLOR

  44. {

  45. float3 normal = i.normal;

  46. i.viewDir = normalize(i.viewDir);

  47. half nsv = saturate(dot( normal, i.viewDir ));

  48. // calculate reflection vector in world space

  49. half3 r = reflect(-i.viewDir, i.rotNormal);

  50. half4 lightmapColor = tex2D(_Lightmap, i.uv);

  51. half4 reflcolor = texCUBE(_Cube, r);

  52. half fresnel = 1 - nsv*0.5;

  53. half fresnelAlpha = 1 - nsv * (1 - _Color.a);

  54. half4 c = half4( lerp( _Color.rgb, reflcolor.rgb, fresnel * lightmapColor.a ), fresnelAlpha );

  55. c.rgb *= lightmapColor.rgb;

  56. return c;

  57. }

  58. ENDCG

  59. }

  60. }

  61. // ---- cards that can do cube maps

  62. SubShader {

  63. Pass {

  64. SetTexture [_Cube] { matrix[_RotMatrix] constantColor(1,1,1,0.5) combine texture, constant }

  65. }

  66. }

  67. // ---- cards that can't do anything

  68. SubShader {

  69. Pass {

  70. Color (1,1,1,0.3)

  71. }

  72. }

  73. }

  74. }
复制代码





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