Gamestudio Links
Zorro Links
Newest Posts
no trade when there is a negative trained WFOcycle
by maxwellreturn. 08/24/19 22:33
Skip Stepcycle
by maxwellreturn. 08/24/19 22:27
Script filename
by MatPed. 08/24/19 20:49
Any Old Timers Still Around?
by pyramide. 08/24/19 18:23
Oanda FIFO issue?
by AndrewAMD. 08/24/19 12:10
IG plugin initial release
by Dalla. 08/24/19 06:06
Tutorial for Vector Graphics
by Dooley. 08/23/19 22:32
Issue with dataParse function
by byakuren81. 08/23/19 21:57
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
1 registered members (AndrewAMD), 627 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Ysbail, trader4321, GorgonzolaBYTE, Southqvist, tawin
18272 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to force more personal textures into an FX file #473726
08/08/18 05:49
08/08/18 05:49
Joined: Apr 2002
Posts: 1,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,225
ny
Hi friends!

Im trying to put more textures into a shader, similar to entSkin1-4. Ideally I would like entSkin1-10, or entSkin1-100!

I see in the manual, that if you name a texture with _bmap at the end of the name, within the fx file, you can set up an arbitrary amount of textures to be used, however these textures are global.

How would I be able to a unique set of textures for each entity, but using the same shader?

I see this method in the d3d9.h

Code:
STDMETHOD(SetTexture)(THIS_ D3DXHANDLE hParameter, LPVOID /*LPDIRECT3DBASETEXTURE9*/ pTexture) PURE;



Would I be able to use that in the materials event?

Code:
_fx->SetTexture("ClothFloatA1bmap",bmpFoamTex);



This doesnt work, it gives me a script crash within the material event.


A8 Pro 8.47
Re: How to force more personal textures into an FX file [Re: jumpman] #473731
08/08/18 08:37
08/08/18 08:37
Joined: Sep 2003
Posts: 6,844
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,844
Kiel (Germany)
Code:
typedef struct BMAP {
	C_LINK	link;
	long 	width,height; // original size of the bitmap
	long	bytespp;	// original bytes per pixel (1..4)
	void	*ptr;		// internal use
	byte	*pixels;	// ptr to palettized, 565, 4444, 888 or 8888 coded original image
	long	flags;      // see BMPF_... above
	void	*d3dtex;	// 	LPDIRECT3DTEXTURE9 (usually a different format than the original image)
	float	u1,v1,u2,v2; // texture pixel bounds
	long	u,v;		// cutout start size
	long	refcount;	// for implicitely created bmaps
	long	finalwidth,finalheight,finalbytespp;
	long	pitch,finalpitch;
	long	miplevels;
	long	finalformat;
	void	*finalbits;	// bitmap content when locked, otherwise NULL
} BMAP;


->
void *d3dtex; // LPDIRECT3DTEXTURE9 (usually a different format than the original image)

That's what you are looking for. DirectX functions do not accept acknex BMAPs. That pointer might be empty though (for example when the texture has not been visible/ drawn at least once yet), need to check for != NULL.


"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: How to force more personal textures into an FX file [Re: Superku] #473732
08/08/18 09:07
08/08/18 09:07
Joined: Jun 2007
Posts: 1,237
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,237
Hiporope and its pain
As addition, if I am not wrong, the maximum texture sampler count is sixteen.

Re: How to force more personal textures into an FX file [Re: txesmi] #473734
08/08/18 16:48
08/08/18 16:48
Joined: Apr 2002
Posts: 1,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,225
ny
Hi friends, thank you for helping me. Here is what I have so far and it works, but can you look over this and help me make it better, less error prone?

This is the new line in the material's event
Code:
if(ent_getskin(me,5)!=NULL)  // If the entity's 5th skin is not NULL
	{
	BMAP* doot = ent_getskin(me,5);     ///get the bmap pointer of the entity's 5th skin
	_fx->SetTexture("clother",doot->d3dtex);  // force the texture sampler to be the bmap of the entitys 5th skin!
	}



This works correctly with models that do actually have a 5th texture! Very exciting!

But for models that dont have a 5th texture saved in their model file, their shader puts up seemingly random textures, which I assume the shader is putting up leftover images in memory.

Also, is it dangerous to declare a bitmap within a material's event function?


A8 Pro 8.47
Re: How to force more personal textures into an FX file [Re: jumpman] #473736
08/08/18 20:36
08/08/18 20:36
Joined: Jun 2007
Posts: 1,237
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,237
Hiporope and its pain
Aside from the need of checking the validity of the d3dtex member of the bitmap, there is nothing could go wrong, I think.

