Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. /*
  2. Genesis Dithering and Pseudo Transparency Shader v1.3 - Pass 0
  3. by Sp00kyFox, 2014
  4.  
  5. Neighbor anaylsis via dot product of the difference vectors.
  6.  
  7. */
  8.  
  9. #pragma parameter MODE "GDAPT Monochrome Analysis" 0.0 0.0 1.0 1.0
  10. #pragma parameter PWR "GDAPT Color Metric Exp" 2.0 0.0 10.0 0.1
  11.  
  12. #ifdef PARAMETER_UNIFORM
  13. uniform float MODE, PWR;
  14. #else
  15. #define MODE 0.0
  16. #define PWR 2.0
  17. #endif
  18.  
  19. /* COMPATIBILITY
  20. - HLSL compilers
  21. - Cg compilers
  22. - FX11 compilers
  23. */
  24.  
  25. #define dot(x,y) saturate(dot(x,y)) // NVIDIA Fix
  26. #define TEX(dx,dy) COMPAT_Sample(decal, texCoord+float2((dx),(dy))*t1).xyz
  27.  
  28. // Reference: http://www.compuphase.com/cmetric.htm
  29. float eq(float3 A, float3 B)
  30. {
  31. float3 diff = A-B;
  32. float ravg = (A.x + B.x) * 0.5;
  33.  
  34. diff *= diff * float3(2.0 + ravg, 4.0, 3.0 - ravg);
  35.  
  36. return pow( smoothstep(3.0, 0.0, sqrt(diff.x + diff.y + diff.z)), PWR );
  37. }
  38.  
  39. #include "../../../../compat_includes.inc"
  40. uniform COMPAT_Texture2D(decal) : TEXUNIT0;
  41. uniform float4x4 modelViewProj;
  42.  
  43. struct out_vertex
  44. {
  45. float4 position : COMPAT_POS;
  46. float2 texCoord : TEXCOORD0;
  47. float2 t1 : TEXCOORD1;
  48. };
  49.  
  50. out_vertex main_vertex(COMPAT_IN_VERTEX)
  51. {
  52. #ifdef HLSL_4
  53. float4 position = VIN.position;
  54. float2 texCoord = VIN.texCoord;
  55. #endif
  56. out_vertex OUT;
  57. OUT.position = mul(modelViewProj, position);
  58. OUT.texCoord = texCoord;
  59. OUT.t1 = 1.0 / COMPAT_texture_size;
  60.  
  61. return OUT;
  62. }
  63.  
  64. /* FRAGMENT SHADER */
  65. float4 gdapt_pass0(float2 texCoord, float2 t1, COMPAT_Texture2D(decal))
  66. {
  67. float3 C = TEX( 0, 0).rgb;
  68. float3 L = TEX(-1, 0).rgb;
  69. float3 R = TEX( 1, 0).rgb;
  70. float3 U = TEX( 0,-1).rgb;
  71. float3 D = TEX( 0, 1).rgb;
  72. float3 S = TEX( 1, 1).rgb;
  73.  
  74. float tag = 0.0;
  75.  
  76.  
  77. if(MODE){
  78. tag = all(L == R) && any(C != L);
  79. }
  80. else{
  81. tag = dot(normalize(C-L), normalize(C-R)) * eq(L,R);
  82. }
  83.  
  84.  
  85. if(all(L != C) && all(L != U) && all(L != D) && all(U == D) && all(D != S) )
  86. tag = 0.0;
  87.  
  88. return float4(C, tag);
  89. }
  90.  
  91. float4 main_fragment(COMPAT_IN_FRAGMENT) : COMPAT_Output
  92. {
  93. return gdapt_pass0(VOUT.texCoord, VOUT.t1, decal);
  94. }
  95. COMPAT_END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement