查看: 1421|回复: 0
打印 上一主题 下一主题

[Shaders] 室外玻璃幕墙Shader

[复制链接]

2317

主题

54

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
20645
精华
62

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2014-4-30 22:15:29 |只看该作者 |倒序浏览
老外分享的一个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. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-8 14:08 , Processed in 0.102945 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部