Quote:
is it dangerous to declare a bitmap within a material's event function?

You are declaring a pointer to a bitmap, if you are asking about it, it is not dangerous at all. You sould not allocate static memory (malloc), create engine objects, etc. The event should stay as simple as possible.

Re: How to force more personal textures into an FX file [Re: txesmi] #473737
08/09/18 06:59
08/09/18 06:59
Joined: Sep 2003
Posts: 6,844
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,844
Kiel (Germany)
Well I've never tried setting a texture myself but you probably would want to use a different material then that doesn't access the 5th skin when the model has none. Or just call SetTexture for a small dummy black skin if you're using it for a mask/ data/ whatever. Keep in mind that you should not do unnecessary SetTexture calls to not waste performance though.


"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: How to force more personal textures into an FX file [Re: Superku] #473745
08/09/18 15:35
08/09/18 15:35
Joined: Apr 2002
Posts: 1,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,225
ny
Hey friends! I spoke a little too soon.

The set texture instruction I put above does work mostly.....until the models that have legitimate 5th and 6th textures randomly flash OTHER entity skins from other models that do not have 5th and 6th textures!

When a model with this shader doesnt have a 5th or 6th texture, and I return color; within the pixel shader, the model can sometimes grab other textures in memory(textures from entitys that use the same shader but with textures 5 and 6 present in their model), even with enable_render on. This seems like normal behavior.

However, models with the same shader but with the extra 5th or 6th texture present in their models, these can show their texture correctly when I do a return color; in the pixel shader....however very rarely even these models can flash other textures, ive had to record these instances on bandicam to make sure I wasnt seeing things!

I tried SetTexture calls outside of the material event, but it doesnt work, it needs to be constantly running in the material event.

Its obviously pointing to the d3d functions as the culprit. But why would a shader thats run independantly on each model still grab textures from other models in memory, even with pointing to the d3d texture?

Ultimately, I wanted more custom textures for each entity besides the 4 entskins, so that these extra textures would be use as masks and stuff for things like cloth movement and stuff.


Last edited by jumpman; 08/09/18 16:05.

A8 Pro 8.47
Re: How to force more personal textures into an FX file [Re: jumpman] #473748
08/09/18 18:36
08/09/18 18:36
Joined: Jun 2007
Posts: 1,237
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,237
Hiporope and its pain
yes, it seems that DX fills textures with valid memory to avoid access violations when the texture is missing. For the rest, I am sorry, but I have no experience enough with SetTexture. It sounds pretty strange though.

Have you tried to check the return value of the method? It may throw some light over the issue. Anyway, the code is so tiny that there is no room for improvements. All the pointers are set by the engine and the event calls a single function only: the very same function that the engine uses to set the textures of the entities, but it is failing... assured headache.

You can use SetTexture out of an event, but no in this case. Each effect loaded in the graphic card has a static memory table associated and is modified for each entity rendered with it. The role of material events is, precisely, to be able to modify an already opened rendering process for each entity.

As a workaround, the use of atlas maps might help. At the end, the textures are normaly related by groups.

Re: How to force more personal textures into an FX file [Re: txesmi] #473749
08/09/18 19:30
08/09/18 19:30
Joined: Apr 2002
Posts: 1,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,225
ny
Hi Txesmi

How do I see the return value of the SetTexture? Will it return a var or string, or a d3d var or string?

How do you use atlas maps? A while back, you were able to help me pack 2 images into one image by multiplying the InTex.x by 0.5f, which was really handy. Is that what you mean?


A8 Pro 8.47
Re: How to force more personal textures into an FX file [Re: jumpman] #473751
08/09/18 20:11
08/09/18 20:11
Joined: Jun 2007
Posts: 1,237
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,237
Hiporope and its pain
Hi,
it returns a DWORD variable, an unsigned integer, 0 when it went right. I would check if it returns any other value first. Something like the following:
Code:
var texErrors = 0;
... 
void event () {
...
if(_fx->SetTexture(...))
   texErrors += 1;
...
}

main () {
   while(1) {
      DEBUG_VAR(texErrors, 10);
      texErrors = 0;
      ...



If there are errors, check for their meanings. Unfortunately the msdn documentation about the method return is brief. As first try I use to look for the header specified into the msdn documentation on internet but I got VS installed for this issues too.

Quote:

Is that what you mean?

Yes laugh

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