njin
Engine 2D gọn nhẹ để tự tay làm game theo ý mình. Vibe coding cũng ổn luôn
Loading...
Searching...
No Matches
njin_post.h
1#pragma once
2#include "_types.h"
3
4namespace njin {
5struct context;
6
9
20struct post_fx {
23 f32 brightness = 0.0f;
24 f32 contrast = 1.0f;
25 f32 saturation = 1.0f;
26 f32 sepia = 0.0f;
27 rgba tint{1.0f, 1.0f, 1.0f, 1.0f};
29
32 f32 vignette = 0.0f;
35 rgba vignette_color{0.0f, 0.0f, 0.0f, 1.0f};
37
40 f32 bloom = 0.0f;
44
47 f32 blur = 0.0f;
48 f32 chromatic = 0.0f;
49 f32 scanlines = 0.0f;
51 f32 crt_curve = 0.0f;
52 f32 pixelate = 0.0f;
53 f32 grain = 0.0f;
55
63 f32 dof = 0.0f;
64 f32 dof_focus = 10.0f;
65 f32 dof_range = 2.0f;
66 f32 dof_falloff = 10.0f;
71 vec3 dof_center{0.0f, 0.0f, 0.0f};
72 f32 dof_radius = 0.0f;
75 rgba dof_haze{0.0f, 0.0f, 0.0f, 0.0f};
77};
78
82void post_fx_set(context &ctx, const post_fx &fx);
83
87post_fx post_fx_get(const context &ctx);
88
94post_fx post_fx_lerp(const post_fx &a, const post_fx &b, f32 t);
95
103namespace post {
106inline post_fx crt() {
107 post_fx p{};
108 p.crt_curve = 0.12f;
109 p.scanlines = 0.35f;
110 p.chromatic = 1.5f;
111 p.vignette = 0.45f;
112 p.contrast = 1.1f;
113 p.brightness = 0.03f;
114 return p;
115}
116
119inline post_fx noir() {
120 post_fx p{};
121 p.saturation = 0.0f;
122 p.contrast = 1.25f;
123 p.vignette = 0.6f;
124 p.vignette_radius = 0.65f;
125 p.grain = 0.08f;
126 return p;
127}
128
131inline post_fx vintage() {
132 post_fx p{};
133 p.sepia = 0.8f;
134 p.contrast = 0.9f;
135 p.vignette = 0.5f;
136 p.grain = 0.05f;
137 return p;
138}
139
142inline post_fx dream() {
143 post_fx p{};
144 p.bloom = 0.9f;
145 p.bloom_threshold = 0.55f;
146 p.bloom_radius = 1.6f;
147 p.saturation = 1.15f;
148 p.vignette = 0.25f;
149 return p;
150}
151
154inline post_fx glow() {
155 post_fx p{};
156 p.bloom = 1.0f;
157 p.bloom_threshold = 0.65f;
158 return p;
159}
160
163inline post_fx retro() {
164 post_fx p{};
165 p.pixelate = 4.0f;
166 p.scanlines = 0.2f;
167 p.scanline_size = 4.0f;
168 p.saturation = 1.1f;
169 return p;
170}
171
175inline post_fx hurt() {
176 post_fx p{};
177 p.vignette = 0.7f;
178 p.vignette_radius = 0.6f;
179 p.vignette_color = {0.6f, 0.0f, 0.0f, 1.0f};
180 p.saturation = 0.7f;
181 return p;
182}
183
186inline post_fx paused() {
187 post_fx p{};
188 p.blur = 6.0f;
189 p.brightness = -0.15f;
190 p.saturation = 0.6f;
191 return p;
192}
193} // namespace post
194
195} // namespace njin
void post_fx_set(context &ctx, const post_fx &fx)
Đặt các hiệu ứng post-processing dựng sẵn.
post_fx post_fx_lerp(const post_fx &a, const post_fx &b, f32 t)
Nội suy giữa hai bộ hiệu ứng, để chuyển mượt (ví dụ vào menu pause).
post_fx post_fx_get(const context &ctx)
Các hiệu ứng đang đặt.
float f32
Số thực 32 bit.
Definition _types.h:28
Các mẫu particle hay dùng, để truyền vào particles_spawn() hoặc gắn thẳng lên entity.
Definition njin_fx.h:147
Các bộ post_fx hay dùng.
Definition njin_post.h:103
post_fx paused()
Menu pause: thế giới mờ và tối phía sau UI.
Definition njin_post.h:186
post_fx hurt()
Bị thương hoặc máu thấp: viền đỏ, hơi nhạt màu.
Definition njin_post.h:175
post_fx vintage()
Ảnh cũ: ngả nâu, hơi mờ nhạt, tối viền.
Definition njin_post.h:131
post_fx retro()
Pixel thô kiểu máy 8-bit, kèm sọc nhẹ.
Definition njin_post.h:163
post_fx dream()
Mơ màng: quầng sáng rộng, màu tươi hơn, tối viền nhẹ.
Definition njin_post.h:142
post_fx glow()
Sáng rực: bloom cho game neon, lửa, phép thuật.
Definition njin_post.h:154
post_fx crt()
Màn hình CRT cũ: cong, sọc, tách màu nhẹ, tối viền.
Definition njin_post.h:106
post_fx noir()
Phim đen trắng: không màu, tương phản cao, tối viền, nhiễu hạt.
Definition njin_post.h:119
Các hiệu ứng post-processing dựng sẵn, áp lên thế giới (không lên UI).
Definition njin_post.h:20
f32 scanline_size
Khoảng cách giữa các sọc, pixel màn hình.
Definition njin_post.h:50
f32 grain
Nhiễu hạt kiểu phim, 0..0.3. 0 là tắt.
Definition njin_post.h:53
f32 dof_focus
Khoảng cách nét nhất.
Definition njin_post.h:64
f32 pixelate
Cỡ ô vuông pixel hóa, pixel màn hình. Dưới 2 là tắt.
Definition njin_post.h:52
f32 blur
Làm mờ cả khung hình, bán kính pixel. 0 là tắt. Cho menu pause.
Definition njin_post.h:47
rgba vignette_color
Màu viền. Đỏ cho hiệu ứng máu thấp.
Definition njin_post.h:35
f32 sepia
Mức ngả màu ảnh cũ, 0..1.
Definition njin_post.h:26
f32 crt_curve
Độ cong kiểu màn CRT, 0..0.3. 0 là tắt.
Definition njin_post.h:51
f32 contrast
Độ tương phản. 1 là giữ nguyên.
Definition njin_post.h:24
f32 dof_radius
Bán kính vùng nét quanh dof_center.
Definition njin_post.h:72
f32 vignette_radius
Bán kính vùng sáng, tính từ tâm (0.7 gần tới cạnh).
Definition njin_post.h:33
f32 dof
Độ mờ tối đa của phần ngoài tiêu điểm, bán kính pixel. 0 là tắt.
Definition njin_post.h:63
f32 vignette_softness
Độ mềm của viền.
Definition njin_post.h:34
f32 saturation
Độ bão hòa. 0 là đen trắng, 1 là giữ nguyên.
Definition njin_post.h:25
f32 vignette
Độ đậm, 0..1. 0 là tắt.
Definition njin_post.h:32
f32 bloom_threshold
Chỉ vùng sáng hơn mức này (0..1) mới tỏa sáng.
Definition njin_post.h:41
rgba tint
Màu nhân vào cả khung hình.
Definition njin_post.h:27
f32 dof_range
Nét hoàn toàn trong khoảng dof_focus ± dof_range.
Definition njin_post.h:65
f32 chromatic
Tách màu đỏ/xanh ở rìa, pixel. 0 là tắt. 2–6 cho cú đánh mạnh.
Definition njin_post.h:48
f32 dof_falloff
Quãng mờ dần từ nét đến mờ nhất, sau dof_range (hay dof_radius).
Definition njin_post.h:66
rgba dof_haze
Màu phủ lên phần ngoài tiêu điểm, đậm theo độ mờ; a là độ đậm ở chỗ mờ nhất.
Definition njin_post.h:75
f32 brightness
Độ sáng cộng thêm, -1..1. 0 là tắt.
Definition njin_post.h:23
f32 scanlines
Độ đậm của sọc ngang kiểu màn CRT, 0..1. 0 là tắt.
Definition njin_post.h:49
vec3 dof_center
Tâm vùng nét, đơn vị 3D, khi dof_radius > 0: độ nét tính theo khoảng cách từ mỗi điểm của cảnh tới đâ...
Definition njin_post.h:71
f32 bloom_radius
Độ tỏa. 1 là mặc định, 2 là rộng gấp đôi.
Definition njin_post.h:42
f32 bloom
Độ mạnh. 0 là tắt, 0.5–1.5 là thường dùng.
Definition njin_post.h:40
Màu gồm đỏ, xanh lá, xanh dương và alpha.
Definition _types.h:64
Vector 3 chiều.
Definition _types.h:47