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

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
597
Reaction score
194
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!
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
597
Reaction score
194
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:

Espilonarge

Veteran
Veteran
Joined
Apr 24, 2016
Messages
124
Reaction score
56
First Language
English
Primarily Uses
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.
 

dragon1up

Veteran
Veteran
Joined
Sep 24, 2013
Messages
112
Reaction score
34
First Language
English
Primarily Uses
RMMV
Thanks for your patience, everyone! The plugin has been updated to fix bugs.

Please note that no feature will be added in possible future updates besides bug fixes.

Version 3.1 was updated to 3.2.
Version 4.0 was updated to 4.2 (so version 3 and 4 have the same minor version number).



@padr81 yes! You will need to add a custom light and change its offset in its declaration.

@Kirika fixed!

@DarthSarlos @Nguyen Phan Vy @HasdrubalBarca I have no intentions of making this plugin compatible with crashes made by 3rd party plugins. That being said, you may manually edit the plugin and see if it works.

Search for:
Game_Map.prototype.getHeight = function(x, y) {
return this.isValid(x, y) ? this._heightMap[x][y] : null;
};


Replace by this:
Game_Map.prototype.getHeight = function(x, y) {
x = Math.round(x);
y = Math.round(y);
return this.isValid(x, y) ? this._heightMap[x][y] : null;
};


@dragon1up let me see if I understood it correctly. If you create a fresh project, things work well. However, if you disable all the plugins (except mine) in your project, the error persists?

I would need a demo to take a look into this problem. There's nothing much I can do without testing it.

@monkeyintartan nope, you need to create your custom lights for that :)

@Kilitar thanks for your help :)

@JamesRyan I'm glad you like it! Regarding your request, I won't do it, I'm sorry. A lot of people ask me to make my plugin compatible with some time systems, but I feel the users are responsible to implement that kind of logic. After all, my plugin has nothing related to time control, so why should I add such thing? There's an add-on for compatibility with the Orange Time System in my Mega shared folder, if you want to take a look.

Regarding performance, version 4 is intensive, and version 3 is lightweight (it outperforms any other lighting plugin for MV). And about smooth transitions, the best way would be to implement a smoother interpolation (currently I'm doing linear interpolation), but this would require a bit of knowledge.

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:

Tuomo L

Oldbie
Veteran
Joined
Aug 6, 2012
Messages
2,294
Reaction score
1,270
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)
 

Espilonarge

Veteran
Veteran
Joined
Apr 24, 2016
Messages
124
Reaction score
56
First Language
English
Primarily Uses
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.
 

Zizka

Veteran
Veteran
Joined
Oct 6, 2017
Messages
127
Reaction score
24
First Language
English
Primarily Uses
RMMV
Looking good. Shadows can't be easy to code in I bet!
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
597
Reaction score
194
First Language
Vietnamese
Primarily Uses
RMMV
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.
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.
 

Shade Aurion

Shadow Keeper
Veteran
Joined
Nov 17, 2014
Messages
60
Reaction score
25
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:

Espilonarge

Veteran
Veteran
Joined
Apr 24, 2016
Messages
124
Reaction score
56
First Language
English
Primarily Uses
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:

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
597
Reaction score
194
First Language
Vietnamese
Primarily Uses
RMMV
Oh I have just realized that. Better wait a little bit more for an official fix.
 

Khas

Detective lv73
Veteran
Joined
Sep 16, 2012
Messages
282
Reaction score
375
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!
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
597
Reaction score
194
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.
 

Shade Aurion

Shadow Keeper
Veteran
Joined
Nov 17, 2014
Messages
60
Reaction score
25
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
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
597
Reaction score
194
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:

dragon1up

Veteran
Veteran
Joined
Sep 24, 2013
Messages
112
Reaction score
34
First Language
English
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)
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..
 

bhindi1224

NOT Indian Okra
Veteran
Joined
Sep 19, 2017
Messages
295
Reaction score
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

Detective lv73
Veteran
Joined
Sep 16, 2012
Messages
282
Reaction score
375
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) {
  };
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
597
Reaction score
194
First Language
Vietnamese
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) {
  };
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.
 

Kike

Paladin
Veteran
Joined
Nov 18, 2015
Messages
40
Reaction score
21
First Language
Portuguese - Br
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.
: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 :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Posts

Latest Profile Posts

Please watch out for your hands when handling chests! XD Did this a few days ago, it was fun to animate

Apparently, it's illegal to be drunk on licensed premises: pubs, etc. It's illegal for keepers of public houses to permit drunkenness and disorderly conduct. lol.
Pillow Hero - A 16-bit arcade styled puzzle game, update 0.5 is live now on Itch.io! --> https://bifrost09.itch.io/pillow-hero
Would you pay monthly for your pc if you'd get "free" upgrades every 2 years?
well, I definitely have a type, cute redheads with medusa piercings, met and hit it off with two of them in the last 72 hours, what does it mean lol?

Forum statistics

Threads
94,431
Messages
920,884
Members
124,236
Latest member
AkiraSenki
Top