Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1.  
  2. Shader "318/TexPixelLightingAlpha" // shader name
  3. {
  4. Properties
  5. {
  6. _MainTex("Bild", 2D) = "white" {}
  7. _Cutoff("CutoffValue",Float) = 0.5
  8. _farbeF("Farbe", Color) = (0.1,0.7,1,0.8)
  9. _SpecfarbeF("Specular", Color) = (1,1,1,1)
  10. _Shiny("Shiny", Float) = 10
  11. }
  12. SubShader // Pro Platform
  13. {
  14. Pass //Shader durchlauf
  15. {
  16. Tags {"LightMode" = "ForwardBase"}
  17. Cull Off
  18.  
  19. CGPROGRAM //---------------CG CODE
  20.  
  21. #pragma vertex VS //ändert den VShader EntryPoint
  22. #pragma fragment PS //ändert den PShader EntryPoint
  23.  
  24. #include "UnityCG.cginc" //hat mehr Globale constant values aus Unity
  25.  
  26. struct VertexInput
  27. {
  28. float4 pos : POSITION;
  29. float3 normal : NORMAL;
  30. float4 tex : TEXCOORD0;
  31. };
  32.  
  33. struct VertexOutput
  34. {
  35. float4 pos : SV_POSITION;
  36. float4 tex : TEXCOORD0;
  37. float4 posWorld : TEXCOORD1;
  38. float3 normalDir : TEXCOORD2;
  39. };
  40.  
  41. uniform sampler2D _MainTex;
  42. uniform float4 _MainTex_ST; //tillling and offset parameters
  43.  
  44. uniform float _Cutoff;
  45.  
  46. uniform float4 _farbeF;
  47. uniform float4 _SpecfarbeF;
  48. uniform float _Shiny;
  49. uniform float4 _LightColor0;
  50.  
  51. //VERTEX shader
  52. VertexOutput VS(VertexInput vi)
  53. {
  54. VertexOutput vo;
  55.  
  56. float4x4 modelMatrix = unity_ObjectToWorld;
  57. float4x4 modelMatrixInvers = unity_WorldToObject;
  58.  
  59. vo.posWorld = mul(modelMatrix, vi.pos);
  60. vo.normalDir = normalize(
  61. mul(float4(vi.normal, 0), modelMatrixInvers).xyz);
  62. vo.pos = UnityObjectToClipPos(vi.pos);
  63. vo.tex = vi.tex;
  64. return vo;
  65. }
  66.  
  67. float4 PS(VertexOutput input) : COLOR
  68. {
  69. float3 normalDir = normalize(input.normalDir);
  70. float3 viewDir = normalize(_WorldSpaceCameraPos -
  71. input.posWorld.xyz);
  72.  
  73. float3 lightDir;
  74. float attenuation;
  75.  
  76. //wenn in der .w eine 0 steht -> dannn directional light
  77. if (0.0 == _WorldSpaceLightPos0.w)
  78. {
  79. attenuation = 1;
  80. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  81. }
  82. else
  83. { //spot or point light
  84. float3 vertexToLight = _WorldSpaceLightPos0.xyz
  85. - input.posWorld.xyz;
  86. float distance = length(vertexToLight);
  87. attenuation = 1.0 / distance;
  88. lightDir = normalize(vertexToLight);
  89. }
  90.  
  91. float3 ambient = UNITY_LIGHTMODEL_AMBIENT.rgb * _farbeF;
  92.  
  93. float3 diffRefl = attenuation * _LightColor0.rgb * _farbeF.rgb
  94. *max(0.0, dot(normalDir, lightDir));
  95.  
  96. float3 specRefl;
  97. if (dot(normalDir, lightDir) < 0)
  98. {
  99. //licht auf falscher seite?
  100. specRefl.rgb = 0;
  101. }
  102. else
  103. {
  104. specRefl = attenuation * _LightColor0.rgb * _SpecfarbeF.rgb *
  105. pow(max(0.0, dot(reflect(-lightDir, normalDir), viewDir)), _Shiny);
  106. }
  107.  
  108. float4 diff = tex2D(_MainTex, _MainTex_ST.xy * input.tex.xy + _MainTex_ST.zw);
  109. float4 FinalColor = float4(diff + ambient + diffRefl + specRefl, 1.0);
  110.  
  111. if (diff.a < _Cutoff)
  112. {
  113. discard;
  114. }
  115.  
  116. return FinalColor;
  117. }
  118.  
  119.  
  120. ENDCG // -------------END CG
  121. }
  122.  
  123. Pass //Shader durchlauf
  124. {
  125. Tags {"LightMode" = "ForwardAdd"}
  126.  
  127. Blend One One
  128.  
  129. CGPROGRAM //---------------CG CODE
  130.  
  131. #pragma vertex VS //ändert den VShader EntryPoint
  132. #pragma fragment PS //ändert den PShader EntryPoint
  133.  
  134. #include "UnityCG.cginc" //hat mehr Globale constant values aus Unity
  135.  
  136. struct VertexInput
  137. {
  138. float4 pos : POSITION;
  139. float3 normal : NORMAL;
  140. };
  141.  
  142. struct VertexOutput
  143. {
  144. float4 pos : SV_POSITION;
  145. float4 posWorld : TEXCOORD0;
  146. float3 normalDir : TEXCOORD1;
  147. };
  148.  
  149. uniform float4 _farbeF;
  150. uniform float4 _SpecfarbeF;
  151. uniform float _Shiny;
  152. uniform float4 _LightColor0;
  153.  
  154. //VERTEX shader
  155. VertexOutput VS(VertexInput vi)
  156. {
  157. VertexOutput vo;
  158.  
  159. float4x4 modelMatrix = unity_ObjectToWorld;
  160. float4x4 modelMatrixInvers = unity_WorldToObject;
  161.  
  162. vo.posWorld = mul(modelMatrix, vi.pos);
  163. vo.normalDir = normalize(
  164. mul(float4(vi.normal, 0), modelMatrixInvers).xyz);
  165. vo.pos = UnityObjectToClipPos(vi.pos);
  166.  
  167. return vo;
  168. }
  169.  
  170. float4 PS(VertexOutput input) : COLOR
  171. {
  172. float3 normalDir = normalize(input.normalDir);
  173. float3 viewDir = normalize(_WorldSpaceCameraPos -
  174. input.posWorld.xyz);
  175.  
  176. float3 lightDir;
  177. float attenuation;
  178.  
  179. //wenn in der .w eine 0 steht -> dannn directional light
  180. if (0.0 == _WorldSpaceLightPos0.w)
  181. {
  182. attenuation = 1;
  183. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  184. }
  185. else
  186. { //spot or point light
  187. float3 vertexToLight = _WorldSpaceLightPos0.xyz
  188. - input.posWorld.xyz;
  189. float distance = length(vertexToLight);
  190. attenuation = 1.0 / distance;
  191. lightDir = normalize(vertexToLight);
  192. }
  193.  
  194. float3 diffRefl = attenuation * _LightColor0.rgb * _farbeF.rgb
  195. *max(0.0, dot(normalDir, lightDir));
  196.  
  197. float3 specRefl;
  198. if (dot(normalDir, lightDir) < 0)
  199. {
  200. //licht auf falscher seite?
  201. specRefl.rgb = 0;
  202. }
  203. else
  204. {
  205. specRefl = attenuation * _LightColor0.rgb * _SpecfarbeF.rgb *
  206. pow(max(0.0, dot(reflect(-lightDir, normalDir), viewDir)), _Shiny);
  207. }
  208.  
  209. return float4(diffRefl + specRefl, 1.0);
  210. }
  211.  
  212.  
  213. ENDCG // -------------END CG
  214. }
  215. }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement