Guest User

Retro Shader

a guest
Aug 26th, 2013
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. /*
  2. Hyllian - Retro Shader - 2013
  3.  
  4. A re-implementation from the original made by Hyllian and DOLLS!
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  
  20. */
  21.  
  22. /*
  23. VERTEX_SHADER
  24. */
  25. void main_vertex
  26. (
  27. float4 position : POSITION,
  28. float4 color : COLOR,
  29. float2 texCoord : TEXCOORD0,
  30.  
  31. uniform float4x4 modelViewProj,
  32.  
  33. out float4 oPosition : POSITION,
  34. out float4 oColor : COLOR,
  35. out float2 otexCoord : TEXCOORD
  36. )
  37. {
  38. oPosition = mul(modelViewProj, position);
  39. oColor = color;
  40. otexCoord = texCoord;
  41. }
  42.  
  43. /*
  44. FRAGMENT SHADER
  45. */
  46.  
  47.  
  48.  
  49. struct output
  50. {
  51. float4 color : COLOR;
  52. };
  53.  
  54. struct input
  55. {
  56. float2 video_size;
  57. float2 texture_size;
  58. float2 output_size;
  59. };
  60.  
  61. // This value must be between 0.0 (totally black) and 1.0 (nearest neighbor)
  62. #define PIXEL_SIZE 0.84
  63.  
  64. output main_fragment(float2 texCoord: TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN)
  65. {
  66. // Reading the texel
  67. float3 E = pow(tex2D(decal, texCoord).xyz, float3(2.4));
  68.  
  69. float2 fp = frac(texCoord*IN.texture_size);
  70. float2 ps = IN.video_size/IN.output_size;
  71.  
  72. float2 f = clamp(clamp(fp + 0.5*ps, 0.0, 1.0) - PIXEL_SIZE, 0.0, ps)/ps;
  73.  
  74. float max_coord = max(f.x, f.y);
  75.  
  76. float3 res = lerp(E*(1.04+fp.x*fp.y), E*0.36, max_coord);
  77.  
  78. // Product interpolation
  79. output OUT;
  80. OUT.color = float4(clamp( pow(res, float3(1.0 / 2.2)), 0.0, 1.0 ), 1.0);
  81. return OUT;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment