#version 460
#extension GL_GOOGLE_include_directive : enable
#include <light.h>
#include <transform.h>
#include "shader-common-generic-lighting.h"
layout ( binding = BIND_MATERIAL ) uniform Uni_Material
{
vec4 color_front, color_back;
};
layout ( binding = BIND_BULGE_INFO ) uniform Buldge_Info
{
float bulge_loc;
float bulge_dist_thresh;
float wire_radius;
bool opt_texture;
};
layout ( binding = BIND_HELIX_COORDS ) buffer Helix_Coord
{
vec4 helix_coord[];
};
#ifdef _VERTEX_SHADER_
layout ( location = LOC_IN_INT1 ) in int in_helix_index;
layout (location = LOC_IN_NORMAL) in vec3 in_normal;
layout (location = LOC_IN_TCOOR) in vec2 in_tex_coord;
layout (location = 0) out Data
{
vec4 vertex_c;
vec3 normal_e;
vec4 vertex_e;
vec2 tex_coord;
int hidx;
} Out;
void
vs_main_helix()
{
Out.hidx = in_helix_index;
float radius = wire_radius * ( Out.hidx == int(bulge_loc) ? 1.2f : 1.0f );
vec4 vertex_o;
vertex_o.xyz = helix_coord[Out.hidx].xyz + radius * in_normal;
vertex_o.w = 1;
Out.vertex_c = ut.clip_from_object * vertex_o;
Out.vertex_e = ut.eye_from_object * vertex_o;
Out.normal_e = normalize(mat3(ut.eye_from_object) * in_normal);
Out.tex_coord = in_tex_coord;
}
#endif
#ifdef _GEOMETRY_SHADER_
layout ( triangles ) in;
layout (location = 0) in DataVG
{
vec4 vertex_c;
vec3 normal_e;
vec4 vertex_e;
vec2 tex_coord;
int hidx;
} In[3];
layout (location = 0) out DataGF
{
vec4 color;
vec3 normal_e;
vec4 vertex_e;
vec2 tex_coord;
int hidx;
} Out;
layout ( triangle_strip, max_vertices = 3 ) out;
void
gs_main_helix()
{
const bool type_a = In[0].hidx < In[2].hidx;
vec4 color_adjust = type_a ? vec4(0.5,0.5,0.5,1) : vec4(1);
for ( int i=0; i<3; i++ )
{
Out.color = color_adjust;
gl_Position = In[i].vertex_c;
Out.tex_coord = In[i].tex_coord;
Out.normal_e = In[i].normal_e;
Out.vertex_e = In[i].vertex_e;
EmitVertex();
}
EndPrimitive();
}
#endif
#ifdef _FRAGMENT_SHADER_
layout ( binding = BIND_TEXUNIT ) uniform sampler2D tex_unit_0;
layout (location = 0) in Data
{
vec4 color;
vec3 normal_e;
vec4 vertex_e;
vec2 tex_coord;
int hidx;
} In;
layout (location = 0) out vec4 out_frag_color;
void
fs_main_phong()
{
vec4 texel = opt_texture ? texture(tex_unit_0,In.tex_coord) : vec4(1,1,1,1);
vec4 material_color = gl_FrontFacing ? color_front : color_back;
vec4 shaded_color = material_color * In.color;
vec4 lit_color = generic_lighting( In.vertex_e, shaded_color, In.normal_e);
out_frag_color = opt_texture ? texel * lit_color : lit_color;
}
#endif