melonjs-effects-and-shaders
Skill này làm gì
Skill giải thích các hiệu ứng hình ảnh có sẵn trong melonJS và cách gắn chúng vào sprite hoặc toàn bộ camera. Dành cho lập trình viên trò chơi muốn hình ảnh đẹp và hoàn thiện.
Khi nào nên dùng
- ✓Khi lập trình viên muốn hiệu ứng phát sáng hoặc vignette trên một sprite trong trò chơi melonJS.
- ✓Khi lập trình viên muốn một lượt chỉnh màu trên toàn bộ màn hình trò chơi.
- ✓Khi hiệu ứng của lập trình viên không có tác dụng trên thiết bị không có backend GPU.
Liên kết skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-effects-and-shaders/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Thêm hiệu ứng phát sáng vào sprite nhân vật của tôi trong melonJS.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill chỉ cách gắn một hiệu ứng có sẵn vào renderable hoặc camera, và cảnh báo rằng hiệu ứng shader cần backend GPU và không làm gì trên chế độ Canvas dự phòng.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Post effects and custom shaders
melonJS ships a catalogue of post effects and a dual-language shader system. The recurring trap is that every shader path needs a GPU backend and degrades to nothing on Canvas rather than erroring. Blend modes are the exception — those work on all three renderers.
Applying an effect
Effects attach to a renderable or to a camera (for full-screen grading):
import { VignetteEffect, GlowEffect } from "melonjs";
sprite.addPostEffect(new GlowEffect(app.renderer));
app.viewport.addPostEffect(new VignetteEffect(app.renderer));
renderable.shader = … is deprecated since 19.2.0, and its setter destroys
whatever it replaces. Use addPostEffect / getPostEffect / removePostEffect.
A camera effect covers the HUD too
A camera's post-effect brackets the entire world draw — floating children included. So the obvious way to write a full-screen pass also washes over every HUD label in that world, which is rarely what you want.
To land a pass after the world but before the HUD, host the effect on a screen-filling floating renderable ordered below the HUD's z instead:
const quad = new Sprite(0, 0, { image: anyImage });
quad.anchorPoint.set(0, 0);
quad.scale(viewW / anyImage.width, viewH / anyImage.height);
quad.floating = true; // its own uv is now screen space
quad.blendMode = "additive";
quad.addPostEffect(myEffect);
world.addChild(quad, HUD_Z - 10); // 2D: below the labels. See the note.
Two things follow from the quad filling the frame: its own uv is screen space
(so a pass like this needs none of the screen_uv / screen_texture builtins),
and the incoming color is the quad's own texture, which a body that paints
from scratch can ignore entirely.
Depth here is easy to get backwards, and the rule FLIPS between the two sort
modes. Under the default sortOn = "z" a higher z draws later, i.e. on top,
so HUD_Z - 10 puts the pass under the labels as written above. Under
sortOn = "depth", which every Camera3d scene sets, a floating child's sort
key is pos.z * pos.z and the walk paints far to near, so the SMALLER
magnitude is nearer and draws on top — HUD_Z - 10 there puts the pass OVER
the labels, the opposite of the comment.
So in a 3D scene give the overlay a larger magnitude than the HUD, and give
the HUD a small one (melonjs-3d and melonjs-ui-and-text both say a HUD
wants a small depth, not the huge z that would put it on top in 2D).
Either way, verify it rather than reasoning about it: return a flat colour from the body for one frame and see what it tints.
A renderable that draws with PRIMITIVES has to ask to be captured
One effect is applied the cheap way: the renderable is drawn with the effect's
own program instead of being captured offscreen and post-processed, which costs
no render target. That is equivalent only when everything the renderable draws
is a textured quad. fillRect, strokeRect and renderer.fill(shape) go
through a batcher that never reads that shader, so one effect on such a
renderable would silently do nothing, while two would work, because a chain
always captures.
So a renderable of your own that draws with primitives says so:
class Bar extends Renderable {
constructor(x, y, w, h) {
super(x, y, w, h);
this.postEffectNeedsCapture = true; // ← or one effect is a no-op
}
draw(renderer) {
renderer.fillRect(this.pos.x, this.pos.y, this.width, this.height);
}
}
ProgressBar and Trail set it for you, and a sprite needs nothing: the flag
defaults to false and only ever changes the single-effect case.
Toggle with enabled, do not remove
removePostEffect() destroys the effect — it calls effect.destroy() and
frees GPU resources, so the instance cannot be re-added. Same for
clearPostEffects() and for reassigning the deprecated .shader.
// ✗ destroys it; re-adding later fails or forces a recompile
sprite.removePostEffect(effect);
// ✓
effect.enabled = false;
An effect with effect.shared === true opts out of auto-destroy because it is
reused across renderables.
Built-in effects
Twenty-three presets, every one constructed as new XEffect(renderer, options)
and every one shipping both a GLSL and a WGSL body, so they all run on either
GPU backend: VignetteEffect, ScanlineEffect (optional CRT curvature),
BloomEffect, GlowEffect, BlurEffect, `PixelateEffect
Câu hỏi thường gặp
Vì sao hiệu ứng shader của tôi không hiện?
Skill nói hiệu ứng shader cần backend GPU và âm thầm không làm gì trên chế độ Canvas dự phòng.
Hiệu ứng có thể chỉ áp dụng cho một phần màn hình không?
Skill mô tả một cách đặt lượt xử lý toàn màn hình phía trên thế giới nhưng dưới phần hiển thị trên màn hình.
Thuộc tính shader cũ còn được dùng không?
Không. Skill nói nó đã bị loại bỏ và khuyên dùng các phương thức hiệu ứng hậu xử lý.
Chi tiết
Mô tả gốc của tác giả
Use this skill for post-processing effects, custom shaders, blend modes and colour grading in melonJS. Covers the built-in ShaderEffect presets, addPostEffect on renderables and cameras, writing a custom dual-language GLSL/WGSL effect, the screen_texture builtins, and why effects silently do nothing on the Canvas fallback. Triggers on: Tween, easing, animate an effect, ShaderEffect, addPostEffect, removePostEffect, getPostEffect, postEffectNeedsCapture, VignetteEffect, GlowEffect, BlurEffect, PixelateEffect, ScanlineEffect, shader, GLSL, WGSL, uniform, setUniform, setTexture, setTime, blendMod
repo: melonjs/melonJS
Độ phổ biến
- Sao GitHub
- 6.4k
- Vị trí xếp hạng
- #14201
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
melonjs-20-migration
6.4kGiúp agent của bạn viết mã trò chơi melonJS cho phiên bản 20 và tránh các phương thức cũ, như bước khởi động bất đồng bộ bắt buộc.
melonjs-3d-assets
6.4kGiúp agent của bạn tải mô hình 3D như file glTF, GLB và OBJ vào trò chơi trình duyệt melonJS, kèm tùy chọn tỷ lệ và ánh sáng.
melonjs-3d
6.4kGiúp agent của bạn xây dựng cảnh 3D hoặc 2.5D trong trò chơi trình duyệt melonJS, gồm camera, lưới, đèn và độ sâu, theo quy tắc trục của công cụ.
melonjs-audio
6.4kGiúp agent của bạn thêm hiệu ứng âm thanh và nhạc nền vào trò chơi melonJS, gồm thiết lập âm thanh, nhạc nền, điều chỉnh âm lượng và âm thanh không gian.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.