Jump to content

Turn character shadows off in Lua


YouGroove
 Share

Recommended Posts

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 ?

Stop toying and make games

Link to comment
Share on other sites

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 ?

Stop toying and make games

Link to comment
Share on other sites

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().

Link to comment
Share on other sites

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.

Stop toying and make games

Link to comment
Share on other sites

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 ?

Stop toying and make games

Link to comment
Share on other sites

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.

Stop toying and make games

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

  • Upvote 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...