Skip to content

Instantly share code, notes, and snippets.

@Gouvernathor
Last active March 31, 2023 11:53
Show Gist options
  • Save Gouvernathor/157e3e707b1eca0ea4fa305eedc97300 to your computer and use it in GitHub Desktop.
Save Gouvernathor/157e3e707b1eca0ea4fa305eedc97300 to your computer and use it in GitHub Desktop.
init python hide:
renpy.register_shader(
"chroma_crt", # https://www.shadertoy.com/view/4dX3zN
fragment_functions="""
vec2 uuv(float wp, vec2 tex_coord)
{
// squared distance from center
vec2 uvv = tex_coord;
vec2 dc = 0.5-uvv;
dc *= dc;
// warp the fragment coordinates
uvv -= .5; uvv *= 1.+(dc.yx*wp); uvv += .5;
return uvv;
}
""", variables="""
uniform float u_warp;
uniform float u_scan;
uniform float u_chroma;
uniform vec2 u_model_size;
uniform sampler2D tex0;
attribute vec2 a_tex_coord;
attribute vec4 a_position;
varying vec2 v_tex_coord;
""", vertex_300="""
//v_tex_coord = a_tex_coord;
v_tex_coord = a_position.xy/u_model_size;
""", fragment_300="""
vec2 uv = uuv(u_warp, v_tex_coord);
#define PI 3.14159265359
// outside boundaries is transparent
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
gl_FragColor = vec4(0.0);
} else {
vec2 texra = texture2D(tex0, uv).ra;
vec2 texga = texture2D(tex0, uuv(u_warp*u_chroma, v_tex_coord)).ga;
vec2 texba = texture2D(tex0, uuv(u_warp*u_chroma*u_chroma, v_tex_coord)).ba;
vec4 pure = vec4(texra.x, texga.x, texba.x, (texra.y+texga.y+texba.y)/3.);
// determine if we are drawing in a scanline
float apply = pow(cos(uv.y*u_model_size.y/PI)*u_scan, 2.);
// sample the texture
gl_FragColor = mix(pure, vec4(0.0), apply);
}
"""
)
transform chroma_crt(warp=.2, scan=.5, chroma=.9):
mesh True
# this for several reasons
# one, we need to turn non-textured things like Solid into a texture
# two, we need to turn everything that's showing on master into a single texture
shader "chroma_crt"
u_warp warp
u_scan scan
u_chroma chroma
# this one is better for applying to whole layers
transform black_chroma_crt(child, warp=.2, scan=.5, chroma=.9):
contains:
"black"
contains:
At(child, chroma_crt(warp, scan, chroma))
label test_crt:
show sand # bg
show jynx # character
camera at black_chroma_crt
pause
# a dialogue here would not be transformed, but you can do a camera screens as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment