pan/roll uv-map/texture via shader?

Posted By: BoH_Havoc

pan/roll uv-map/texture via shader? - 12/18/07 14:08

Hi,
i was wondering if its possible to pan or tilt an uv-map/texture via shader. I already had a look through the internet but couldn't find a solution. I'd say it should be possible, but i can't think of a way to do it right now.

Any ideas?
Posted By: lostclimate

Re: pan/roll uv-map/texture via shader? - 12/18/07 18:48

well what acutally you'd have to do is do the inverse transformation to the actual map on the texture as far as how to do it, there is some trig involved, but it shouldnt be too hard.
Posted By: ello

Re: pan/roll uv-map/texture via shader? - 12/18/07 20:41

Code:

float4x4 rMat = {
1,a,0,0,
b,1,0,0,
0,0,0,0,
0,0,0,0
};
Out.Tex = mul(inTex,rMat);


where a rotates quite obvious and b does something, too.. i still dont really know how matrixes work, but this should help you

btw, the two "1" entries are tiling factors
Posted By: BoH_Havoc

Re: pan/roll uv-map/texture via shader? - 12/19/07 02:20

Duh! I didn't even think about using a matrix. Thanks for the hint, that should do the trick
Posted By: alienheretic

Re: pan/roll uv-map/texture via shader? - 12/19/07 04:13

if anyone succedes with this please fill me in with an example
Posted By: ello

Re: pan/roll uv-map/texture via shader? - 12/19/07 07:21

yes, if you get it done please give feedback, since i tried for the past weeks and didnt a reliable working version
Posted By: ventilator

Re: pan/roll uv-map/texture via shader? - 12/19/07 07:35

i think just tinkering with the values won't really get you anywhere. you have to create a correct rotation matrix with sin and cos like that:

if you also want to scale or translate then multiply this rotation matrix with a scale or translation matrix before you use it to transform the uvs.
Posted By: ello

Re: pan/roll uv-map/texture via shader? - 12/19/07 07:54

thank you very much!

still one proble remains:
Code:

float a = radians(45);
float3x3 matRotate =
{
cos(a) , -sin(a) , 0,
sin(a) , cos(a) , 0,
0 , 0 , 1
};
Out.tex = mul(In.tex,matRotate);



this works perfect, but if i youse entSkill41 instead of 45 and pass it from the entities action via my.skill41 = floatv(45); it does not work correct.. any idea whats wrong?
Posted By: ventilator

Re: pan/roll uv-map/texture via shader? - 12/19/07 10:57

i don't know whats wrong with entskill but i guess it would make sense to calculate sin(a) and cos(a) outside of the shader since the angle stays the same for every vertex anyway.
Posted By: ello

Re: pan/roll uv-map/texture via shader? - 12/19/07 11:25

this does not work, too. to bad i cant read out values as text in the shader ... there seems to be some conversion when passing the skill. because the texture gets rotated when passing sin(0) or (90) and so on, and you have to scale the values in the shader by 0.001 , and there are other strange things happening... hmm

ok, got it nearly working:
Code:

float s=entSkill41;
float c=entSkill42;
float3x3 matRotate =
{
c , -s , 0,
s , c , 0,
0 , 0 , 1
};
In.tex += float2(-0.5,-0.5);
Out.tex = mul(In.tex,0.001*matRotate);


where

my.skill41 = sinv(my.pan);
my.skill42 = cosv(my.pan);
but still when the pan is 0 the rotaion matrix produces a slightly rotation, what could that be??


Posted By: BoH_Havoc

Re: pan/roll uv-map/texture via shader? - 12/19/07 14:44

hmm i'm not entirely sure but shouldn't this

Code:

my.skill41 = sinv(my.pan);
my.skill42 = cosv(my.pan);



be changed to somehing like this

Code:

my.skill41 = floatv(sinv(my.pan));
my.skill42 = floatv(cosv(my.pan));



?
© 2024 lite-C Forums