Jump to content

Instance state/DNA in shader?


Guppy
 Share

Recommended Posts

Say I have a "orc" model from this model I wish to create 100 instances.

In order to give the illusion of diversity these would be slightly differently scaled on x,y,z axis ( I believe this is possible with LE, correct me if I am wrong ) - but In order to further create diversion it would be nice if I could alter their hues slightly since the shader applies the texture it would need to know something about this model - namely it's state or DNA - is it possible to make this information available to the shader on a per instance basis?

 

I suspect it is possible given that each instance already tracks it own animation state, but I'd like to know for sure.

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

It's a bit more complex than that as the idea involves a texture atlas, but that function would allow me to set up to 8 floats of information.

 

Not crazy about it being floats but I suppose that can be worked with, thanks.

 

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entitysetcolor-r162

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

It's a bit strange tho that http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entityinstance-r173 is undocumented

 

What exactly is the relationship between entity and instance - I mean I assume that :instance() returns a entity (because the command reference does not have a instance class) that is an instance of the entity ( as opposed to a full fledged copy ) - but what variables are instanced what is private/copied? - IE would calling :setColor(...) affect just the instance or all entities?

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

I would like some documentation on this as well. My guess (I have no access to my PC right now to try it out) is:

 

Basically everything is shared between an entity and its instances, with the following exceptions

 

1) the transforms (position, rotation, scle)

2) the entity color (ie entitiy:SetColor())

 

If you look in one of the vertex shaders, you'll see that the enity matrix is indexed with gl_InstanceID, so that's why the transforms are per instance. In addition, Leadwerks encodes the entity color in the fourth column of the entity matrix, so that is per instance as well.

 

Everything else (like material diffuse color) is passed in as a uniform, so it will be shared between instances.

 

But again, this is just my guess from the code, an official documentation on this would be nice...

  • Upvote 2
Link to comment
Share on other sites

There are 2 ways to do this:

 

1) A custom shader (I created one with the help of shamdar for 3.0) that allows basically a table of textures inside 1 giant texture and it uses the SetColor() function to decide on which one to pick (of course this removes the normal functionality of SetColor() as the data passed to it are bastardized for the selection of what row/col in the texture to use). I think this is the most efficient way to do it. I can't find my shader for this here on the site. I'm sure I have it at home with my 3.0 build (if I still have it installed). I'll see if I can find it when I get home.

 

2) There is a parameter to Model:Load() that allows you to have separate materials for the returned model but the geometry is instanced still. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/asset/ I think Unmanaged gives you separate material but shared geometry and CreateNew gives you a non-instanced model completely.

 

I just asked a question around this for loading prefabs as it has this extra parameter in Load() as well. I haven't tested this yet but Josh did reply saying how you can get the prefab to both load scripts AND be Unmanaged. http://www.leadwerks.com/werkspace/topic/8593-how-to-have-prefabs-be-unique-and-load-scripts/

Link to comment
Share on other sites

[...]

1) A custom shader (I created one with the help of shamdar for 3.0) that allows basically a table of textures inside 1 texture and it uses the SetColor() function to decide on which one to pick. I think this is the most efficient way to do it.

[...]

 

This was pretty much what I had planed on - I had hoped to be able to pass a larger genome than 4 floats tho

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

1) A custom shader (I created one with the help of shamdar for 3.0) that allows basically a table of textures inside 1 giant texture and it uses the SetColor() function to decide on which one to pick (of course this removes the normal functionality of SetColor() as the data passed to it are bastardized for the selection of what row/col in the texture to use). I think this is the most efficient way to do it.

 

 

Well is this overrrides SetColor .. beware if some people use by inadvertance or to test and they complain SetColor not woking anymore.

 

Overriding engine basic function to other things they are not supposed to do and to do your custom stuff is really bad design choice.

 

 

Better use parameter script that would be passed to the shader.

Does LE3 allow to pass simple variables by script to shaders ?

I seen that on other engines, and it allows big possibilities , like changing values used by the shader.

 

Having a new Lua function allowing to pass values to a shader.

setValueShader("shaderName", entity, TypeOfParameter, "Value")

Stop toying and make games

Link to comment
Share on other sites

I'm preety sure I chattet these functions to you, but you were all set on SetColor, so there was no stopping you .. smile.png

 

But there is a slight issue if you don't want to change it for all your shaded entities that uses that shader... the uniform is set for ALL entities using the shader. SetColor is sent per entity.

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

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