Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 533 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473719
08/07/18 17:20
08/07/18 17:20
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
The effect compiler errors are always described in a prompt window. It does never crash. I don't know what could be happening crazy

Here goes a complete and tested example of the very same
Code:
#include <acknex.h>
#include <windows.h>
#include <d3d9.h>

#define skFloatArray     skill20

function evnCamMtl () {
	if (mtl->d3deffect == NULL)
		return 1;
	if (me == NULL)
		return 0;
	if (my->skFloatArray == 0)
		return 0;
	LPD3DXEFFECT _fx = mtl->d3deffect;
	_fx->SetVector("myFloats", (float*)my->skFloatArray);
	return 0;
}

MATERIAL *mtlCam = {
	event = evnCamMtl;
	flags = ENABLE_RENDER;
	effect = "
		const float4x4 matWorldViewProj;
		
		float4 myFloats;
		
		void VS (
			in float4 inPos	: POSITION,
			out float4 outPos	: POSITION) {
				outPos = mul ( inPos, matWorldViewProj );
			}
		
		float4 PS () : COLOR0 {
			return myFloats;
		}
		
		technique tech {
			pass p0 {
				ZWriteEnable = True;
				AlphaBlendEnable = False;
				
				VertexShader = compile vs_3_0 VS();
				PixelShader  = compile ps_3_0 PS();
			}
		}	
	";
}

action actSphere () {
	float *_fV = sys_malloc(sizeof(float) * 4);
	memset(_fV, 0, sizeof(float) * 4);
	my->skFloatArray = (var)_fV;
	my->material = mtlCam;
	while (!key_esc) {
		_fV[0] = random(1);
		_fV[1] = random(1);
		_fV[2] = random(1);
		_fV[3] = random(1);
		wait(1);
	}
	
	sys_free(_fV);
	ent_remove(me);
}


void main () {
	wait(1);
	level_load ("");
	camera->x = -200;
	int _count = 0;
	for (; _count<5; _count+=1)
		ENTITY *_ent = ent_create(SPHERE_MDL, vector(0, _count*50, 0), actSphere);
	
	while (!key_esc) {
		camera->pan = ang(camera->pan - mickey.x * 0.2);
		camera->tilt = clamp(camera->tilt - mickey.y * 0.2, -90, 90);
		wait(1);
	}
	
	wait(1);
	sys_exit(NULL);
}


Re: Ways to send variables/locations to entity shaders [Re: txesmi] #473720
08/07/18 20:08
08/07/18 20:08
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Personally I'd just use the entity skills and not bother with the memory management. In the event:

float floatArray[4];
floatArray[0] = my.skill10;
floatArray[1] = my.skill11;
floatArray[2] = my.skill12;
floatArray[3] = my.skill13;
_fx->SetVector("myFloats", floatArray);


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Ways to send variables/locations to entity shaders [Re: Superku] #473721
08/07/18 20:11
08/07/18 20:11
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
whats the advantage of that Superku?

Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473722
08/07/18 20:39
08/07/18 20:39
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
No additional memory management. Currently, you need to sys_free the memory before you remove an entity (that includes on level changes, for example via on_ent_remove). Keep it simple, makes it easier to debug and less error prone.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Ways to send variables/locations to entity shaders [Re: Superku] #473725
08/08/18 05:30
08/08/18 05:30
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Txesmi, Superku, Im using both of your methods and it works so far! Thank you so much.

Just curious, didnt you allocate memory with:

float floatArray[4];

Will that be released automatically once the entity is removed?

Re: Ways to send variables/locations to entity shaders [Re: jumpman] #473730
08/08/18 08:34
08/08/18 08:34
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
No, not directly, that's just grabbing memory from the stack as with any other variable. For example writing "int i;" before a for(i ...) loop. That memory will be "lost" on function exit (but restored after when there is a "wait" instruction).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Page 2 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