MGKJ_Base_1.02.shader 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //2012.03.12
  2. //2012.04.05
  3. //2013.06.26
  4. //2013.07.05
  5. Shader "@MGKJ_Base"
  6. {
  7. Properties
  8. {
  9. _SpecColor0("Specular Color", Color) = (0,0,0,1)
  10. _Shininess("Shininess", Range(0,1) ) = 0.5
  11. _Color ("Main Color", Color) = (0,0,0,1)
  12. _MainTex ("DiffuseMap", 2D) = "white" {}
  13. _globalInfluence("Global Influence", Range(0,1) ) = 1
  14. _brightness("Brightness", Range(1,5) ) = 1
  15. _contrast("Contrast", Range(1,2.5) ) = 1
  16. _lightmap_color("Lighting Color", Color) = (0,0,0,1)
  17. _LightMap ("SecondMap (CompleteMap or LightMap)", 2D) = "white" {}
  18. _changeType ("<<<HDR Type *** NoHDR>>>", Range(0,1)) =0
  19. _SelectColor ("Outline Color", Color) = (0.2,0.6,0.8,0)
  20. _SelectColorAlpha("Select Color Alpha",Range(0,1) ) = 0
  21. }
  22. SubShader {
  23. Tags { "RenderType"="Opaque"}
  24. LOD 200
  25. CGPROGRAM
  26. #pragma surface surf BlinnPhong_wjm finalcolor:mycolor
  27. #pragma multi_compile_fwdadd_fullshadows
  28. #pragma target 3.0
  29. #pragma profileoption MaxTexIndirections=64
  30. // #pragma debug
  31. float4x4 _RotateUVM;
  32. float _GLOBALBRIGHTNESS;
  33. float _GLOBALCONTRASR;
  34. float depth_bias;
  35. float border_clamp;
  36. float _changeType;
  37. float4 _SpecColor0;
  38. float _Parallax;
  39. float _Shininess;
  40. float _brightness;
  41. float _contrast;
  42. float4 _Color;
  43. float4 _lightmap_color;
  44. float4 _lightmap_color2;
  45. // float _reflect_blender;
  46. // float _fresnel_ctrl;
  47. sampler2D _MainTex;
  48. // sampler2D _BumpMap;
  49. sampler2D _LightMap;
  50. // sampler2D _LightMap2;
  51. // sampler2D _relaxedcone_relief_map;
  52. // samplerCUBE _Cube;
  53. float4 _SelectColor;
  54. float _SelectColorAlpha;
  55. float _globalInfluence;
  56. struct Input {
  57. float2 uv_MainTex;
  58. // float2 uv_BumpMap;
  59. float2 uv2_LightMap;
  60. };
  61. struct SurfaceOutput_wjm
  62. {
  63. half3 Albedo;
  64. half3 Normal;
  65. half3 Emission;
  66. half3 Gloss;
  67. half Specular;
  68. half Alpha;
  69. };
  70. inline half4 LightingBlinnPhong_wjm_PrePass (SurfaceOutput_wjm s, half4 light)
  71. {
  72. half3 spec = light.a * s.Gloss;
  73. half4 c;
  74. c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
  75. c.a = s.Alpha;
  76. return c;
  77. }
  78. inline half4 LightingBlinnPhong_wjm (SurfaceOutput_wjm s, half3 lightDir, half3 viewDir, half atten)
  79. {
  80. half3 h = normalize (lightDir + viewDir);
  81. half diff = max (0, dot ( lightDir, s.Normal ));
  82. float nh = max (0, dot (s.Normal, h));
  83. float spec = pow (nh, s.Specular*128.0);
  84. half4 lightPower;
  85. lightPower.rgb = _LightColor0.rgb * diff;
  86. lightPower.w = spec * Luminance (_LightColor0.rgb);
  87. lightPower *= atten * 2.0;
  88. half4 c;
  89. c.rgb = (s.Albedo * lightPower.rgb + lightPower.rgb * spec*s.Gloss);
  90. c.a = 1;
  91. return c;
  92. }
  93. void mycolor (Input IN, SurfaceOutput_wjm o, inout fixed4 color)
  94. {
  95. // color *= _lightmap_color;
  96. color += _SelectColor*_SelectColorAlpha;
  97. }
  98. inline float3 DecodeLightmap2( float4 color )
  99. {
  100. #if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE)
  101. return 2.0 * color.rgb;
  102. #else
  103. // potentially faster to do the scalar multiplication
  104. // in parenthesis for scalar GPUs
  105. // return pow((8.0 * color.a),2.2) * color.rgb;
  106. return pow((_GLOBALBRIGHTNESS*_globalInfluence+_brightness)* lerp(8.0 * color.a,1,_changeType)* color.rgb,_contrast+_GLOBALCONTRASR*_globalInfluence);
  107. #endif
  108. }
  109. void surf (Input IN, inout SurfaceOutput_wjm o)
  110. {
  111. // float3 p,v;
  112. // setup_ray(IN,p,v);
  113. // ray_intersect_relaxedcone(_relaxedcone_relief_map,p,v);
  114. IN.uv_MainTex=mul(IN.uv_MainTex.xyxy, _RotateUVM).xy;
  115. o.Normal = float3(0.0,0.0,1.0);
  116. // o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
  117. // o.Normal = tex2D(_relaxedcone_relief_map,p.xy).xyz;
  118. float4 Tex2D0=tex2D(_MainTex,IN.uv_MainTex);
  119. float4 Tex2D1=0;
  120. // Tex2D1+=_lightmap_color*pow(_brightness.xxxx +tex2D(_LightMap,(IN.uv2_LightMap).xy),_contrast.xxxx)- _brightness.xxxx;
  121. Tex2D1+=_lightmap_color*float4(DecodeLightmap2(tex2D(_LightMap,(IN.uv2_LightMap).xy)),1);
  122. // float3 worldRefl = WorldReflectionVector (IN, o.Normal);
  123. // fixed4 cubeColor = texCUBE (_Cube, IN.worldRefl);
  124. // float fresnel_intensity=1-clamp(pow((max(0,dot (normalize(IN.viewDir), o.Normal))),-_fresnel_ctrl).xxxx,0,1);
  125. float3 diffuseColor=Tex2D0;
  126. o.Albedo=_Color.rgb*diffuseColor;
  127. // o.Albedo=_Color.rgb*Tex2D0;
  128. o.Emission=Tex2D1.rgb*diffuseColor;
  129. o.Specular=_Shininess ;
  130. o.Gloss =Tex2D0.a*_SpecColor0;
  131. o.Alpha = Tex2D0.a * _Color.a;
  132. o.Normal=normalize(o.Normal);
  133. }
  134. ENDCG
  135. }
  136. FallBack "Diffuse"
  137. }