NewSurfaceShader.shader 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Shader "Custom/NewSurfaceShader"
  2. {
  3. Properties
  4. {
  5. _Color ("Color", Color) = (1,1,1,1)
  6. _MainTex ("Albedo (RGB)", 2D) = "white" {}
  7. _Glossiness ("Smoothness", Range(0,1)) = 0.5
  8. _Metallic ("Metallic", Range(0,1)) = 0.0
  9. }
  10. SubShader
  11. {
  12. Tags { "RenderType"="Opaque" }
  13. LOD 200
  14. CGPROGRAM
  15. // Physically based Standard lighting model, and enable shadows on all light types
  16. #pragma surface surf Standard fullforwardshadows
  17. // Use shader model 3.0 target, to get nicer looking lighting
  18. #pragma target 3.0
  19. sampler2D _MainTex;
  20. struct Input
  21. {
  22. float2 uv_MainTex;
  23. };
  24. half _Glossiness;
  25. half _Metallic;
  26. fixed4 _Color;
  27. // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  28. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  29. // #pragma instancing_options assumeuniformscaling
  30. UNITY_INSTANCING_BUFFER_START(Props)
  31. // put more per-instance properties here
  32. UNITY_INSTANCING_BUFFER_END(Props)
  33. void surf (Input IN, inout SurfaceOutputStandard o)
  34. {
  35. // Albedo comes from a texture tinted by color
  36. fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
  37. o.Albedo = c.rgb;
  38. // Metallic and smoothness come from slider variables
  39. o.Metallic = _Metallic;
  40. o.Smoothness = _Glossiness;
  41. o.Alpha = c.a;
  42. }
  43. ENDCG
  44. Pass{
  45. Cull Front
  46. CGPROGRAM
  47. #pragma vertex vert
  48. #pragma fragment frag
  49. #include "UnityCG.cginc"
  50. #include "AutoLight.cginc"
  51. struct appdata
  52. {
  53. float4 vertex : POSITION;
  54. float2 texcoord0 : TEXCOORD0;
  55. float3 normal : NORMAL;
  56. float4 color : COLOR;
  57. };
  58. struct v2f
  59. {
  60. float4 pos : SV_POSITION;
  61. float2 uv : TEXCOORD0;
  62. float4 vertex_color : TEXCOORD3;
  63. };
  64. float _OutlineWidth;
  65. float _OutlineZbias;
  66. float4 _OutlineColor;
  67. v2f vert(appdata v)
  68. {
  69. v2f o;
  70. float3 pos_view = UnityObjectToViewPos(v.vertex);
  71. float3 normal_world = UnityObjectToWorldNormal(v.normal);
  72. float3 outline_dir = normalize(mul((float3x3)UNITY_MATRIX_V, normal_world));
  73. outline_dir.z = _OutlineZbias * (1.0 - v.color.b);
  74. pos_view += outline_dir * _OutlineWidth * 0.001 * v.color.a;
  75. o.pos = mul(UNITY_MATRIX_P, float4(pos_view, 1.0));
  76. o.uv = v.texcoord0;
  77. o.vertex_color = v.color;
  78. return o;
  79. }
  80. half4 frag(v2f i) : SV_Target
  81. {
  82. half3 outlineColor = _OutlineColor.xyz;
  83. return float4(outlineColor, 1.0);
  84. }
  85. ENDCG
  86. }
  87. }
  88. FallBack "Diffuse"
  89. }