调色与滤镜
本页属于 GenPy Ren'Py 学习路线。教程内容面向 Ren'Py 8.x,并在页面末尾连接到 GenPy 的对应工作流。
学习目标
- 了解“调色与滤镜”在 Ren'Py 项目中的用途。
- 能在一个最小项目里验证本章相关语法或工作流。
- 知道发布前需要检查的常见风险,并能在 GenPy 中继续维护。
核心语法
Matrixcolorblurtintgrayscaledepth of field
可运行示例
text
# 在图像定义里固定调色
image bg_room_sepia = Transform("bg/room.png", matrixcolor=SepiaMatrix())
# 在 ATL/at 里动态调色(可动画)
transform tint_blue:
matrixcolor TintMatrix("#aaccff")
label start:
show bg room at tint_blue教程正文
调色 = 改变画面的颜色/明暗/饱和度,做出昼夜、黄昏、黑白回忆、染红警报等氛围。核心是 matrixcolor 变换属性 + 各种 ColorMatrix 类;模糊/景深用 blur 属性。
1. matrixcolor 基础
给任意可显示物套一个颜色矩阵:
text
# 在图像定义里固定调色
image bg_room_sepia = Transform("bg/room.png", matrixcolor=SepiaMatrix())
# 在 ATL/at 里动态调色(可动画)
transform tint_blue:
matrixcolor TintMatrix("#aaccff")
label start:
show bg room at tint_blue2. 内置 ColorMatrix 速查
| 类 | 作用 |
|---|---|
TintMatrix("#rrggbb") | 染色(整体偏向某色) |
BrightnessMatrix(b) | 亮度(-1~1,0 不变) |
ContrastMatrix(c) | 对比度(1.0 不变) |
SaturationMatrix(s) | 饱和度(1 原始,0 灰度,>1 鲜艳) |
SepiaMatrix() | 棕褐色(怀旧/老照片) |
HueMatrix(deg) | 色相旋转(度) |
InvertMatrix() | 反色 |
OpacityMatrix(a) | 不透明度 |
ColorizeMatrix(black, white) | 把黑/白分别映射到两种颜色(双色调) |
SplineMatrix(...) | 样条调色(高级) |
IdentityMatrix() | 不变(基准) |
3. 组合多个矩阵(用 *)
矩阵可相乘叠加,按从左到右顺序应用:
text
transform dusk:
matrixcolor TintMatrix("#ffccaa") * SaturationMatrix(0.85) * BrightnessMatrix(-0.05)4. 昼夜 / 时间变化(可平滑过渡)
matrixcolor 支持在 ATL 里 linear/ease 插值,做出平滑的天色变化:
text
transform day_to_night:
matrixcolor TintMatrix("#ffffff")
linear 3.0 matrixcolor TintMatrix("#5566aa") * BrightnessMatrix(-0.1)
label evening:
show bg town at day_to_night
"太阳渐渐落下,天色转蓝。"封装成函数,按“时段”取调色:
text
init python:
TIME_TINT = {
"morning": TintMatrix("#fff3e0"),
"noon": TintMatrix("#ffffff"),
"dusk": TintMatrix("#ffccaa") * SaturationMatrix(0.85),
"night": TintMatrix("#5566aa") * BrightnessMatrix(-0.12),
}
transform timed(tod):
matrixcolor TIME_TINT[tod]
label scene:
show bg street at timed("dusk")5. 黑白回忆 / 闪回
饱和度降到 0 = 灰度,常用于回忆段落:
text
transform flashback:
matrixcolor SaturationMatrix(1.0)
linear 0.6 matrixcolor SaturationMatrix(0.0) * ContrastMatrix(1.1)
label memory:
show layer master at flashback # 整屏转灰
"那是很多年前的事了……"回到现实时反向插值回 SaturationMatrix(1.0)。
6. 染色警报 / 情绪渲染
text
transform alarm_red:
matrixcolor TintMatrix("#ffffff")
block:
linear 0.5 matrixcolor TintMatrix("#ff6666")
linear 0.5 matrixcolor TintMatrix("#ffffff")
repeat
show layer master at alarm_red # 整屏红光脉动(警报感)7. 模糊(Blur)与景深
blur 是变换属性,给图加高斯模糊(GPU,自动转 model 渲染)。常用于背景虚化、聚焦、失神。
text
transform focus_pull:
blur 0.0
ease 0.5 blur 12.0 # 0.5 秒内逐渐模糊
label dizzy:
show eileen happy at focus_pull
"意识开始模糊……"背景虚化、突出立绘
text
transform bg_blur:
blur 8.0 matrixcolor BrightnessMatrix(-0.05)
label talk:
show bg room at bg_blur # 背景虚化压暗
show eileen happy # 立绘保持清晰
e "看着我。"8. 整层调色 / 模糊
对 master 整层套滤镜,一句话改变全场氛围:
text
show layer master:
matrixcolor SaturationMatrix(0.0) # 全场黑白9. 与旧式 im.MatrixColor 的关系
- 旧写法
im.MatrixColor("bg.png", im.matrix.tint(...))仍可用,但现代推荐用变换属性matrixcolor+*ColorMatrix(能用 ATL 动画、更灵活、走 GPU)。
常见坑
SaturationMatrix(0)= 灰度;(1)= 原始;别记反。- 多矩阵用
*串联,注意可读性,复杂调色封装成常量。 blur较吃 GPU,低端/网页端控制半径与使用范围。- 想要平滑过渡,务必用
linear/ease ... matrixcolor ...(直接赋值是瞬变)。 - 整屏滤镜放
show layer master;只调单图就作用在单图。
官方参考
- Matrixcolor:https://www.renpy.org/doc/html/matrixcolor.html
- 变换属性(matrixcolor / blur):https://www.renpy.org/doc/html/transform_properties.html
在 GenPy 里怎么做
- 在 GenPy 的代码模式中维护相关 .rpy 文件,先保持语法清晰,再逐步加入本章功能。
- 用故事图谱、变量、校验或演出编辑器把“能运行”提升到“可维护”。
- 导出前结合 Ren'Py Lint 和 GenPy 校验结果,确认脚本、素材和发布路径一致。
推荐继续阅读:
