Skip to content

Instantly share code, notes, and snippets.

@hiroakioishi
Created June 2, 2020 05:29
Show Gist options
  • Select an option

  • Save hiroakioishi/bb32e2451d4d841ebb94fa7e397c8815 to your computer and use it in GitHub Desktop.

Select an option

Save hiroakioishi/bb32e2451d4d841ebb94fa7e397c8815 to your computer and use it in GitHub Desktop.
球体内部のランダムな点
// Generate random number
float rand(float2 co)
{
return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453);
}
// 半径1の球体の内部のランダムな点
float3 randomInsideUnitSphere(float co)
{
float phi = 2 * PI * rand(co);
float th = acos(1.0 - 2.0 * rand(co + float2(0.0, 1.0)));
float r = pow(rand(co + float2(0.0, 0.2)), 0.333333333);
float x = r * sin(th) * cos(phi);
float y = r * sin(th) * sin(phi);
float z = r * cos(th);
return float3(x, y, z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment