Hi there, Sorry I’m new to shaders.
I’m having trouble to converting a mat2 Type function(GLSL). I have normally seen vec2 functions, but I can’t seem to find out how to call the equivalent float2x2(HLSL).
GLSL
float s = sin(a);
float c = cos(a);
return mat2(c, -s, s, c);
}```
HLSL
``` float2x2 Rot(float a) {
float s = sin(a);
float c = cos(a);
return float2x2(c, -s, s, c);
}```
OR
```float2 Rot(float a) {
float s = sin(a);
float c = cos(a);
return float2x2(c, -s, s, c);
}```
Function call:
``` float map(float3 p){
p.xy*=Rot(_Time*0.06);
}```
Getting error:: "type mismatch at line xx" ie "p.xy*=Rot(_Time*0.06);"
How do I rewrite the original mat2 function? This seem to run fine on GLSL. I think "rotate" is expecting float2 but that doesn't work.
When you multiply a vector and a matrix together in GLSL you can do myVector *= myMatrix to get the equivalent of myMatrix * myVector.
But in HLSL you don’t use the * operator for matrices this way. You instead need to use the mul() function to multiply matrices by vectors or vice versa. That also means there’s no *= operator where the right hand variable is a matrix, unless the left hand is also a matrix.
So you’ll want:
p.xy = mul(rotate(_Time.y * 0.06), p.xy);
Also note Unity’s _Time is a float4 where _Time.y is the unmodified game time.
Thanks, I meant to put in “p.xy*=Rot(_Time0.06);" I don’t think there’s anything wrong with “Rot”. I think I calling it incorrectly ""p.xy=Rot(_Time*0.06)”