Skip to content

Instantly share code, notes, and snippets.

@xeechou
Last active September 13, 2023 20:30
Show Gist options
  • Save xeechou/1d2eea46c4dd822be24441bd14ae5927 to your computer and use it in GitHub Desktop.
Save xeechou/1d2eea46c4dd822be24441bd14ae5927 to your computer and use it in GitHub Desktop.
gen 3d direction
//x is theta in range(0, pi), y is phi in range(0, 2pi), solid angle pi/8
layout(local_size_x = 8, local_size_y = 16, local_size_z = 1) in;
//using local group for theta and phi
#define M_PI 3.141592653f
vec3 get_direction()
{
vec2 pos = vec2(gl_LocalInvocationID.xy) / vec2(gl_WorkGroupSize.xy);
float theta = mix(0.0f, M_PI, pos.x); //theta is 0 at north pole, pi at south pole
float phi = mix(0.0f, 2.0f * M_PI, pos.y); //phi is 0 at +x direction, PI at -x direction.
return vec3(sin(theta) * cos(phi), //this is right hand y-up coordinate system.
cos(theta),
sin(theta) * sin(phi));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment