Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, Nymphodora, Quad, TipmyPip, Imhotep), 852 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Ways to send variables/locations to entity shaders #473701
08/07/18 06:16
08/07/18 06:16
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hello friends!

Anyone have any tricks to send as many vector positions from the entity to be read by shaders? I'm already using vecSkill41-60 for individual vectors. Are there any other ways/tricks I can use to send more vectors for shaders? I dont want global variables (_var), because that will change every shader.

Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473704
08/07/18 08:25
08/07/18 08:25
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
materials point to their directX LPD3DXEFFECT struct. It has many methods to modify the static table of the effect.

Code:
LPD3DXEFFECT _fx = _mtl->d3deffect;
if (_fx == NULL)
   error("unable to retrieve the effect of a material");
float _f[4] = ...;
if(_fx->SetVector("customName", _f) != NULL) // see: SetFloat, SetVectorArray, SetMatrix, SetMatrixArray...
   error("unable to modify the static table of an effect");



https://docs.microsoft.com/en-us/windows/desktop/direct3d9/id3dxbaseeffect

Salud!

Re: Ways to send variables/locations to entity shaders [Re: txesmi] #473708
08/07/18 13:39
08/07/18 13:39
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hi Txesmi, how do I use that snippet of code?

Where do I define/retrieve LPD3DXEFFECT ?

How would an entity set that custom float for their own material, but also be unique to that material like the vecSkill41?

Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473710
08/07/18 14:48
08/07/18 14:48
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
you need to include windows.h, the definition is into d3d9.h

ENABLE_RENDER material flag lets you modify the render of each visible entity which has the material assigned.

(untested code)
Code:
#define skFloatArray     skill20

...

function evnMtl00 () {
	if (mtl->d3deffect == NULL) // no effect loaded?
		return 1; // do not render
	if (me == NULL) // not an actual entity?
		return 0; // render as it is
	LPD3DXEFFECT _fx = mtl->d3deffect;
	// fill a float array, or retrieve a pointer to an array from the entity skill or whatever
	float *_fArray = (float*)my->skFloatArray;
	_fx->SetVector("myFloats", _fArray);
	return 0;
}

MATERIAL *mtl00 = {
	event = evnMtl00;
	flags = ENABLE_RENDER;
}



This is only needed when each entity has its own values for the same variables.

Re: Ways to send variables/locations to entity shaders [Re: txesmi] #473713
08/07/18 15:56
08/07/18 15:56
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hey txesmi thanks for helping me, I think thats what im going for, but i get a script crash in the event, I think its this line?:

float *_fArray = (float*)my->skFloatArray;


Last edited by jumpman; 08/07/18 16:04. Reason: script crashes when line is added to .fx file, see post below
Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473714
08/07/18 16:03
08/07/18 16:03
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
If I go into my .FX file and I place this:

Code:
float4 myFloats;



The script will crash when the engine runs.

i can see this in the d3d9.h

Code:
STDMETHOD(SetVector)(THIS_ D3DXHANDLE hParameter, CONST D3DXVECTOR4* pVector) PURE;



in the .fx file ive done this as well:

Code:
const float4 myFloats;



and the script still crashes in the material event

Last edited by jumpman; 08/07/18 16:08.
Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473715
08/07/18 16:13
08/07/18 16:13
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
It has to point to an actual array of floats. The example simply casts an skill to a pointer, but the skill has to be filled first in the entity initialization.

Code:
float4 *myFloatsArray = sys_malloc(sizeof(float) * 4); // only once!
my->skFloatArray = (var)myFloatsArray;
... // whenever you need to change the values
myFloatsArray[0] = (float)my->red / 255.0;
myFloatsArray[1] = (float)my->green / 255.0;
myFloatsArray[2] = (float)my->blu / 255.0;
myFloatsArray[3] = (float)my->lightrange;


Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473716
08/07/18 16:22
08/07/18 16:22
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
if i leave the game running, the material event function crashes with "too many functions!" as well!

Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473717
08/07/18 16:27
08/07/18 16:27
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
It sound pretty strange. Have you added any loop to the event?

Re: Ways to send variables/locations to entity shaders [Re: txesmi] #473718
08/07/18 16:58
08/07/18 16:58
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
That was unrelated to your work, Im sorry, I had a wait(1); by mistake in the material event, which caused the functions to increase when i paused the game, forgive me.

Back on track, heres what Im doing at the top of my entity action:
Code:
Action tester_ent()

{
float4 *myFloatsArray = sys_malloc(sizeof(float) * 4); // only once!
my->skFloatArray = (var)myFloatsArray;

...


my.material = mtl_Hero;  //---------Assign the Hero shader


while(1)

// changing the variable
myFloatsArray[0] = (float)my.x+random(200)-random(200);
myFloatsArray[1] = (float)my.y+random(200)-random(200);
myFloatsArray[2] = (float)my.z+random(200)-random(200);
myFloatsArray[3] = (float)0;

wait(1);
}




Here is the material event:

Code:
hero_event()
{
...

if (mtl->d3deffect == NULL) // no effect loaded?
		return 1; // do not render
		
	if (me == NULL) // not an actual entity?
		return 0; // render as it is
		
	LPD3DXEFFECT _fx = mtl->d3deffect;
	
	float *_fArray = (float*)my->skFloatArray; // fill a float array, or retrieve a pointer to an array from the entity skill or whatever
	_fx->SetVector("myFloats", _fArray);
//	
	return 0;

}





Is that correct?

This all doesnt crash until i add myFloats to the .fx file

Page 1 of 2 1 2

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