Advertisement
Uhyve

PCSX2 CRT Shader V1

Aug 31st, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
  2.  
  3. Texture2D Texture;
  4. SamplerState TextureSampler;
  5.  
  6. //#define SplitRGB
  7. #define ResX 480.0
  8. #define ResY 270.0
  9. #define Wasteful
  10. //#define Vignette
  11. #define Curved
  12.  
  13. float2 radialDistortion(float2 coord)
  14. {
  15.     float2 cc = coord - 0.5;
  16.     float dist = dot(cc, cc) * 0.1;            
  17.     return (coord + cc * (1.0 + dist) * dist);
  18. }
  19.  
  20. struct PS_INPUT
  21. {
  22.     float4 p : SV_Position;
  23.     float2 t : TEXCOORD0;
  24. };
  25.  
  26. struct PS_OUTPUT
  27. {
  28.     float4 c : SV_Target0;
  29. };
  30.  
  31.  
  32. PS_OUTPUT ps_main(PS_INPUT input)
  33. {
  34.     PS_OUTPUT output;  
  35.  
  36.     #ifdef Curved
  37.         input.t = radialDistortion(input.t);
  38.  
  39.         // Again wasteful, but for some reason, I couldn't set BORDER as a samplerstate
  40.         if( input.t.x > 1.0 || input.t.x < 0.0 || input.t.y > 1.0 || input.t.y < 0.0 )
  41.         {
  42.             output.c = float4(0.0,0.0,0.0,1.0);
  43.             return output;
  44.         }
  45.     #endif
  46.  
  47.     float2 vPixelPos;
  48.     vPixelPos.x = (input.t.x * ResX) + 0.5;
  49.     vPixelPos.y = (input.t.y * ResY) + 0.5;
  50.    
  51.     float2 vPixel = round(vPixelPos);
  52.     float2 vPixelDist = vPixelPos - vPixel;
  53.     float fMaxDist = 1.0;
  54.  
  55.     #ifdef Wasteful
  56.         input.t.x = vPixel.x / ResX;
  57.         input.t.y = vPixel.y / ResY;
  58.     #endif
  59.  
  60.     float fVignette = 1.0;
  61.  
  62.     #ifdef Vignette
  63.         fVignette = saturate(1.3 - (pow(input.t.x-0.5,2) + pow(input.t.y-0.5,2)) );
  64.     #endif
  65.  
  66.     float4 color = Texture.Sample(TextureSampler, input.t) * fVignette;
  67.  
  68.     // Shame this doesn't work, not entirely sure why either. Should split the RGB slightly.
  69.     #if SplitRGB
  70.         float fTexelPos = (vPixelDist.x + 1.0) * 0.7854;
  71.         color.x *= 1.0 - sin(fTexelPos+0.00) * 0.25;
  72.         color.y *= 1.0 - sin(fTexelPos+0.52) * 0.25;
  73.         color.z *= 1.0 - sin(fTexelPos+1.04) * 0.25;
  74.         color.xyz *= 1.5;
  75.     #endif
  76.  
  77.     float fPixelDist = saturate( fMaxDist - sqrt(pow(abs(vPixelDist.x),2) + pow(abs(vPixelDist.y),2)) );
  78.    
  79.     color.xyz *= fPixelDist;
  80.     output.c = color;
  81.     return output;
  82. }
  83.  
  84. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement