Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn), 584 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
matTexture not getting calculated #405677
08/04/12 20:55
08/04/12 20:55
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline OP
Expert
Error014  Offline OP
Expert

Joined: Jul 2002
Posts: 3,208
Germany
Hello!

There's a strange bug concerning matTexture - it seems that it's not getting calculated. DoTexture (nor, of course, the direct multiplication of the vector with matTexture) does nothing.

Here is a rar that has a simple test model and code ready for testing: link.

The important code is:

Code:
MATERIAL* uvcheck = {
	effect =
	"
		const float4x4 matWorldViewProj;
		float4x4 matTexture;
		
		texture entSkin1;

		sampler sBaseTex = sampler_state { 
			Texture = <entSkin1>;
			AddressU = Wrap;
			Addressv = Wrap;
		};

		void vs_uvshift( 
		   in float4 InPos: POSITION, 
		   in float2 InTex: TEXCOORD0, 
		   out float4 OutPos: POSITION, 
		   out float2 OutTex: TEXCOORD0) 
		{ 
		   OutPos = mul(InPos, matWorldViewProj); 
		   OutTex = mul(float4(InTex.x,InTex.y,1,1),matTexture).xy;
		} 
	
		float4 ps_uvshift(in float2 InTex: TEXCOORD0): COLOR
		{
			return tex2D(sBaseTex,InTex);
		}	
	
		technique uvtest {
			pass p0 {
				VertexShader = compile vs_2_0 vs_uvshift();
				PixelShader = compile ps_2_0 ps_uvshift();					
			}	
		}
	";
}


function shiftuv() {
        my.material = uvcheck;
	while(1) {
		my.u += time_step;
		wait(1);
	}
}



It's worth pointing out that if you don't assign a new material to an entity, u and v work as expected (the right entity in the demo).

This has been tested in both 8.30.5, and, superku reports the same issue in the new 8.40 version in the original thread.


Additionally, it'd be great if the manual could be a bit more detailed about u,v and matTexture. Simply writing that matTexture is (what we assume, at least)

Code:
1 0 u 0
0 1 0 v
0 0 1 0
0 0 0 1



and then saying that DoTexture is a simple way to do texture shifting would be enough and much appreciated.

Thanks in advance!



Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: matTexture not getting calculated [Re: Error014] #405713
08/06/12 08:21
08/06/12 08:21
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
If matTexture would "not be calculated", you would not see a texture, just a single pixel.

A texture matrix looks like this:

1 0 0 0
0 1 0 0
u v 1 0
0 0 0 1

I've added this to the manual.

Re: matTexture not getting calculated [Re: jcl] #405715
08/06/12 09:52
08/06/12 09:52
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline OP
Expert
Error014  Offline OP
Expert

Joined: Jul 2002
Posts: 3,208
Germany
Thanks for adding that to the manual! laugh


Have you tried the demo, though? While u is being changed in the entity's action, it doesn't give the expected texture shift. Which is the reason why I assumed that "it's not getting calculated", meaning it looks like matTexture is just the identity matrix.


Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: matTexture not getting calculated [Re: Error014] #405718
08/06/12 11:22
08/06/12 11:22
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
Don't you see an u texture shift without your shader?

Re: matTexture not getting calculated [Re: jcl] #405720
08/06/12 11:45
08/06/12 11:45
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline OP
Expert
Error014  Offline OP
Expert

Joined: Jul 2002
Posts: 3,208
Germany
Yeah, there's texture shifting for that one - the right entity in the demo.


And while I normally would think that this suggests an error in the shader, I can't find any. laugh
Checking matTexture[0][2] or matTexture[2][0] directly also results in zeros - for that, I've simply returned

Code:
return float4(matTexture[0][2], matTexture[2][0], 0, 1);



in the Pixel shader. By changing u, we'd expect the thing to become more red or more green (I used both to make sure I don't accidentally use the wrong convention :)), but it's actually staying black.


Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: matTexture not getting calculated [Re: Error014] #405724
08/06/12 12:30
08/06/12 12:30
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
The engine uses matTexture for uv shifting, so there's obviously nothing wrong with the matrix. Check the transformations in your shader. The _31 and _32 matrix coordinates determine the uv offsets. They must have a range between 0 and 1.

