Création d'un petit party-game anonyme de Build + Bagar sous Unity
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

wMaillageShader.shader 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. Shader "Custom/wMaillageShader"
  2. {
  3. Properties
  4. {
  5. _MainTex("Texture", 2D) = "white" {}
  6. _Color("Color", Color) = (1,1,1,1)
  7. _Threshold("Threshold", float) = 0.01
  8. _EdgeColor("Edge color", Color) = (1,0,0,1)
  9. _Glossiness("Smoothness", Range(0,1)) = 0.5
  10. _Metallic("Metallic", Range(0,1)) = 0.0
  11. }
  12. SubShader
  13. {
  14. Cull Off ZWrite Off ZTest Always
  15. Tags { "RenderType" = "Opaque" }
  16. Pass
  17. {
  18. CGPROGRAM
  19. #pragma vertex vert
  20. #pragma fragment frag
  21. #include "UnityCG.cginc"
  22. struct appdata
  23. {
  24. float4 vertex : POSITION;
  25. float2 uv : TEXCOORD0;
  26. };
  27. struct v2f
  28. {
  29. float2 uv : TEXCOORD0;
  30. float4 vertex : SV_POSITION;
  31. };
  32. sampler2D _CameraDepthNormalsTexture;
  33. float4 _MainTex_ST;
  34. v2f vert(appdata v)
  35. {
  36. v2f o;
  37. o.vertex = UnityObjectToClipPos(v.vertex);
  38. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  39. return o;
  40. }
  41. sampler2D _MainTex;
  42. float4 _MainTex_TexelSize;
  43. float _Threshold;
  44. fixed4 _EdgeColor;
  45. float4 GetPixelValue(in float2 uv) {
  46. half3 normal;
  47. float depth;
  48. DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, uv), depth, normal);
  49. return fixed4(normal, depth);
  50. }
  51. fixed4 frag(v2f i) : SV_Target
  52. {
  53. fixed4 col = tex2D(_MainTex, i.uv);
  54. fixed4 orValue = GetPixelValue(i.uv);
  55. float2 offsets[8] = {
  56. float2(-1, -1),
  57. float2(-1, 0),
  58. float2(-1, 1),
  59. float2(0, -1),
  60. float2(0, 1),
  61. float2(1, -1),
  62. float2(1, 0),
  63. float2(1, 1)
  64. };
  65. fixed4 sampledValue = fixed4(0,0,0,0);
  66. for (int j = 0; j < 8; j++) {
  67. sampledValue += GetPixelValue(i.uv + offsets[j] * _MainTex_TexelSize.xy);
  68. }
  69. sampledValue /= 8;
  70. return lerp(col, _EdgeColor, step(_Threshold, length(orValue - sampledValue)));
  71. }
  72. ENDCG
  73. }
  74. }
  75. }