Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- init python:
- # It's worth it to note that shaders are programmed in GLSL, and NOT Python or renpy script.
- # Lines must END with a semi-colon (;) and data types need to be declared.
- # Comments are expressed in // rather than the # you're used to.
- # If you want to make a parameter you can change via a Transform, it needs
- # to be a Uniform value starting with the prefix "u_".
- # Docs here: https://www.renpy.org/doc/html/model.html#uniforms-and-attributes
- # Oh and if something weird happens while you're editing these, give the game a full reboot if you get stuck.
- renpy.register_shader("MakeVisualNovels.Chromatic_Aberration", variables="""
- uniform float u_time;
- uniform sampler2D tex0;
- varying vec2 v_tex_coord;
- uniform float u_aberrationAmount;
- """, fragment_300="""
- float tileSize= 10;
- vec2 uv = v_tex_coord;
- //If you want this effect to be still
- //Uncomment the next line and comment the line after.
- //float offset = u_aberrationAmount;
- float offset = cos(u_time * 1.3 * 3.14159) * u_aberrationAmount;
- vec2 redUV = uv + vec2(offset, 0);
- vec2 blueUV = uv - vec2(offset, 0);
- vec4 red = texture2D(tex0, redUV);
- vec4 blue = texture2D(tex0, blueUV);
- //These do not need to be implemented as two seperate vec2's, but it is helpful for
- //understanding how they work for folks new to GLSL programming.
- vec2 greenUV = uv;
- vec2 alphaUV = uv;
- vec4 green = texture2D(tex0, greenUV);
- vec4 alpha = texture2D(tex0, alphaUV);
- gl_FragColor = vec4(red.r, green.g, blue.b, alpha.a);
- """)
- renpy.register_shader("MakeVisualNovels.Scanlines", variables="""
- uniform float u_time;
- uniform sampler2D tex0;
- varying vec2 v_tex_coord;
- uniform vec4 u_colorshift
- """, fragment_300="""
- vec2 uv = v_tex_coord;
- vec4 colorShift = u_colorshift;
- uv.x += sin(u_time * 0.5) * 0.12;
- uv.y += cos(u_time * 0.5) * 0.11;
- vec4 color = texture2D(tex0, v_tex_coord) * colorShift;
- float scanline = fract(uv.y * 50.0) < 0.5 ? 0.95 : 1.0;
- color.rgb *= scanline;
- float alpha = texture2D(tex0, v_tex_coord).a;
- gl_FragColor = vec4(color.r,color.g, color.b, color.a);
- """)
- renpy.register_shader("MakeVisualNovels.Static", variables="""
- uniform float u_time;
- uniform sampler2D tex0;
- varying vec2 v_tex_coord;
- """, fragment_300="""
- vec2 uv = v_tex_coord;
- uv.x += sin(u_time * 0.5) * 0.12;
- uv.y += cos(u_time * 0.5) * 0.11;
- //These aren't strictly needed, but I like them personally.
- //Remove comments from the next line and add comments to the two after it to remove the color shift.
- vec4 colorShift = vec4(0.9, 0.7, 1.0, 1.0);
- vec4 color = texture2D(tex0, v_tex_coord) * colorShift;
- //Comment the nex two lines out if you don't want to add scanlines to the static effect.
- float scanline = fract(uv.y * 50.0) < 0.5 ? 0.95 : 1.0;
- color.rgb *= scanline;
- //A clever programmer can spend some time figuring out how to make bright and/or chromatic noise in the lines below.
- //Consider it a friendly challenge. :) Let me know how you make out at https://discord.gg/devtalk
- //or on one of my streams over at https://twitch.tv/makevisualnovels
- //Good luck!
- float alpha = texture2D(tex0, v_tex_coord).a;
- float noise = alpha > 0.0 ? fract(sin(dot(v_tex_coord + u_time, vec2(12.9898, 78.233))) * 43758.5453) : 0.0;
- color.rgb *= noise * 1;
- gl_FragColor = vec4(color.r,color.g, color.b, color.a);
- """)
- # Premade transforms for you to use.
- transform Aberate:
- shader "MakeVisualNovels.Chromatic_Aberration"
- u_aberrationAmount 0.005
- # If you want this to be a still effect, you can edit the shader using the comments in it above.
- transform Scanlines:
- shader "MakeVisualNovels.Scanlines"
- u_colorshift (0.9, 0.7, 1.0, 1.0)
- # Remember Red, Green, Blue, Alpha.
- # To disable the color shift, setting all to 1 will make it 'White'
- # and effectively turn it off without touching the shader.
- transform Static:
- shader "MakeVisualNovels.Static"
- # I included a challenge to aspiring programers in the attached shader. Good luck!
Advertisement
Add Comment
Please, Sign In to add comment