Re: matTexture not getting calculated [Re: jcl] #405728
08/06/12 13:19
08/06/12 13:19
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline OP
Expert
Error014  Offline OP
Expert

Joined: Jul 2002
Posts: 3,208
Germany
The transformation may very well be wrong, but so is it in DoTexture then.

This material - fundamentally the same - uses DoTexture, and thus hopefully eliminates any doubt that this is just a mistake on my end. laugh

Code:
#include <texture>

const float4x4 matWorldViewProj;

texture entSkin1;

sampler sBaseTex = sampler_state { 
	Texture = <entSkin1>;
	AddressU = Wrap;
	Addressv = Wrap;
};

void vs_uvshift( 
   in float4 InPos: POSITION, 
   in float2 InTex: TEXCOORD0, 
   out float4 OutPos: POSITION, 
   out float2 OutTex: TEXCOORD0) 
{ 
   OutPos = mul(InPos, matWorldViewProj); 
   OutTex = DoTexture(InTex);
} 

float4 ps_uvshift(in float2 InTex: TEXCOORD0): COLOR
{
	return tex2D(sBaseTex,InTex);
        //Feel free to use that line for a more direct test:
	//return float4(matTexture[0][2], matTexture[2][0], 0, 1);
}	

technique uvtest {
	pass p0 {
		VertexShader = compile vs_2_0 vs_uvshift();
		PixelShader = compile ps_2_0 ps_uvshift();					
	}	
}




Here's a picture:



And, once more, I refer to the demo that would probably make testing easier.


EDIT: In fairness, it might be that I'm missing something - do I need to do anything but change u,v outside the shader?


In the meantime, I'm using skill41 as a workaround. I still think it's wrong behaviour, though.

Last edited by Error014; 08/06/12 13:33. Reason: added pic, demo link; also added question

Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: matTexture not getting calculated [Re: Error014] #405730
08/06/12 13:54
08/06/12 13:54
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
I see now your problem: you just copied your shader code from DoTexture. But DoTexture does not do a texture translation. It is a scaling function.

A texture has 2 coordinates, u and v. That's why matTexture has the translation coordinates in the 3rd row. So you need to get a 3x3 matrix from it and multiply it with a float3 extended texture coordinate vector (x,y,1). The result are the translated coordinates. Hope this helps. There is no shader library function for texture translation, but if you have problems, let me know and I'll write one.

Re: matTexture not getting calculated [Re: jcl] #405736
08/06/12 15:12
08/06/12 15:12
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline OP
Expert
Error014  Offline OP
Expert

Joined: Jul 2002
Posts: 3,208
Germany
That would be great, as I have to admit I'm a bit lost here; specifically on why the current version doesn't work.


As far as I understand, this line:

Code:
OutTex = mul(float4(InTex.x,InTex.y,1,1),matTexture).xy;



(which is just what DoTexture does)

would, together with this matrix:

Code:
1 0 0 0
0 1 0 0
u v 1 0
0 0 0 1



result in

(x+u, y+v, 1, 1)

so, using .xy of that should give us texture translation.

Scaling, however, doesn't seem to be something that could be done with that matrix structure, at least not with the vector DoTexture multiplies it with.

It also doesn't quite explain why the components [0][2]/[2][0] of matTexture are all zero ([3][1]/[1][3] are also zero, by the way)


My apologies - I probably come across as thick here. Your help is much appreciated!

Last edited by Error014; 08/06/12 15:16.

Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: matTexture not getting calculated [Re: Error014] #405787
08/07/12 12:04
08/07/12 12:04
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
I've changed the DoTexture function so that it now also supports translation. There were also several other small bugs in the recent version that were fixed. You can download the new version, 8.40.1, with the new DoTexture function from the announcements forum.

Page 1 of 2 1 2

Moderated by  jcl, Nems, Spirit, Tobias 

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