Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 900 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Passing color to a shader #82461
07/21/06 11:47
07/21/06 11:47
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
I'd like to pass two colors to a shader. I should be able to change the colors at runtime (in c-script) and the colors should be different per entity.

I can't use material skills because that would influence all entities with that material. entSkill41..entSkill44 only have room for one color.

Is there any way this could be achieved?

Re: Passing color to a shader [Re: Excessus] #82462
07/21/06 12:26
07/21/06 12:26
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
you could use entskill41-44 to pass virtual texturecoordinates for looking up the colors in a special texture (filled up with fields of different colors)

did you understand the idea behind this? i never did something like this, it was just what came to my mind first, but it should be possible

Re: Passing color to a shader [Re: ello] #82463
07/21/06 12:44
07/21/06 12:44
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Thats a good idea, but I have some concerns:
Would adding another texture (even if it is small, 8x8 pixels should do) slow things down alot? This shader will be used by every actor in my world, and although they can all share the same 'colortable texture', I think it has to be sent to the GPU for every object, right? Or will it be cached?

Another idea I came up with is this:
Every entity that uses this material gets a copy of the material (created through mtl_create) so then I can use the mtlSkills. Are there any drawbacks to this? I don't think a material takes alot of memory so storing one per entity wouldn't be a big deal.

Which one shall I go with?

Re: Passing color to a shader [Re: Excessus] #82464
07/21/06 12:50
07/21/06 12:50
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
if that slows things down a lot, well, i wont think so.. the second one sounds good as well. i never looked at mtl_create. but if that works, why not use mtlSkills. would be easier i guess

Re: Passing color to a shader [Re: ello] #82465
07/21/06 14:54
07/21/06 14:54
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
the texture is cached. You need some more processes in the shader pipeline. You can pass more values though:

Use mtl.skill1/2/3/4....
In the fx use "float4 vecSkill1;" as declaration.
The first four Skills are now accessible through vecSkill1.xyzw

Then vecSkill5 ...

material skills are the same for every model but you can use an event to change the skills:

Code:
function mat_colorsend_values() {
mtl.skill1 = float(my.skill12); // or whatever skill you need
mtl.skill2 = float(my.skill13); // or whatever skill you need
...
}

material mat_colorsend {
event = mat_colorsend_values;
flags = enable_render; // call event before every rendering process
}




Follow me on twitter
Re: Passing color to a shader [Re: mk_1] #82466
07/21/06 15:28
07/21/06 15:28
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Thanks both, I've got it working
I used mk_1's aproach since it seems to be the most elegant way to do it.

Re: Passing color to a shader [Re: Excessus] #82467
07/21/06 18:43
07/21/06 18:43
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
Not very elegant but it works.


Follow me on twitter
Re: Passing color to a shader [Re: mk_1] #82468
07/21/06 19:33
07/21/06 19:33
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Ok, least ugly


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1