Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created October 26, 2018 10:35
Show Gist options
  • Select an option

  • Save unitycoder/5305b83de5cc7e4bbace1ef29ce6516b to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/5305b83de5cc7e4bbace1ef29ce6516b to your computer and use it in GitHub Desktop.
Vertex Rotations in Shader
// https://forum.unity.com/threads/how-to-compute-vertex-rotation.470676/
inline float3x3 xRotation3dRadians(float rad) {
float s = sin(rad);
float c = cos(rad);
return float3x3(
1, 0, 0,
0, c, s,
0, -s, c);
}
inline float3x3 yRotation3dRadians(float rad) {
float s = sin(rad);
float c = cos(rad);
return float3x3(
c, 0, -s,
0, 1, 0,
s, 0, c);
}
inline float3x3 zRotation3dRadians(float rad) {
float s = sin(rad);
float c = cos(rad);
return float3x3(
c, s, 0,
-s, c, 0,
0, 0, 1);
}
// usage
// degree is the variable with the degrees you want to rotate your vertex
float3 rotatedVertex = mul(yRotation3dRadians(radians(degree)), v.vertex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment