6ivec4 int_to_ivec4(in 
int x) {
 
   10        return ivec4(255,255,255,255);
 
   13    int R = glup_mod(w, 256);
 
   15    int G = glup_mod(w, 256);
 
   17    int B = glup_mod(w, 256);
 
   19    int A = glup_mod(w, 256);
 
   20    return ivec4(R,G,B,A);
 
   23ivec4 int_to_ivec4(in 
int x) {
 
   35ivec4 ivec4_add(in ivec4 V1, in ivec4 V2) {
 
   39    int G = V1.g + V2.g + carry;
 
   42    int B = V1.b + V2.b + carry;
 
   45    int A = V1.a + V2.a + carry;
 
   46    return ivec4(R,G,B,A);
 
   51vec4 ivec4_to_vec4(in ivec4 V) {
 
   62highp 
vec4 int_to_vec4(in 
int x) {
 
   63    return ivec4_to_vec4(int_to_ivec4(x));
 
   66float min3(in 
float x, in 
float y, in 
float z) {
 
   67    return min(min(x,y),z);
 
   70float min4(in 
float x, in 
float y, in 
float z, in 
float w) {
 
   71    return min(min(x,y),min(z,w));
 
   74float edge_factor1(in 
float bary) {
 
   75    float d = fwidth(bary);
 
   76    float a = smoothstep(0.0, d*GLUP.mesh_width, bary);
 
   80float edge_factor3(in vec3 bary) {
 
   81    vec3 d = fwidth(bary);
 
   83        vec3(0.0, 0.0, 0.0), d*GLUP.mesh_width, bary
 
   85    return min3(a.x, a.y ,a.z);
 
   88float edge_factor4(in vec4 bary) {
 
   89    vec4 d = fwidth(bary);
 
   91        vec4(0.0, 0.0, 0.0, 0.0), d*GLUP.mesh_width, bary
 
   93    return min4(a.x, a.y, a.z, a.w);
 
   96vec4 glup_picking(in highp 
int primitive_id) {
 
   98    if(GLUP.picking_mode == GLUP_PICK_PRIMITIVE) {
 
   99        ivec4 A4 = int_to_ivec4(primitive_id);
 
  101        ivec4 B4 = int_to_ivec4(GLUP.base_picking_id);
 
  102        result = ivec4_to_vec4(ivec4_add(A4,B4));
 
  104        result = int_to_vec4(GLUP.picking_id);
 
  109vec4 glup_texturing(in vec4 color, in vec4 tex_coord) {
 
  112    if(GLUP.texture_type == GLUP_TEXTURE_1D) {
 
  113        tex_color = glup_texture(
 
  114            texture1Dsampler, tex_coord.xy
 
  116    } 
else if(GLUP.texture_type == GLUP_TEXTURE_2D) {
 
  117        tex_color = glup_texture(
 
  118            texture2Dsampler, tex_coord.xy
 
  121#ifdef GLUP_NO_TEXTURE_3D 
  123        tex_color = 
vec4(1.0, 0.0, 0.0, 1.0);
 
  126    else if(GLUP.texture_type == GLUP_TEXTURE_3D) {
 
  128            texture3Dsampler, tex_coord.xyz
 
  132    if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) {
 
  133        tex_color = GLUP.texture_matrix * tex_color;
 
  134        tex_color = glup_texture(texture1Dsampler, tex_color.xy);
 
  136    if(GLUP.texture_mode == GLUP_TEXTURE_REPLACE) {
 
  138    } 
else if(GLUP.texture_mode==GLUP_TEXTURE_MODULATE) {
 
  146vec4 glup_lighting(in vec4 color, in vec3 normal) {
 
  148    float diff = 
dot(normal,GLUP.light_vector);
 
  150        result.rgb = diff*result.rgb + 
vec3(0.2, 0.2, 0.2);
 
  151        if(GLUP.specular > 0.0) {
 
  152            float spec = 
dot(normal,GLUP.light_half_vector);
 
  154                spec = pow(spec, 30.0);
 
  155                result.rgb += GLUP.specular*spec*
vec3(1.0, 1.0, 1.0);
 
  159        result.rgb = 
vec3(0.2, 0.2, 0.2);
 
  165void glup_alpha_discard() {
 
  166    if(glupIsEnabled(GLUP_ALPHA_DISCARD)) {
 
  167        if(glup_FragColor.a < GLUP.alpha_threshold) {
 
  173void glup_primitive_filter(highp 
int primitive_id) {
 
  174#ifdef GLUP_PRIMITIVE_FILTER 
  177            texturePrimitiveFiltersampler,
 
  178            GLUP.base_picking_id + primitive_id
 
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors.   vecng
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.