[RenPy] 纯文本查看 复制代码
init python:
renpy.register_shader("FixedMask",
variables="""
uniform sampler2D tex0;
uniform float u_FMask_s; //
uniform float u_FMask_f; //
uniform float u_FMask_w; //
varying vec2 v_tex_coord;
""",
fragment_300="""
vec4 color = texture2D(tex0, v_tex_coord);
float x = v_tex_coord.x;
float y = v_tex_coord.y;
float alpha = 1.0;
float t;
// 将 f 转换为实际渐变范围 (最大到中心点 0.5)
float f_actual = u_FMask_f * 0.5;
// 根据方向计算 alpha
if (u_FMask_s == 1.0) { // 仅顶部
if (y < f_actual) {
t = y / f_actual;
alpha = smoothstep(0.0, 1.0, pow(t, u_FMask_w));
}
}
else if (u_FMask_s == 2.0) { // 仅底部
if (y > 1.0 - f_actual) {
t = (1.0 - y) / f_actual;
alpha = smoothstep(0.0, 1.0, pow(t, u_FMask_w));
}
}
else if (u_FMask_s == 3.0) { // 仅左侧
if (x < f_actual) {
t = x / f_actual;
alpha = smoothstep(0.0, 1.0, pow(t, u_FMask_w));
}
}
else if (u_FMask_s == 4.0) { // 仅右侧
if (x > 1.0 - f_actual) {
t = (1.0 - x) / f_actual;
alpha = smoothstep(0.0, 1.0, pow(t, u_FMask_w));
}
}
else if (u_FMask_s == 5.0) { // 上下
if (y < f_actual) {
t = y / f_actual;
alpha = min(alpha, smoothstep(0.0, 1.0, pow(t, u_FMask_w)));
}
if (y > 1.0 - f_actual) {
t = (1.0 - y) / f_actual;
alpha = min(alpha, smoothstep(0.0, 1.0, pow(t, u_FMask_w)));
}
}
else if (u_FMask_s == 6.0) { // 左右
if (x < f_actual) {
t = x / f_actual;
alpha = min(alpha, smoothstep(0.0, 1.0, pow(t, u_FMask_w)));
}
if (x > 1.0 - f_actual) {
t = (1.0 - x) / f_actual;
alpha = min(alpha, smoothstep(0.0, 1.0, pow(t, u_FMask_w)));
}
}
else if (u_FMask_s == 7.0) { // 四边
if (y < f_actual) {
t = y / f_actual;
alpha = min(alpha, smoothstep(0.0, 1.0, pow(t, u_FMask_w)));
}
if (y > 1.0 - f_actual) {
t = (1.0 - y) / f_actual;
alpha = min(alpha, smoothstep(0.0, 1.0, pow(t, u_FMask_w)));
}
if (x < f_actual) {
t = x / f_actual;
alpha = min(alpha, smoothstep(0.0, 1.0, pow(t, u_FMask_w)));
}
if (x > 1.0 - f_actual) {
t = (1.0 - x) / f_actual;
alpha = min(alpha, smoothstep(0.0, 1.0, pow(t, u_FMask_w)));
}
}
// 预乘 alpha
color.rgb *= alpha;
color.a = alpha;
gl_FragColor = color;
""")
transform MDX_fmask(s=5.0,f=0.3,w=2.0):
mesh True
shader "FixedMask"
u_FMask_s s # side 1=上, 2=下, 3=左, 4=右, 5=上下, 6=左右, 7=四边
u_FMask_f f # fade 渐变范围 0.0~1.0
u_FMask_w w # warp 曲线陡峭度 =1线性, >1陡峭
#测试
screen abc():
fixed:
align(0.5,0.5)
xysize(445,900)
at MDX_fmask
frame:
vbox:
text _("{size=68}画廊{/size}"):
outlines [ (1, "#f00", 0, 0 ) ]
textbutton "text" action NullAction()
viewport:
vbox:
for i in range(10):
text "1"