YouGroove Posted February 17, 2014 Share Posted February 17, 2014 When alien is dead and stays immobile on map , i want it to consume less GPU, os i wonder if it is possible to turn shadow and shader-shadow both off for some entity in Lua ? Perhaps i missed the function, but didn't find it in Entity commands reference ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
DudeAwesome Posted February 17, 2014 Share Posted February 17, 2014 I also looking for something to do this. 1 Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
AggrorJorn Posted February 18, 2014 Share Posted February 18, 2014 This option is set for the material: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/material/materialsetshadowmode-r257 Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 18, 2014 Author Share Posted February 18, 2014 It's C++ only no ? I got this code and it says mat is nll ? mat = self.entity:GetMaterial() mat:SetShadowMode(false) the model is a simple one with assigned material and shader in the scene, so it has a material indeed. There is also shadows enabled or not in Appearence tab not only on material, should we also specify something for the shadow mode of Appearence Tab ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rastar Posted February 18, 2014 Share Posted February 18, 2014 If a method isn't supported in Lua, the compiler complains that you're trying to access non-existing property XY. If you get a nil mat then the call was successful, but the entity doesn't have a material. Are you sure you're calling GetMaterial() on the correct entity? self.entity will be the scene object to which the script is assigned, is that the correct one? By the way, I think calling that method will change the shadow casting for all models that use that material (even for the non-dead aliens). So maybe you should create a "Dead alien material" and assign that using SetMaterial(). Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 18, 2014 Author Share Posted February 18, 2014 Are you sure you're calling GetMaterial() on the correct entity? self.entity will be the scene object to which the script is assigned, is that the correct one? Yes, the previous code works so GetMaterial should work. --Stop navigation call self.entity:Stop() self.entity:SetColor(0,0,0) self.entity:SetMass(0) self.entity:SetCollisionType(Collision.None) mat = self.entity:GetMaterial() mat:SetShadowMode(false) So it's a bug or it's not available in Lua ? By the way, I think calling that method will change the shadow casting for all models that use that material (even for the non-dead aliens). So maybe you should create a "Dead alien material" and assign that using SetMaterial(). You are totally right, i hope SetMaterial to work. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted February 18, 2014 Author Share Posted February 18, 2014 Even SetMaterial i have errors. I tried Script.matKo=nil --path ... After setting path in Script input folder self.enity:SetMaterial(matKo,false) self.enity:SetMaterial("myPath/matko.mat" ,false) etc ... Well i got errors all the time ? Argument 2 for example should be mat, if i change it argument 2 should be String etc ... Is SetMaterial possible only with Material created by code ? Or can we assign a Material for who we give the String path ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted February 18, 2014 Share Posted February 18, 2014 Path returns the string path to the material NOT the material object itself. You have to first load the material from the path and then use the loaded material variable in SetMaterial(). local mat = Material:Load(self.matKo) self.entity:SetMateria:(mat) Quote Link to comment Share on other sites More sharing options...
Rastar Posted February 18, 2014 Share Posted February 18, 2014 ..and just to be sure.. in your sample code you write "self.enity" instead of "self.entity" (though that might just be in your post and not your code) Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted February 18, 2014 Share Posted February 18, 2014 I have used in one of early projects, so I assumed it would still work. Not all commands of the Material class seem to have examples. bug report made. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 18, 2014 Author Share Posted February 18, 2014 Thanks. So changing material seemed to work at some point. My aliens are not prefab, but duplicated entities. Strange because specifying material path for one or two seems to impact all other even when not in dead state ? I'll experiment a bit more, but seems not so trivial. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted February 18, 2014 Author Share Posted February 18, 2014 I tested with alien as prefab. Once i change material for one it changes it for all. Without prefab it also changed for all. Perhaps a bug ? i'll do moretesting tonight. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted February 18, 2014 Share Posted February 18, 2014 Strange because specifying material path for one or two seems to impact all other even when not in dead state ? Yes, this is instancing at work. All instances of the same model share the same Material. This is the downside to instancing where the good side is that it saves memory and loading is instant because it just uses the already loaded mesh/material/texture. When you load a model you see that there is a parameter that accepts values defined here: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/asset/ CreateNew will load new mesh and material (this will cause a delay) Unmanaged I think will use the same mesh but load a new material (this is what you want, but it might cause a noticeable delay as well) The other way around this is something I did in 3.0 (with shadmars help) that uses a mega texture idea where this texture has sub textures inside of it in a grid like fashion. You then control, per model instance, what sub-texture should be displayed on it by using the SetColor() function since that information gets to the shader and is instance specific and this was all controlled at the shader level. I'll have to look for this and see if it works without modification in 3.1 but it makes it the fastest possible way but has limitations on texture size and how much sub textures you'd need. What you are experiencing with this is NOT a bug though. It's how LE was designed. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 18, 2014 Author Share Posted February 18, 2014 well ,strange because even when entities was not prefab changing a material in one affected the others ? It was just a copy/paste of entity in the editor. Does copy/paste work as instance behind the scene ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted February 18, 2014 Share Posted February 18, 2014 Yes, instancing happens not only on prefabs but on everything by default. Copy/paste in editor does instancing. You have to load in code with the CreateNew or Unmanaged value to not get instancing. A nice feature would be to ask if you want instancing when you copy/paste in the editor. Just remember the less instancing the more memory it takes up. The only way to get a ton of models on the screen all at the same time with minimal impact is via instancing. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.