Khas Advanced Lighting v4.2 Ultra (now with real-time shadows!)

Discussion in 'JS Plugin Releases (RMMV)' started by Khas, Apr 22, 2017.

    Tags:
  1. JamesRyan

    JamesRyan Game Designer Veteran

    Messages:
    590
    Likes Received:
    187
    Location:
    Vietnam
    First Language:
    Vietnamese
    Primarily Uses:
    RMMV
    So bad to hear that. I guess i have to manage to make it work well with MOG Time System. Btw, i have been able to make its transition look smoother by adding transition time to AmbientLight plugin command. I will use v3.2 for better performance, since i don't really need real-time shadows. Thanks for the update, Khas!
     
    Khas likes this.
  2. JamesRyan

    JamesRyan Game Designer Veteran

    Messages:
    590
    Likes Received:
    187
    Location:
    Vietnam
    First Language:
    Vietnamese
    Primarily Uses:
    RMMV
    By the way @Khas , i have tried Real Time Shadows in v4.2, and it is really fascinating. However, it uses Region Tags to define map's height, and i find this a bit uncomfortable. For example, i have a huge map with many region tags, some of them are more than 10 or even 20, and they are on the floor, not walls. However, the lights still cast shadows over those regions and it doesn't seem to be right. I know there is a command [light_shadows on/off] to toggle shadow casting, but i have to do it manually for every single light source. Do you have another method for this?

    Game_2017_10_02_21_33_08_592.png
     
    Last edited: Oct 3, 2017
  3. Espilonarge

    Espilonarge Veteran Veteran

    Messages:
    117
    Likes Received:
    51
    Location:
    Australia
    First Language:
    English
    I noticed the same issue as well. The problem is that unlike the VXAce version, you can't "define" Regions used for height in the plugins settings to prevent this hiccup with shadow oddities and while other plugins use regions (like Yanfly's Region Restriction plugin). The only (and current) solution to this is to alter the line mentioned in Kilitar's Post on line 568 in a text editor (I currently have it set to 100 instead of 10).

    This is something Khas should have accounted for to be honest.
     
    JamesRyan likes this.
  4. dragon1up

    dragon1up Veteran Veteran

    Messages:
    69
    Likes Received:
    7
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV

    No I did test just a fresh project with just your plugins being used and the same map had the same issues, well most likely edit this reply once tested the new versions out, if error persists I will make a little demo project, did try with 1.5.1 with the new update but error of the black screens persists maybe 1.5.2 would fix it honestly not sure. But will make a blank project soon.
     
    Last edited: Oct 3, 2017
  5. Tuomo L

    Tuomo L Oldbie Veteran

    Messages:
    2,292
    Likes Received:
    1,267
    Location:
    Finland!
    First Language:
    Finnish
    Primarily Uses:
    RMMV
    Still crashing with undefined is not function with new patch, @Nicke workaround doesn't help. Both advanced and ultra crash same way. Still can't update.

    TypeError: undefined is not a function
    at Game_Lighting.setAmbientLight (file:///E:/Enterbrain/MV/Strangers%20of%20Power%20-%20Copy%20(3)/js/plugins/KhasAdvancedLighting.js:682:26)
    at Game_Map.callKhasCommand (file:///E:/Enterbrain/MV/Strangers%20of%20Power%20-%20Copy%20(3)/js/plugins/KhasAdvancedLighting.js:420:61)
    at Game_Map.khasScanNote (file:///E:/Enterbrain/MV/Strangers%20of%20Power%20-%20Copy%20(3)/js/plugins/KhasCore.js:155:14)
    at Game_Map.setup (file:///E:/Enterbrain/MV/Strangers%20of%20Power%20-%20Copy%20(3)/js/plugins/KhasCore.js:140:12)
     
  6. Espilonarge

    Espilonarge Veteran Veteran

    Messages:
    117
    Likes Received:
    51
    Location:
    Australia
    First Language:
    English
    Looks like trying to make alterations/fixes to the region vs walls issue that Kilitar stated kind of backfired. Until Khas (or someone) can put in a piece of code to "restrain" the plugin from using every non-wall region value (eg = ignore 1-9 / 10 / ignore 11-19 / 20 / etc) it's going to be a seriously annoying bug. Again, this is something Khas should have identified as a major issue as this affects EVERY other plugin.
     
  7. Zizka

    Zizka Veteran Veteran

    Messages:
    127
    Likes Received:
    24
    First Language:
    English
    Primarily Uses:
    RMMV
    Looking good. Shadows can't be easy to code in I bet!
     
    Khas likes this.
  8. JamesRyan

    JamesRyan Game Designer Veteran

    Messages:
    590
    Likes Received:
    187
    Location:
    Vietnam
    First Language:
    Vietnamese
    Primarily Uses:
    RMMV
    I have a very little knowledge about JS, but I did this in my project. However, I have no idea if there will be a side effect. If you want to try, find this line in the plugin:
    Code:
    var h = Math.floor(this.regionId(x, y) / 10) * 2;
    Make a little change:
    Code:
    if (this.regionId(x, y) % 10 === 0){
            var h = Math.floor(this.regionId(x, y) / 10) * 2;
            this._heightMap[x].push(h);}
    By this way, only regions which can be divided by 10 (10, 20, 30 and so on) can cast shadow. Just a temporary method while waiting for another method from Khas.
     
    Kike likes this.
  9. Shade Aurion

    Shade Aurion Shadow Keeper Veteran

    Messages:
    60
    Likes Received:
    25
    Location:
    Brisbane, Au
    First Language:
    English
    Primarily Uses:
    RMMV
    Thank you for all your work Khas! When I can afford it i'll throw you the money for commercial use.

    One question. How would I turn off the day/night temporarily? Like for instance, if I were to walk into a cave and set an ambient light to be very dark and use a lantern to get around and then resume the flow of time once exiting the cave?
     
    Last edited: Oct 7, 2017
    Kike likes this.
  10. Espilonarge

    Espilonarge Veteran Veteran

    Messages:
    117
    Likes Received:
    51
    Location:
    Australia
    First Language:
    English
    Sadly your fix is not exactly working as intended.

    Any region that isn't divisible by 10 will now mis-aligning the shadows altogether. Region 1X/2X/3X/etc (where X is 1 through 9) will now generate shadows further south of the original location by 10 tiles.

    On top of this, any region that is divisible by 10 is not recognizing the height factor that is suppose to prevent light penetration.

    I've tried changing "% 10" to "% 100". While it does fix the mis-aligned shadows from being generated however, it also now breaks region-heights.
     
    Last edited: Oct 7, 2017
    Kike likes this.
  11. JamesRyan

    JamesRyan Game Designer Veteran

    Messages:
    590
    Likes Received:
    187
    Location:
    Vietnam
    First Language:
    Vietnamese
    Primarily Uses:
    RMMV
    Oh I have just realized that. Better wait a little bit more for an official fix.
     
  12. Khas

    Khas Detective lv73 Veteran

    Messages:
    282
    Likes Received:
    374
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    For performance reasons, I chose to keep two separate versions of this plugin: version 3 is the most lightweight, version 4 is the most performance intensive. The only difference between them are the shadows, so if you don't want shadows in your game, please use version 3.

    Regarding the shadow casting method, I tried many options and the one implemented is what I liked most. I know it's not perfect and it does demand some work on your maps, but please understand that there's no way for the system to know from where to cast shadows without telling it explicitly. I tried a more automatic method in the past, but it proved itself unreliable in many cases, so I'm keeping this one.

    There's no such thing as a universal plugin that will work for all games, so I implemented what I believed to be the most user friendly and reliable solution. Therefore, I'm not changing the way the plugin works. If you want something that suits your project better, feel free to edit the plugin.

    The function that must be edited is the following:
    Code:
    Game_Map.prototype.genHeightMap = function() {
        this._heightMap = [];
        for (var x = 0; x < this.width(); x++) {
          this._heightMap.push([]);
          for (var y = 0; y < this.height(); y++) {
            var h = Math.floor(this.regionId(x, y) / 10) * 2;
            this._heightMap[x].push(h);
          };
        };
        for (var x = 0; x < this.width(); x++) {
          for (var y = 0; y < this.height(); y++) {
            var h = this._heightMap[x][y];
            var nh = this.getHeight(x, y + 1);
            if (h > 0 && this.isFloor(x, y) && h > nh) {
              h -= 1;
              var dy = 1;
              while (h > 0 && (nh == 0 || h - 1 > nh) && this.isValid(x, y + dy)) {
                this.setHeight(x, y + dy, h);
                h -= 2;
                dy += 1;
                if (this.isValid(x, y + dy)) nh = this.getHeight(x, y + dy);
              };
            };
          };
        };
      };
    This line is responsible for generating the height based on the region tag. Heights equal to 0 are ignored.
    Code:
    var h = Math.floor(this.regionId(x, y) / 10) * 2;
    You may want to do something like this, for example, where region tags not multiples of 10 will be ignored. Note that the var h must always be equal to something, otherwise this will result in bugs.
    Code:
    // Check if the region tag is a multiple of ten
    if (this.regionId(x, y) % 10 == 0) {
      // Generate the height
      var h = Math.floor(this.regionId(x, y) / 10) * 2;
    
    } else {
      // Set the tile's height to zero
      var h = 0;
    }
    Another example, it will discard region tags bigger or equal than 50.
    Code:
    // Check if the region tag is a multiple of ten
    if (this.regionId(x, y) < 50) {
      // Generate the height
      var h = Math.floor(this.regionId(x, y) / 10) * 2;
    
    } else {
      // Set the tile's height to zero
      var h = 0;
    }


    @JamesRyan please check the statement above :)

    @Espilonarge when I made the similar system for the VX Ace version, people complained about the solution (it lacked multiple region tags for a given height). That is why I made something different this time. If 10 regions tags per height (0,1,2,3,4,5,6,7,8,9 can be used for height 0, and so on) are not enough (which is considered advanced use), feel free to edit the plugin.

    @Tuomo L can you send me a demo reproducing the error?

    @Shade Aurion you may set the ambient light for the two maps using the map notes. But if the question is related to any time system, I'm not the correct person to ask, sorry!
     
    Shade Aurion and JamesRyan like this.
  13. JamesRyan

    JamesRyan Game Designer Veteran

    Messages:
    590
    Likes Received:
    187
    Location:
    Vietnam
    First Language:
    Vietnamese
    Primarily Uses:
    RMMV
    Thanks, @Khas! I guess the "Divisible-by-10" method is the best so far. I can now use other region tags without worrying.
     
    Khas likes this.
  14. Shade Aurion

    Shade Aurion Shadow Keeper Veteran

    Messages:
    60
    Likes Received:
    25
    Location:
    Brisbane, Au
    First Language:
    English
    Primarily Uses:
    RMMV
    No probs man. I appreciate all you've done over the years. Thank you for this! You're a legend <3
     
    Khas likes this.
  15. JamesRyan

    JamesRyan Game Designer Veteran

    Messages:
    590
    Likes Received:
    187
    Location:
    Vietnam
    First Language:
    Vietnamese
    Primarily Uses:
    RMMV
    By the way, @Khas, there is something i have just noticed. The shadows which are generated by the default system are no longer shown in game. I can see and edit them in the Editor, but once i play test, there is none of them. I try to disable your Lighting plugin and the shadows appear again. Details are in my pictures below. I know your Ultra Lighting generates real-time shadows, but is it supposed to remove the default shadows?
    Game_2017_10_22_03_47_09_359.png
    Game_2017_10_22_03_46_02_761.png
     
    Last edited: Oct 25, 2017
  16. dragon1up

    dragon1up Veteran Veteran

    Messages:
    69
    Likes Received:
    7
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I switched back to terrax due to everything else I was running graphic plugin wise, as amazing as it looks just run to many graphics plug-ins in the end..
     
  17. bhindi1224

    bhindi1224 NOT Indian Okra Veteran

    Messages:
    295
    Likes Received:
    167
    First Language:
    English
    Primarily Uses:
    RMMV
    I've just started playing around with this plugin and was surprised at how easy it was to implement. I'm using the 3.0 version right now and experimenting. Just wanted to say I love this plugin and commend you on some great work.
     
    Khas likes this.
  18. Khas

    Khas Detective lv73 Veteran

    Messages:
    282
    Likes Received:
    374
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    @JamesRyan this is on purpose! You can remove this feature by commenting or removing the following lines:
    Code:
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // * ShaderTilemap
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      ShaderTilemap.prototype._drawShadow = function(layer, shadowBits, dx, dy) {
      };
     
  19. JamesRyan

    JamesRyan Game Designer Veteran

    Messages:
    590
    Likes Received:
    187
    Location:
    Vietnam
    First Language:
    Vietnamese
    Primarily Uses:
    RMMV
    Thanks @Khas. Personally, i don't think it is a good idea to remove default shadows. I mean there should be one natural light source (Sunlight, moonlight) and other lighting effects are used as lamps or something like that, because some places don't have lights, but they still need to have shadows generated under sunlight or moonlight.
     
    Khas and Kike like this.
  20. Kike

    Kike Paladin Veteran

    Messages:
    38
    Likes Received:
    21
    Location:
    Brasil
    First Language:
    Portuguese - Br
    Primarily Uses:
    RMMV
    :blink: Well... I disagree, in my opinion, the idea of remove default shadows make it have more sense, think about it, the plugin is about to use lights to generate shadows in real angle, :p there's no reason to see the default shadows appearing in wrong position.

    In the case of sunlight and moonlight, you have a point, however, an option to enable or disable cast shadows to make the default shadows enable could solve this :)
     

Share This Page