#version 460
#extension GL_GOOGLE_include_directive : enable
#include <light.h>
#include "shader-common-generic-lighting.h"
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; };
layout ( binding = BIND_OPTIONS ) uniform Uni_Options
{
ivec4 tryout;
vec4 tryoutf;
int opt_tri_normals;
};
#ifdef _VERTEX_SHADER_
layout ( location = LOC_IN_POS ) in vec4 in_vertex;
layout ( location = LOC_IN_NORMAL ) in vec3 in_normal;
layout ( location = LOC_IN_COLOR ) in vec4 in_color;
layout (location = 0) out VGF
{
vec4 vertex_e;
vec4 color;
vec3 normal_e;
} Out;
void
vs_main()
{
gl_Position = clip_from_object * in_vertex;
Out.vertex_e = eye_from_object * in_vertex;
Out.normal_e = normalize( mat3(eye_from_object) * in_normal );
Out.color = in_color;
}
#endif
#ifdef _GEOMETRY_SHADER_
layout ( triangles ) in;
layout ( triangle_strip, max_vertices = 3 ) out;
layout (location = 0) in VGF
{
vec4 vertex_e;
vec4 color;
vec3 normal_e;
} In[];
layout (location = 0) out VGF
{
vec4 vertex_e;
vec4 color;
vec3 normal_e;
} Out;
void
gs_main()
{
vec3 v01 = In[0].vertex_e.xyz - In[1].vertex_e.xyz;
vec3 v02 = In[0].vertex_e.xyz - In[2].vertex_e.xyz;
vec3 tn = normalize( cross(v01,v02) );
for ( int i=0; i<3; i++ )
{
gl_Position = gl_in[i].gl_Position;
Out.vertex_e = In[i].vertex_e;
Out.color = In[ tryout.x == 0 ? i : 0 ].color;
Out.normal_e = opt_tri_normals != 0 ? tn : In[i].normal_e;
EmitVertex();
}
EndPrimitive();
}
#endif
#ifdef _FRAGMENT_SHADER_
layout ( location = 0 ) in VGF
{
vec4 vertex_e;
vec4 color;
vec3 normal_e;
} In;
layout ( location = 0 ) out vec4 out_frag_color;
void
fs_main()
{
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