#version 460
#extension GL_GOOGLE_include_directive : enable
layout ( binding = BIND_MISC ) uniform Uni_Misc
{
ivec4 opt_tryout;
ivec4 opt_assign;
float opt_tryoutf;
};
bool opt_tryout1 = bool(opt_tryout.x);
bool opt_tryout2 = bool(opt_tryout.y);
bool opt_tryout3 = bool(opt_tryout.z);
int opt_tryouti = opt_tryout.w;
bool opt_texture = bool(opt_assign.x);
const int ncolors = 10;
layout ( binding = BIND_HW05 ) uniform I_can_forget_this_name_no_problem
{
vec4 front[ncolors], back[ncolors];
mat4 local_from_object;
int s_sides, s_levels, n_sides, n_levels;
float n_sides_inv, n_levels_inv;
} uc;
layout ( binding = BIND_LIGHT_SIMPLE ) uniform Uni_Light
{
vec4 position;
vec4 color;
} uni_light;
layout ( binding = BIND_TRANSFORM ) uniform Uni_Transform
{
mat4 eye_from_object, clip_from_eye, clip_from_object;
mat4 object_from_eye, eye_from_clip;
} ut;
layout ( binding = BIND_HYPERB_COORDS ) buffer sc { vec4 hyperb_coords[]; };
layout ( binding = BIND_HYPERB_NORMS ) buffer sn { vec4 hyperb_norms[]; };
#ifdef _VERTEX_SHADER_
layout (location = 0) out Data_VG
{
vec4 padding;
};
void
vs_points()
{
}
#endif
#ifdef _GEOMETRY_SHADER_
layout ( points ) in;
layout ( triangle_strip, max_vertices = 4 ) out;
layout (location = 0) in Data_VG
{
vec4 padding;
} In[];
layout (location = 0) out Data_GF
{
vec4 vertex_e;
vec3 normal_e;
int color_idx;
vec2 tcoor;
} Out;
void
gs_points()
{
int level0 = gl_PrimitiveIDIn % uc.n_levels;
int side0 = gl_PrimitiveIDIn / uc.n_levels;
for ( int dl = 0; dl<2; dl++ )
for ( int ds = 0; ds < 2; ds ++ )
{
int level = level0 + dl;
int side = side0 + ds;
int idx = level + side * uc.s_levels;
vec4 p = hyperb_coords[ idx ];
vec4 n = hyperb_norms[ idx ];
gl_Position = ut.clip_from_object * p;
Out.vertex_e = ut.eye_from_object * p;
Out.normal_e = normalize( mat3(ut.eye_from_object) * n.xyz );
Out.color_idx = side0 != 0 ? 1 :
ds == 0 ? ( level0 % 2 == 0 ? 2 : 5 ) : ( level0 % 2 == 0 ? 4 : 3 );
if ( opt_tryout1 )
{
Out.tcoor = vec2( 10 * side * uc.n_sides_inv,
1 - level * uc.n_levels_inv );
}
else
{
vec4 ploc = uc.local_from_object * p;
float theta = atan( ploc.y, ploc.x );
Out.tcoor = vec2( 1.5 * theta, 1 - level * uc.n_levels_inv );
}
EmitVertex();
}
EndPrimitive();
}
#endif
#ifdef _FRAGMENT_SHADER_
layout ( binding = BIND_TEXUNIT ) uniform sampler2D tex_unit_0;
layout (location = 0) in Data_GF
{
vec4 vertex_e;
vec3 normal_e;
flat int color_idx;
vec2 tcoor;
};
layout (location = 0) out vec4 frag_color;
void
fs_points()
{
vec4 texel = opt_texture ? texture(tex_unit_0,tcoor) : vec4(1,1,1,1);
vec3 vec_vl = uni_light.position.xyz - vertex_e.xyz;
float dist_sq = dot( vec_vl, vec_vl );
bool lit_side = dot( normal_e, vec_vl )>0 == dot( normal_e, -vertex_e.xyz )>0;
float ambient_attn = 0.01;
float attenuation = lit_side ? abs( dot( normal_e, vec_vl ) / dist_sq ) : 0;
vec4 mat_color = gl_FrontFacing ? uc.front[color_idx] : uc.back[color_idx];
frag_color =
texel * mat_color * uni_light.color * ( attenuation + ambient_attn );
}
#endif