2 registered members (Ayumi, 1 invisible),
584
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Serious User
|
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.
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/id3dxbaseeffectSalud!
|
|
|
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
Serious User
|
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)
#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
OP
Serious User
|
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
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
If I go into my .FX file and I place this: The script will crash when the engine runs. i can see this in the d3d9.h
STDMETHOD(SetVector)(THIS_ D3DXHANDLE hParameter, CONST D3DXVECTOR4* pVector) PURE;
in the .fx file ive done this as well: 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: txesmi]
#473718
08/07/18 16:58
08/07/18 16:58
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
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:
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:
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
|
|
|
|