Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. // Parameter lines go here:
  2. #pragma parameter LUT_Size "LUT Size" 16.0 1.0 64.0 1.0
  3.  
  4. #if defined(VERTEX)
  5.  
  6. #if __VERSION__ >= 130
  7. #define COMPAT_VARYING out
  8. #define COMPAT_ATTRIBUTE in
  9. #define COMPAT_TEXTURE texture
  10. #else
  11. #define COMPAT_VARYING varying
  12. #define COMPAT_ATTRIBUTE attribute
  13. #define COMPAT_TEXTURE texture2D
  14. #endif
  15.  
  16. #ifdef GL_ES
  17. #define COMPAT_PRECISION mediump
  18. #else
  19. #define COMPAT_PRECISION
  20. #endif
  21.  
  22. COMPAT_ATTRIBUTE vec4 VertexCoord;
  23. COMPAT_ATTRIBUTE vec4 COLOR;
  24. COMPAT_ATTRIBUTE vec4 TexCoord;
  25. COMPAT_VARYING vec4 COL0;
  26. COMPAT_VARYING vec4 TEX0;
  27.  
  28. vec4 _oPosition1;
  29. uniform mat4 MVPMatrix;
  30. uniform COMPAT_PRECISION int FrameDirection;
  31. uniform COMPAT_PRECISION int FrameCount;
  32. uniform COMPAT_PRECISION vec2 OutputSize;
  33. uniform COMPAT_PRECISION vec2 TextureSize;
  34. uniform COMPAT_PRECISION vec2 InputSize;
  35.  
  36. // compatibility #defines
  37. #define vTexCoord TEX0.xy
  38. #define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
  39. #define OutSize vec4(OutputSize, 1.0 / OutputSize)
  40.  
  41. void main()
  42. {
  43. gl_Position = MVPMatrix * VertexCoord;
  44. TEX0.xy = TexCoord.xy;
  45. }
  46.  
  47. #elif defined(FRAGMENT)
  48.  
  49. #if __VERSION__ >= 130
  50. #define COMPAT_VARYING in
  51. #define COMPAT_TEXTURE texture
  52. out vec4 FragColor;
  53. #else
  54. #define COMPAT_VARYING varying
  55. #define FragColor gl_FragColor
  56. #define COMPAT_TEXTURE texture2D
  57. #endif
  58.  
  59. #ifdef GL_ES
  60. #ifdef GL_FRAGMENT_PRECISION_HIGH
  61. precision highp float;
  62. #else
  63. precision mediump float;
  64. #endif
  65. #define COMPAT_PRECISION mediump
  66. #else
  67. #define COMPAT_PRECISION
  68. #endif
  69.  
  70. uniform COMPAT_PRECISION int FrameDirection;
  71. uniform COMPAT_PRECISION int FrameCount;
  72. uniform COMPAT_PRECISION vec2 OutputSize;
  73. uniform COMPAT_PRECISION vec2 TextureSize;
  74. uniform COMPAT_PRECISION vec2 InputSize;
  75. uniform sampler2D Texture;
  76. uniform sampler2D SamplerLUT;
  77. COMPAT_VARYING vec4 TEX0;
  78.  
  79. // compatibility #defines
  80. #define Source Texture
  81. #define vTexCoord TEX0.xy
  82. #define texture(c, d) COMPAT_TEXTURE(c, d)
  83. #define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
  84. #define OutSize vec4(OutputSize, 1.0 / OutputSize)
  85.  
  86. #ifdef PARAMETER_UNIFORM
  87. uniform COMPAT_PRECISION float LUT_Size;
  88. #else
  89. #define LUT_Size 16.0
  90. #endif
  91.  
  92. // This shouldn't be necessary but it seems
  93. vec4 mixfix(vec4 a, vec4 b, float c)
  94. {
  95. return (c > 0.0 && a.y < 1.0) ? mix(a, b, c) : a;
  96. }
  97.  
  98. void main()
  99. {
  100. vec4 imgColor = texture(Source, vTexCoord.xy);
  101. float red = ( imgColor.r * (LUT_Size - 1.0) + 0.4999 ) / (LUT_Size * LUT_Size);
  102. float green = ( imgColor.g * (LUT_Size - 1.0) + 0.4999 ) / LUT_Size;
  103. float blue1 = (floor(imgColor.b * (LUT_Size - 1.0)) / LUT_Size) + red;
  104. float blue2 = (ceil(imgColor.b * (LUT_Size - 1.0)) / LUT_Size) + red;
  105. float mixer = (imgColor.b - blue1) / (blue2 - blue1);
  106. vec4 color1 = texture( SamplerLUT, vec2( blue1, green ));
  107. vec4 color2 = texture( SamplerLUT, vec2( blue2, green ));
  108. FragColor = mixfix(color1, color2, mixer);
  109. }
  110. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement