Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

write for me an rpg maker mv script that adds bloom, write in jscript. be detailed and…

  1. User

    write for me an rpg maker mv script that adds bloom, write in jscript. be detailed and customized

  2. Assistant

    Certainly! I'll help you create a custom RPG Maker MV plugin that adds a bloom effect using JavaScript. The bloom effect will enhance your game’s visuals by making bright areas glow, giving a soft and luminous atmosphere.

    Below is the detailed script for the plugin, along with explanations and customization options.


    Plugin: BloomEffect.js

    /*:
     * @plugindesc Adds a customizable bloom effect to your game using PIXI filters. ✨
     * @author 
     *
     * @param Threshold
     * @text Bloom Threshold
     * @type number
     * @decimals 2
     * @min 0
     * @max 1
     * @desc The luminance threshold for bloom. Range: 0 (full bloom) to 1 (no bloom).
     * @default 0.5
     *
     * @param Bloom Blur Strength
     * @text Bloom Blur Strength
     * @type number
     * @min 0
     * @decimals 2
     * @desc Controls the blur radius of the bloom effect.
     * @default 8.0
     *
     * @param Bloom Brightness
     * @text Bloom Brightness
     * @type number
     * @min 0
     * @decimals 2
     * @desc Controls the brightness of the bloom effect.
     * @default 1.5
     *
     * @help
     * ============================================================================
     * **Bloom Effect Plugin**
     * ============================================================================
     * This plugin adds a beautiful bloom effect to your RPG Maker MV game using
     * PIXI's built-in filters. Customize the intensity, blur, and brightness to
     * achieve the desired glow effect.
     *
     * **Plugin Commands:**
     *
     * - `BloomThreshold [value]`  
     *   Set the bloom threshold (0 to 1).
     *
     * - `BloomBlur [value]`  
     *   Set the bloom blur strength.
     *
     * - `BloomBrightness [value]`  
     *   Set the bloom brightness.
     *
     * - `EnableBloom`  
     *   Enable the bloom effect.
     *
     * - `DisableBloom`  
     *   Disable the bloom effect.
     *
     * **Examples:**
     *
     * - `BloomThreshold 0.7`
     * - `BloomBlur 10.0`
     * - `BloomBrightness 2.0`
     * - `EnableBloom`
     * - `DisableBloom`
     *
     * **Terms of Use:**
     *
     * Free to use in both non-commercial and commercial projects. Attribution is
     * appreciated but not required.
     *
     * **Support:**
     *
     * For questions or support, feel free to reach out.
     * ============================================================================
     */
    
    (() => {
        const pluginName = 'BloomEffect';
    
        // Retrieve plugin parameters
        const parameters = PluginManager.parameters(pluginName);
        let bloomThreshold = parseFloat(parameters['Threshold'] || '0.5');
        let bloomBlur = parseFloat(parameters['Bloom Blur Strength'] || '8.0');
        let bloomBrightness = parseFloat(parameters['Bloom Brightness'] || '1.5');
        let bloomEnabled = true;
    
        // Initialize the bloom filter
        const bloomFilter = new PIXI.filters.AdvancedBloomFilter({
            threshold: bloomThreshold,
            bloomScale: bloomBrightness,
            brightness: bloomBrightness,
            blur: bloomBlur,
            quality: 4,
        });
    
        // Apply bloom filter to the scene
        const applyBloomFilter = () => {
            const scene = SceneManager._scene;
            if (scene && scene.filters && bloomEnabled) {
                if (!scene.filters.includes(bloomFilter)) {
                    scene.filters.push(bloomFilter);
                }
            }
        };
    
        // Remove bloom filter from the scene
        const removeBloomFilter = () => {
            const scene = SceneManager._scene;
            if (scene && scene.filters) {
                const index = scene.filters.indexOf(bloomFilter);
                if (index > -1) {
                    scene.filters.splice(index, 1);
                }
            }
        };
    
        // Update bloom filter settings
        const updateBloomFilter = () => {
            bloomFilter.threshold = bloomThreshold;
            bloomFilter.bloomScale = bloomBrightness;
            bloomFilter.brightness = bloomBrightness;
            bloomFilter.blur = bloomBlur;
        };
    
        // Override SceneManager.update to apply/remove bloom filter
        const _SceneManager_updateMain = SceneManager.updateMain;
        SceneManager.updateMain = function() {
            _SceneManager_updateMain.call(this);
            if (bloomEnabled) {
                applyBloomFilter();
            } else {
                removeBloomFilter();
            }
        };
    
        // Process plugin commands
        const _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
        Game_Interpreter.prototype.pluginCommand = function(command, args) {
            _Game_Interpreter_pluginCommand.call(this, command, args);
            if (command === 'BloomThreshold') {
                const value = parseFloat(args[0]);
                if (!isNaN(value) && value >= 0 && value <= 1) {
                    bloomThreshold = value;
                    updateBloomFilter();
                } else {
                    console.warn('BloomEffect Plugin: Invalid value for BloomThreshold. It must be between 0 and 1.');
                }
            } else if (command === 'BloomBlur') {
                const value = parseFloat(args[0]);
                if (!isNaN(value) && value >= 0) {
                    bloomBlur = value;
                    updateBloomFilter();
                } else {
                    console.warn('BloomEffect Plugin: Invalid value for BloomBlur. It must be 0 or greater.');
                }
            } else if (command === 'BloomBrightness') {
                const value = parseFloat(args[0]);
                if (!isNaN(value) && value >= 0) {
                    bloomBrightness = value;
                    updateBloomFilter();
                } else {
                    console.warn('BloomEffect Plugin: Invalid value for BloomBrightness. It must be 0 or greater.');
                }
            } else if (command === 'EnableBloom') {
                bloomEnabled = true;
                applyBloomFilter();
            } else if (command === 'DisableBloom') {
                bloomEnabled = false;
                removeBloomFilter();
            }
        };
    })();
    

    Explanation & Customization

    Plugin Parameters:

    • Threshold (Bloom Threshold):
      Determines the luminance threshold for applying bloom. Values range from 0 (applies bloom to all areas) to 1 (applies bloom to only the brightest areas). Default is 0.5.

    • Bloom Blur Strength:
      Adjusts the blur radius of the bloom effect. Higher values result in a softer and more spread-out glow. Default is 8.0.

    • Bloom Brightness:
      Controls the intensity of the bloom's brightness. Default is 1.5.

    Main Components:

    • Bloom Filter Initialization:
      The PIXI.filters.AdvancedBloomFilter is initialized with the parameters. This filter is part of PIXI.js, which RPG Maker MV uses for rendering.

    • Applying and Removing the Filter:

      • applyBloomFilter: Adds the bloom filter to the current scene's filters.
      • removeBloomFilter: Removes the bloom filter from the current scene's filters.
    • Updating the Filter Settings:
      The updateBloomFilter function updates the bloom filter's properties if the parameters change.

    • SceneManager Override:
      The SceneManager.updateMain method is overridden to apply or remove the bloom filter each frame based on whether bloom is enabled.

    • Plugin Commands Processing:
      The plugin commands allow in-game adjustment of the bloom settings and toggling the bloom effect on or off.

    Plugin Commands:

    • BloomThreshold [value]
      Sets the bloom threshold to a value between 0 and 1.

    • BloomBlur [value]
      Sets the bloom blur strength (any non-negative number).

    • BloomBrightness [value]
      Sets the bloom brightness (any non-negative number).

    • EnableBloom
      Enables the bloom effect.

    • DisableBloom
      Disables the bloom effect.

    Quality Setting (Advanced):

    • Inside the bloom filter initialization, the quality parameter is set to 4. This affects the rendering quality of the bloom effect.
      • Lower values: Faster performance but lower quality.
      • Higher values: Better quality but may impact performance.

    You can adjust this by modifying the quality property:

    const bloomFilter = new PIXI.filters.AdvancedBloomFilter({
        // ... other settings ...
        quality: 4, // Adjust between 1 and 7
    });
    

    How to Use This Plugin

    1. Installation:

    • Step 1: Copy the entire script provided above.

    • Step 2: Open a text editor (like Notepad) and paste the script.

    • Step 3: Save the file as BloomEffect.js.

    • Step 4: Place the BloomEffect.js file into your RPG Maker MV project's js/plugins directory.

    2. Activating the Plugin:

    • Step 1: Open your project in RPG Maker MV.

    • Step 2: Go to Tools > Plugin Manager.

    • Step 3: Click on an empty row and double-click to open the plugin selection.

    • Step 4: Find and select BloomEffect from the list.

    • Step 5: Ensure the plugin is set to ON.

    • Step 6: Configure the plugin parameters as desired.

    3. Using Plugin Commands:

    • Step 1: In your game, create an event where you want to adjust the bloom settings.

    • Step 2: Add a Plugin Command event command.

    • Step 3: Enter one of the plugin commands:

      • Adjust Threshold:
        BloomThreshold 0.7

      • Adjust Blur Strength:
        BloomBlur 10.0

      • Adjust Brightness:
        BloomBrightness 2.0

      • Enable Bloom:
        EnableBloom

      • Disable Bloom:
        DisableBloom

    • Step 4: Test the event to see the changes in effect.


    Additional Customization

    Dynamic Adjustments:

    You can create events that adjust the bloom effect dynamically based on in-game conditions, such as time of day or entering specific areas.

    Performance Considerations:

    • High-Quality Settings:
      Setting the quality parameter too high might affect performance on lower-end devices. Test on your target platforms.

    • Conditional Application:
      If certain scenes don't require bloom, consider disabling it with the DisableBloom command to optimize performance.

    Visual Tweaking:

    Experiment with different combinations of threshold, blur strength, and brightness to achieve the perfect glow for your game.


    Support and Troubleshooting

    • Testing:
      Always test your game after adding or adjusting plugins to ensure they work as intended.

    • Compatibility:
      If you have other plugins that affect rendering or use filters, ensure compatibility by adjusting their order in the Plugin Manager.

    • Updates:
      Keep your RPG Maker MV software up to date to ensure all features work correctly.


    Conclusion

    You've now added a dynamic and customizable bloom effect to your RPG Maker MV game! This effect can significantly enhance the visual appeal, making bright areas glow beautifully.

    Feel free to reach out if you have any questions or need further assistance with customization. Happy game developing! 🎮✨