मुख्य सामग्री पर जाएँ
Skillpedia
सामान्य कोडिंग6.4k · #14201

melonjs-effects-and-shaders

यह क्या करती है

यह melonJS के अंतर्निहित दृश्य प्रभाव और उन्हें किसी sprite या पूरे कैमरा से कैसे जोड़ें, यह समझाती है। यह उन गेम डेवलपर्स के लिए है जिन्हें परिष्कृत दृश्य चाहिए।

कब इस्तेमाल करें

  • ✓जब डेवलपर melonJS गेम में किसी sprite पर ग्लो या vignette प्रभाव चाहे।
  • ✓जब डेवलपर पूरे गेम स्क्रीन पर रंग ग्रेडिंग पास चाहे।
  • ✓जब डेवलपर का प्रभाव GPU बैकएंड के बिना डिवाइस पर कुछ न करे।

Skill का लिंक

https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-effects-and-shaders/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-effects-and-shaders/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरे melonJS किरदार sprite में ग्लो इफ़ेक्ट जोड़िए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह स्किल दिखाती है कि अंतर्निहित प्रभाव को renderable या कैमरा से कैसे जोड़ें, और चेताती है कि shader प्रभाव GPU बैकएंड माँगते हैं और Canvas फ़ॉलबैक पर कुछ नहीं करते।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

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

अक्सर पूछे जाने वाले सवाल

मेरा shader प्रभाव क्यों नहीं दिखता?

स्किल कहती है कि shader प्रभाव को GPU बैकएंड चाहिए, और Canvas फ़ॉलबैक पर वे चुपचाप कुछ नहीं करते।

क्या प्रभाव स्क्रीन के केवल एक हिस्से पर लग सकता है?

स्किल एक तरीका बताती है जिसमें पूरी स्क्रीन का पास दुनिया के ऊपर पर on-screen डिस्प्ले के नीचे रखा जाता है।

क्या पुरानी shader प्रॉपर्टी अब भी इस्तेमाल होती है?

नहीं। स्किल कहती है कि यह deprecated है और उसकी जगह post-effect मेथड सुझाती है।

जानकारी

लेखक का मूल विवरण

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

लोकप्रियता

GitHub स्टार
6.4k
रैंकिंग में स्थान
#14201
लाइसेंस
MIT
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

melonjs-20-migration

6.4k

आपके एजेंट को melonJS वर्शन 20 के लिए गेम कोड लिखने में मदद करती है और पुराने वर्शन के आउटडेटेड तरीकों से बचाती है, जैसे ज़रूरी async स्टार्टअप।

कोडिंगसामान्य कोडिंग

melonjs-3d-assets

6.4k

आपके एजेंट को glTF, GLB और OBJ जैसे 3D मॉडल melonJS ब्राउज़र गेम में लोड करने में मदद करती है, scale और lighting विकल्पों के साथ।

कोडिंगसामान्य कोडिंग

melonjs-3d

6.4k

आपके एजेंट को melonJS ब्राउज़र गेम में 3D या 2.5D दृश्य बनाने में मदद करती है, जिसमें कैमरा, मेश, लाइट और गहराई शामिल हैं, इंजन के अपने axis नियमों के साथ।

कोडिंगसामान्य कोडिंग

melonjs-audio

6.4k

आपके एजेंट को melonJS गेम में साउंड इफ़ेक्ट और संगीत जोड़ने में मदद करती है, जिसमें ऑडियो सेटअप, बैकग्राउंड ट्रैक, वॉल्यूम नियंत्रण और स्थानिक ध्वनि शामिल हैं।

कोडिंगसामान्य कोडिंग

मिलती-जुलती skills