|
|
matTexture not getting calculated
#405677
08/04/12 20:55
08/04/12 20:55
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
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:
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)
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: jcl]
#405715
08/06/12 09:52
08/06/12 09:52
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
OP
Expert
Joined: Jul 2002
Posts: 3,208
Germany
|
Thanks for adding that to the manual!  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: jcl]
#405720
08/06/12 11:45
08/06/12 11:45
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
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.  Checking matTexture[0][2] or matTexture[2][0] directly also results in zeros - for that, I've simply returned
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: jcl]
#405728
08/06/12 13:19
08/06/12 13:19
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
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. 
#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: jcl]
#405736
08/06/12 15:12
08/06/12 15:12
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
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:
OutTex = mul(float4(InTex.x,InTex.y,1,1),matTexture).xy;
(which is just what DoTexture does) would, together with this matrix:
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!
|
|
|
|