You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.2 KiB

6 years ago
  1. Shader "Paco/NormalDirection/Vertex" {
  2. Properties {
  3. _Positive ("Positive", Color) = (0.737931,1,0,1)
  4. _Negative ("Negative", Color) = (0,0.9044118,0.8295637,1)
  5. [MaterialToggle] _UseNegative ("Use Negative", Float ) = 0
  6. [MaterialToggle] _XZAxis ("X / Z Axis", Float ) = 0
  7. _SmoothLight ("Smooth Light", Range(0, 1)) = 1
  8. [MaterialToggle] _ShowNormalDirection ("Show Normal Direction", Float ) = 0.475862
  9. }
  10. SubShader {
  11. Tags {
  12. "RenderType"="Opaque"
  13. }
  14. Pass {
  15. Name "FORWARD"
  16. Tags {
  17. "LightMode"="ForwardBase"
  18. }
  19. CGPROGRAM
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. #define UNITY_PASS_FORWARDBASE
  23. #include "UnityCG.cginc"
  24. #pragma multi_compile_fwdbase_fullshadows
  25. #pragma multi_compile_fog
  26. #pragma only_renderers d3d9 d3d11 glcore gles
  27. #pragma target 3.0
  28. uniform float4 _Negative;
  29. uniform fixed _ShowNormalDirection;
  30. uniform fixed _XZAxis;
  31. uniform float4 _Positive;
  32. uniform fixed _UseNegative;
  33. uniform float _SmoothLight;
  34. struct VertexInput {
  35. float4 vertex : POSITION;
  36. float3 normal : NORMAL;
  37. float4 vertexColor : COLOR;
  38. };
  39. struct VertexOutput {
  40. float4 pos : SV_POSITION;
  41. float3 normalDir : TEXCOORD0;
  42. float4 vertexColor : COLOR;
  43. UNITY_FOG_COORDS(1)
  44. };
  45. VertexOutput vert (VertexInput v) {
  46. VertexOutput o = (VertexOutput)0;
  47. o.vertexColor = v.vertexColor;
  48. o.normalDir = UnityObjectToWorldNormal(v.normal);
  49. o.pos = UnityObjectToClipPos( v.vertex );
  50. UNITY_TRANSFER_FOG(o,o.pos);
  51. return o;
  52. }
  53. float4 frag(VertexOutput i) : COLOR {
  54. i.normalDir = normalize(i.normalDir);
  55. float3 normalDirection = i.normalDir;
  56. ////// Lighting:
  57. float2 node_2973 = normalDirection.rb;
  58. float _XZAxis_var = lerp( node_2973.r, node_2973.g, _XZAxis );
  59. float node_8533 = (_SmoothLight*48.0+2.0);
  60. float3 NormalDir = normalDirection;
  61. float3 finalColor = lerp( lerp(i.vertexColor.rgb,saturate(( lerp(_Negative.rgb,_Positive.rgb,lerp(1.0,saturate(((100.0*_XZAxis_var)*0.5+0.5)),_UseNegative)) > 0.5 ? (1.0-(1.0-2.0*(lerp(_Negative.rgb,_Positive.rgb,lerp(1.0,saturate(((100.0*_XZAxis_var)*0.5+0.5)),_UseNegative))-0.5))*(1.0-i.vertexColor.rgb)) : (2.0*lerp(_Negative.rgb,_Positive.rgb,lerp(1.0,saturate(((100.0*_XZAxis_var)*0.5+0.5)),_UseNegative))*i.vertexColor.rgb) )),floor(saturate(lerp(_XZAxis_var,abs(_XZAxis_var),_UseNegative)) * node_8533) / (node_8533 - 1)), NormalDir, _ShowNormalDirection );
  62. fixed4 finalRGBA = fixed4(finalColor,1);
  63. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  64. return finalRGBA;
  65. }
  66. ENDCG
  67. }
  68. }
  69. FallBack "Diffuse"
  70. }