#version 460
#extension GL_GOOGLE_include_directive : enable
#include <light.h>
#include "shader-common-generic-lighting.h"
#include "links-shdr-common.h"
layout ( binding = BIND_UNI_COMMON ) uniform Common_Uniform
{
Shdr_Uni_Common com;
};
bool opt_tryout1 = com.tryout.x != 0;
bool opt_tryout2 = com.tryout.y != 0;
bool opt_tryout3 = com.tryout.z != 0;
float opt_tryoutf = com.tryoutf.x;
bool opt_hw04_stel = com.opt_hw04.x != 0;
bool opt_hw04_dot = com.opt_hw04.y != 0;
bool opt_hw04_tex = com.opt_hw04.z != 0;
float opt_hw04_height_stel = com.tryoutf.y;
layout ( binding = BIND_TRANSFORM ) uniform Uni_Transform
{
mat4 eye_from_object; mat4 clip_from_eye; mat4 clip_from_object; mat4 object_from_eye; mat4 eye_from_clip; mat4 object_from_clip; };
#ifdef HW4_TRI
#ifdef _VERTEX_SHADER_
layout ( location = LOC_IN_POS ) in vec4 in_vertex;
layout ( location = LOC_IN_COLOR ) in vec4 in_color;
layout ( location = LOC_IN_MAT4 ) in mat4 in_mat_object_from_local;
layout (location = 0) out VG
{
vec4 vertex_e;
vec4 color;
} Out;
void
vs_main()
{
gl_Position = clip_from_object * in_mat_object_from_local * in_vertex;
Out.vertex_e = eye_from_object * in_mat_object_from_local * in_vertex;
Out.color = in_color;
}
#endif
#ifdef _GEOMETRY_SHADER_
layout ( triangles ) in;
layout ( triangle_strip, max_vertices = 3 ) out;
layout (location = 0) in VG
{
vec4 vertex_e;
vec4 color;
} In[3];
layout (location = 0) out GF
{
vec4 vertex_e;
vec4 color;
vec3 normal_e;
} Out;
void
gs_main()
{
vec3 v12 = In[2].vertex_e.xyz - In[1].vertex_e.xyz;
vec3 v10 = In[0].vertex_e.xyz - In[1].vertex_e.xyz;
vec3 tn = normalize( cross(v12,v10) );
float edge_len = length(v12);
const float pi = radians(180); vec3 v12o = cross(tn,v12) * float( 1.0 / ( 2 * tan( 2 * pi / 10 ) ) );
vec4 ctr_pentagon_e = vec4( In[1].vertex_e.xyz + 0.5f * v12 + v12o, 1 );
for ( int i=0; i<3; i++ )
{
vec4 pt_i_e = In[ i ].vertex_e;
vec4 pt_n_e = In[ (i+1)%3 ].vertex_e;
bool is_pentagon_edge = distance(pt_i_e,pt_n_e) < edge_len * 1.1f;
gl_Position = gl_in[i].gl_Position;
Out.vertex_e = In[i].vertex_e;
Out.color = In[i].color;
Out.normal_e = tn;
EmitVertex();
}
EndPrimitive(); }
#endif
#ifdef _FRAGMENT_SHADER_
layout ( location = 0 ) in GF
{
vec4 vertex_e;
vec4 color;
vec3 normal_e;
} In;
layout ( binding = BIND_TEXUNIT ) uniform sampler2D tex_unit_0;
layout ( location = 0 ) out vec4 out_frag_color;
void
fs_main()
{
vec2 tc = vec2(0.5,0.5);
vec4 texel = texture(tex_unit_0,tc);
vec4 our_color = gl_FrontFacing ? In.color : vec4(1,0,0,1);
vec4 lighted_color = generic_lighting( In.vertex_e, our_color, In.normal_e );
out_frag_color = lighted_color;
}
#endif
#endif
#ifdef HW4_CLEAN
#ifdef _VERTEX_SHADER_
layout ( location = LOC_IN_POS ) in vec4 in_vertex;
layout ( location = LOC_IN_COLOR ) in vec4 in_color;
layout ( location = LOC_IN_MAT4 ) in mat4 in_mat_object_from_local;
layout (location = 0) out VG
{
vec4 vertex_e;
vec4 color;
} Out;
void
vs_main_clean()
{
gl_Position = clip_from_object * in_mat_object_from_local * in_vertex;
Out.vertex_e = eye_from_object * in_mat_object_from_local * in_vertex;
Out.color = in_color;
}
#endif
#ifdef _GEOMETRY_SHADER_
layout ( triangles ) in;
layout ( triangle_strip, max_vertices = 3 ) out;
layout (location = 0) in VG
{
vec4 vertex_e;
vec4 color;
} In[3];
layout (location = 0) out GF
{
vec4 vertex_e;
vec4 color;
vec3 normal_e;
} Out;
void
gs_main_clean()
{
vec3 v12 = In[2].vertex_e.xyz - In[1].vertex_e.xyz;
vec3 v10 = In[0].vertex_e.xyz - In[1].vertex_e.xyz;
vec3 tn = normalize( cross(v12,v10) );
float edge_len = length(v12);
const float pi = radians(180); vec3 v12o = cross(tn,v12) * float( 1.0 / ( 2 * tan( 2 * pi / 10 ) ) );
vec4 ctr_pentagon_e = vec4( In[1].vertex_e.xyz + 0.5f * v12 + v12o, 1 );
for ( int i=0; i<3; i++ )
{
vec4 pt_i_e = In[ i ].vertex_e;
vec4 pt_n_e = In[ (i+1)%3 ].vertex_e;
bool is_pentagon_edge = distance(pt_i_e,pt_n_e) < edge_len * 1.1f;
gl_Position = gl_in[i].gl_Position;
Out.vertex_e = In[i].vertex_e;
Out.color = In[i].color;
Out.normal_e = tn;
EmitVertex();
}
EndPrimitive();
}
#endif
#ifdef _FRAGMENT_SHADER_
layout ( location = 0 ) in GF
{
vec4 vertex_e;
vec4 color;
vec3 normal_e;
} In;
layout ( binding = BIND_TEXUNIT ) uniform sampler2D tex_unit_0;
layout ( location = 0 ) out vec4 out_frag_color;
void
fs_main_clean()
{
vec2 tc = vec2(0.5,0.5);
vec4 texel = texture(tex_unit_0,tc);
vec4 our_color = gl_FrontFacing ? In.color : vec4(1,0,0,1);
vec4 lighted_color = generic_lighting( In.vertex_e, our_color, In.normal_e );
out_frag_color = lighted_color;
}
#endif
#endif