Матрица вращения.
Добавлено: 10 дек 2014, 19:14
Доброго времени суток! Решил для общего развития попробовать написать шейдер вращения модели. Шейдер написал, все рисует но модель не крутит.
Может кто подскажет где ошибка?
Может кто подскажет где ошибка?
Синтаксис:
Используется csharp
Shader "Custom/Vert_test" {
Properties{
_ang ("angle", Range (0,360)) = 0
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float _ang;
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
};
v2f vert (appdata_full v)
{
v2f o;
float ang = _ang * 3.16 / 180.0; //Перевод в радианы
float4x4 rot = (1,0,0,0,
0,cos(ang),sin(ang),0,
0,-sin(ang),cos(ang),0,
0,0,0,1);
float4 posit = mul (UNITY_MATRIX_MVP*rot, v.vertex);
o.pos = posit;
o.color.xyz = v.normal * 0.5 + 0.5;
o.color.w = 1.0;
return o;
}
fixed4 frag (v2f i) : COLOR0 { return i.color; }
ENDCG
}
}
FallBack "Diffuse"
}
Properties{
_ang ("angle", Range (0,360)) = 0
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float _ang;
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
};
v2f vert (appdata_full v)
{
v2f o;
float ang = _ang * 3.16 / 180.0; //Перевод в радианы
float4x4 rot = (1,0,0,0,
0,cos(ang),sin(ang),0,
0,-sin(ang),cos(ang),0,
0,0,0,1);
float4 posit = mul (UNITY_MATRIX_MVP*rot, v.vertex);
o.pos = posit;
o.color.xyz = v.normal * 0.5 + 0.5;
o.color.w = 1.0;
return o;
}
fixed4 frag (v2f i) : COLOR0 { return i.color; }
ENDCG
}
}
FallBack "Diffuse"
}