Guest User

MakeVIsualNovelsVHSShaderTutorial

a guest
Mar 21st, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | Source Code | 0 0
  1. init python:
  2.  
  3. # It's worth it to note that shaders are programmed in GLSL, and NOT Python or renpy script.
  4. # Lines must END with a semi-colon (;) and data types need to be declared.
  5. # Comments are expressed in // rather than the # you're used to.
  6. # If you want to make a parameter you can change via a Transform, it needs
  7. # to be a Uniform value starting with the prefix "u_".
  8. # Docs here: https://www.renpy.org/doc/html/model.html#uniforms-and-attributes
  9. # Oh and if something weird happens while you're editing these, give the game a full reboot if you get stuck.
  10.  
  11. renpy.register_shader("MakeVisualNovels.Chromatic_Aberration", variables="""
  12. uniform float u_time;
  13. uniform sampler2D tex0;
  14. varying vec2 v_tex_coord;
  15. uniform float u_aberrationAmount;
  16.  
  17. """, fragment_300="""
  18. float tileSize= 10;
  19. vec2 uv = v_tex_coord;
  20. //If you want this effect to be still
  21. //Uncomment the next line and comment the line after.
  22. //float offset = u_aberrationAmount;
  23. float offset = cos(u_time * 1.3 * 3.14159) * u_aberrationAmount;
  24. vec2 redUV = uv + vec2(offset, 0);
  25. vec2 blueUV = uv - vec2(offset, 0);
  26. vec4 red = texture2D(tex0, redUV);
  27. vec4 blue = texture2D(tex0, blueUV);
  28.  
  29. //These do not need to be implemented as two seperate vec2's, but it is helpful for
  30. //understanding how they work for folks new to GLSL programming.
  31. vec2 greenUV = uv;
  32. vec2 alphaUV = uv;
  33. vec4 green = texture2D(tex0, greenUV);
  34. vec4 alpha = texture2D(tex0, alphaUV);
  35. gl_FragColor = vec4(red.r, green.g, blue.b, alpha.a);
  36. """)
  37.  
  38. renpy.register_shader("MakeVisualNovels.Scanlines", variables="""
  39. uniform float u_time;
  40. uniform sampler2D tex0;
  41. varying vec2 v_tex_coord;
  42. uniform vec4 u_colorshift
  43.  
  44. """, fragment_300="""
  45. vec2 uv = v_tex_coord;
  46. vec4 colorShift = u_colorshift;
  47. uv.x += sin(u_time * 0.5) * 0.12;
  48. uv.y += cos(u_time * 0.5) * 0.11;
  49. vec4 color = texture2D(tex0, v_tex_coord) * colorShift;
  50. float scanline = fract(uv.y * 50.0) < 0.5 ? 0.95 : 1.0;
  51. color.rgb *= scanline;
  52. float alpha = texture2D(tex0, v_tex_coord).a;
  53. gl_FragColor = vec4(color.r,color.g, color.b, color.a);
  54. """)
  55.  
  56.  
  57. renpy.register_shader("MakeVisualNovels.Static", variables="""
  58. uniform float u_time;
  59. uniform sampler2D tex0;
  60. varying vec2 v_tex_coord;
  61.  
  62. """, fragment_300="""
  63. vec2 uv = v_tex_coord;
  64. uv.x += sin(u_time * 0.5) * 0.12;
  65. uv.y += cos(u_time * 0.5) * 0.11;
  66.  
  67. //These aren't strictly needed, but I like them personally.
  68. //Remove comments from the next line and add comments to the two after it to remove the color shift.
  69.  
  70. vec4 colorShift = vec4(0.9, 0.7, 1.0, 1.0);
  71. vec4 color = texture2D(tex0, v_tex_coord) * colorShift;
  72.  
  73. //Comment the nex two lines out if you don't want to add scanlines to the static effect.
  74. float scanline = fract(uv.y * 50.0) < 0.5 ? 0.95 : 1.0;
  75. color.rgb *= scanline;
  76.  
  77. //A clever programmer can spend some time figuring out how to make bright and/or chromatic noise in the lines below.
  78. //Consider it a friendly challenge. :) Let me know how you make out at https://discord.gg/devtalk
  79. //or on one of my streams over at https://twitch.tv/makevisualnovels
  80. //Good luck!
  81.  
  82. float alpha = texture2D(tex0, v_tex_coord).a;
  83. float noise = alpha > 0.0 ? fract(sin(dot(v_tex_coord + u_time, vec2(12.9898, 78.233))) * 43758.5453) : 0.0;
  84. color.rgb *= noise * 1;
  85. gl_FragColor = vec4(color.r,color.g, color.b, color.a);
  86. """)
  87.  
  88. # Premade transforms for you to use.
  89.  
  90. transform Aberate:
  91. shader "MakeVisualNovels.Chromatic_Aberration"
  92. u_aberrationAmount 0.005
  93. # If you want this to be a still effect, you can edit the shader using the comments in it above.
  94.  
  95. transform Scanlines:
  96. shader "MakeVisualNovels.Scanlines"
  97. u_colorshift (0.9, 0.7, 1.0, 1.0)
  98. # Remember Red, Green, Blue, Alpha.
  99. # To disable the color shift, setting all to 1 will make it 'White'
  100. # and effectively turn it off without touching the shader.
  101.  
  102. transform Static:
  103. shader "MakeVisualNovels.Static"
  104. # I included a challenge to aspiring programers in the attached shader. Good luck!
  105.  
Advertisement
Add Comment
Please, Sign In to add comment