Advertisement
Guest User

gdapt-pass0-stripes.cg

a guest
Mar 23rd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 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.  
  73. float tag = 0.0;
  74.  
  75.  
  76. if(MODE){
  77. tag = all(L == R) && any(C != L);
  78. }
  79. else{
  80. tag = dot(normalize(C-L), normalize(C-R)) * eq(L,R);
  81. }
  82.  
  83. if(all(L == R) && all(U == D) && all(L == U))
  84. tag = 0.0;
  85.  
  86. return float4(C, tag);
  87. }
  88.  
  89. float4 main_fragment(COMPAT_IN_FRAGMENT) : COMPAT_Output
  90. {
  91. return gdapt_pass0(VOUT.texCoord, VOUT.t1, decal);
  92. }
  93. COMPAT_END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement