Advertisement
Guest User

Gameboy Mimic Shader

a guest
Feb 20th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /* COMPATIBILITY
  2. - HLSL compilers
  3. - Cg compilers
  4. */
  5.  
  6. /*
  7. Gameboy Mimic Shader
  8. by Sp00kyFox, 2014
  9.  
  10. Calculates luma and rounds it to one of 4 grayscales.
  11.  
  12. */
  13.  
  14.  
  15. #define TEX(dx,dy) tex2D(decal, VAR.texCoord+float2((dx),(dy))*VAR.t1)
  16.  
  17. static float3 weights = float3(0.299, 0.587, 0.114);
  18.  
  19. struct input
  20. {
  21. float2 video_size;
  22. float2 texture_size;
  23. float2 output_size;
  24. };
  25.  
  26. struct out_vertex {
  27. float4 position : POSITION;
  28. float2 texCoord : TEXCOORD0;
  29. float2 t1;
  30. };
  31.  
  32.  
  33. /* VERTEX_SHADER */
  34. out_vertex main_vertex
  35. (
  36. float4 position : POSITION,
  37. float2 texCoord : TEXCOORD0,
  38.  
  39. uniform float4x4 modelViewProj,
  40. uniform input IN
  41. )
  42. {
  43. out_vertex OUT;
  44.  
  45. OUT.position = mul(modelViewProj, position);
  46.  
  47. float2 ps = float2(1.0/IN.texture_size.x, 1.0/IN.texture_size.y);
  48. float dx = ps.x;
  49. float dy = ps.y;
  50.  
  51. OUT.texCoord = texCoord;
  52. OUT.t1 = float2(dx, dy); // F H
  53.  
  54. return OUT;
  55. }
  56.  
  57.  
  58. /* FRAGMENT SHADER */
  59. float3 main_fragment(in out_vertex VAR, uniform sampler2D decal : TEXUNIT0, uniform input IN) : COLOR
  60. {
  61.  
  62. float3 C = TEX( 0, 0);
  63.  
  64. float luma = (ceil(4.0 * dot(C, weights)) - 1.0) / 3.0;
  65.  
  66. return float3(luma);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement