PixelateMask Shader

This commit is contained in:
LoafyLemon 2024-04-08 15:48:23 +01:00
parent 5c4ce667a5
commit e295fbb791

View File

@ -34,6 +34,63 @@ init python:
gl_FragColor = vec4(mix(gl_FragColor.xyz, gl_FragColor.xyz * ctemp2rgb(ctemp), u_strength), 1.0);
""")
renpy.register_shader("pixelatemaskshader", variables="""
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform vec2 res0;
uniform float u_step;
uniform float u_lod_bias;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;
""", vertex_600="""
v_tex_coord = a_tex_coord;
""", fragment_functions="""
vec2 CalculateNewUV(vec2 uv, vec2 size, float step) {
float dx = (step / size.x);
float dy = (step / size.y);
return vec2(dx*(floor(uv.x/dx) + 0.5), dy*(floor(uv.y/dy) + 0.5));
}
vec4 PixelateMask(sampler2D source, float alpha, vec2 size, vec2 uv, float step, float lod) {
if (alpha > 0.0) {
vec2 new_uv = CalculateNewUV(uv, size, step);
vec4 old = vec4(texture2D(source, uv, lod).rgb, 1.0);
vec4 new = vec4(texture2D(source, new_uv, lod).rgb, 1.0);
return mix(old, new, alpha);
}
return texture2D(source, uv, lod);
}
""", fragment_600="""
float alpha = texture2D(tex1, v_tex_coord).a;
gl_FragColor = PixelateMask(tex0, alpha, res0, v_tex_coord, u_step, u_lod_bias);
""")
class PixelateMask(renpy.Displayable, NoRollback):
def __init__(self, child, mask, step=1.0, **kwargs):
super().__init__(**kwargs)
self.child = renpy.displayable(child)
self.mask = renpy.displayable(mask)
self.step = step
def render(self, width, height, st, at):
child = renpy.display.render.render(self.child, width, height, st, at)
mask = renpy.display.render.render(self.mask, width, height, st, at)
rv = renpy.display.render.Render(width, height)
if renpy.display.render.models:
rv.mesh = True
rv.add_shader("pixelatemaskshader")
rv.add_uniform("u_step", self.step)
rv.blit(child, (0, 0))
rv.blit(mask, (0, 0))
renpy.redraw(self, 0)
return rv
transform color_temperature(factor=1.0, strength=1.0):
mesh True
shader "color_temperature_shader"