Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. Shader "Bora/updated_carpaint" {
  2. Properties {
  3. _Color ("Diffuse Color", Color) = (1, 1, 1,1)
  4. _SpecColor ("Specular Color", Color) = (1,1,1,1)
  5. _AmbientColor ("Metalic Color", Color) = (1,1,1, 1)
  6. _ReflectionColor("Reflection Color", Color) = (1,1,1, 1)
  7. _Shininess ("Glossiness", Range(0.1,2)) = 0.5
  8. _MainTex ("Diffuse", 2D) = "white" {}
  9. _FlakeTex ("Flakes", 2D) = "white" {}
  10. _FlakeDens ("Flakes Tile", Range(1,40) ) = 2
  11. _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }
  12. _Cube2 ("Reflection Cubemap2", Cube) = "" { TexGen CubeReflect }
  13. _FresnelScale ("Fresnel Intensity", Range(0,2)) = 0
  14. _FresnelPower ("Fresnel Power", Range(0.1,3) ) = 0
  15. _MetalicScale ("Metalic Intens", Range(0.0,4.0)) = 0
  16. _MetalicPower ("Metalic Power", Range(0.0,20.0)) = 0
  17. _Blend ("Blend Rate", Range(0,1)) = 0
  18. }
  19. SubShader {
  20. Tags { "RenderType"="Opaque" }
  21. LOD 400
  22. Cull Back
  23. ZWrite On
  24. ZTest Lequal
  25. ColorMask RGBA
  26. CGPROGRAM
  27.  
  28. #pragma surface surf BlinnPhong vertex:vert
  29. #pragma target 3.0
  30.  
  31. struct Input
  32. {
  33. float2 uv_MainTex;
  34. float2 uv_FlakeTex;
  35. float3 worldRefl;
  36. float3 viewDir;
  37. float3 lightDir;
  38. float3 normal;
  39. float3 worldNormal;
  40. INTERNAL_DATA
  41. };
  42. uniform float _Rotate;
  43. samplerCUBE _Cube;
  44. samplerCUBE _Cube2;
  45. sampler2D _MainTex;
  46. sampler2D _FlakeTex;
  47. float4 _Color;
  48. float4 _AmbientColor;
  49. float4 _ReflectionColor;
  50. float _Shininess;
  51. float _FlakeDens;
  52. float _FresnelScale;
  53. float _FresnelPower;
  54. float _MetalicScale;
  55. float _MetalicPower;
  56. float _Blend;
  57.  
  58. float3 RotateAroundXInDegrees (float3 vertex, float degrees)
  59. {
  60. float alpha = degrees * UNITY_PI / 180.0;
  61. float sina, cosa;
  62. sincos(alpha / 2, sina, cosa);
  63. float3x3 m = float3x3(1, 0, 0, 0, cosa, -sina, 0, sina, cosa);
  64. float3 r = float3(mul(m, vertex.xyz) ).rgb;
  65. return r;
  66. }
  67.  
  68. float3 RotateAroundYInDegrees (float3 vertex, float degrees)
  69. {
  70. float alpha = degrees * UNITY_PI / 180.0;
  71. float sina, cosa;
  72. sincos(alpha / 2, sina, cosa);
  73. float3x3 m = float3x3(cosa, 0, sina, 0, 1, 0, -sina, 0, cosa);
  74. float3 r = float3(mul(m, vertex.xyz) ).rgb;
  75. return r;
  76. }
  77.  
  78. float3 RotateAroundZInDegrees (float3 vertex, float degrees)
  79. {
  80. float alpha = degrees * UNITY_PI / 180.0;
  81. float sina, cosa;
  82. sincos(alpha / 2, sina, cosa);
  83. float3x3 m = float3x3(cosa, -sina, sina, sina, cosa, 0, 0, 0, 1);
  84. float3 r = float3(mul(m, vertex.xyz) ).rgb;
  85. return r;
  86. }
  87.  
  88.  
  89.  
  90. void vert (inout appdata_full v, out Input o) {
  91. UNITY_INITIALIZE_OUTPUT(Input,o);
  92. v.normal.x = RotateAroundXInDegrees(float3(v.normal.x, 0, 1), _Rotate * 10);
  93. v.normal.z = RotateAroundZInDegrees(float3(1, 0, v.normal.z), _Rotate * 10);
  94.  
  95. }
  96.  
  97.  
  98. void surf (Input IN, inout SurfaceOutput o){
  99.  
  100. //Reflection ve isik icin hesaplamalar
  101. o.Normal = normalize(float3(0.0,0.0,1.0));
  102. float3 normEyeVec = normalize (IN.viewDir);
  103. float dotEyeVecNormal = abs(dot(normEyeVec, o.Normal));
  104.  
  105. //GET WORLD REFLECTION FROM o.Normal.x and o.Normal.y
  106. float3 worldRefl = WorldReflectionVector (IN, o.Normal);
  107. float3 worldRefl2 = WorldReflectionVector (IN, o.Normal);
  108. float3 worldLight = normalize (IN.lightDir);
  109. //Gerekli ise flake texture
  110. float4 Tex1 = tex2D( _MainTex,IN.uv_MainTex );
  111. float specularmask = Tex1.a ;
  112. float4 Diffuse = ((_Color* (specularmask) )* Tex1) + (Tex1*(1-specularmask));
  113.  
  114. float4 Tex2 = tex2D( _FlakeTex, IN.uv_FlakeTex*_FlakeDens );
  115. float4 Specular = (_Shininess * Tex2) + Tex2;
  116. //Cubemap' lerin alimi
  117. float4 TexCUBE = texCUBE( _Cube, worldRefl) * _ReflectionColor;
  118. float4 TexCUBE2 = texCUBE( _Cube2, worldRefl2) * _ReflectionColor;
  119. //Cubemap degisimi
  120. float4 env = lerp(TexCUBE, TexCUBE2, IN.normal.x);
  121. //Paint efekti
  122. float4 fresnel = (1.0 - dot( normEyeVec,o.Normal ));
  123. float4 emmission = _FresnelScale * env * pow(fresnel,_FresnelPower);
  124. float metalic = (specularmask*_MetalicScale) * pow(dotEyeVecNormal,_MetalicPower);
  125.  
  126.  
  127. o.Albedo = Diffuse * ((metalic+(1-specularmask)+((1-Tex2)*(specularmask))) + (_AmbientColor.rgb*specularmask) ) + ( specularmask*(1-Tex2));
  128. o.Specular = Specular;
  129. o.Gloss = _SpecColor * specularmask;
  130. o.Emission = emmission * emmission * specularmask;
  131. }
  132. ENDCG
  133. }
  134. FallBack "Reflective/Diffuse"
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement