Changeset 2190


Ignore:
Timestamp:
Jan 1, 2013, 6:43:30 PM (7 years ago)
Author:
sam
Message:

tutorial: add fancy dots to line segment ends.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tutorial/04_texture.lolfx

    r2136 r2190  
    3333    float height = 600.0;
    3434    float line_width = 1.8;
     35    float dot_size = 2.0;
    3536    vec4 delta = vec4(1.0 / 128, 0.0,
    3637                      2.0 / 128, 0.0);
     
    4546    c[3] = texture2D(u_Texture, tc + delta.zw).x;
    4647
    47     /* Quick hack: artificially compress display in Y */
    48     c *= 0.3;
    49 
    5048    vec2 p0 = vec2((tc.x - delta.x) * width, c[0] * height);
    51     vec2 p1 = vec2((tc.x) * width,          c[1] * height);
     49    vec2 p1 = vec2((tc.x          ) * width, c[1] * height);
    5250    vec2 p2 = vec2((tc.x + delta.x) * width, c[2] * height);
    5351    vec2 p3 = vec2((tc.x + delta.z) * width, c[3] * height);
    5452    vec2 a = vec2(p.x * width, p.y * height);
    5553
    56     float d0 = segdist(p0, p1, a);
    57     float d1 = segdist(p1, p2, a);
    58     float d2 = segdist(p2, p3, a);
     54    /* Compute distance to segments */
     55    float d =        segdist(p0, p1, a);
     56          d = min(d, segdist(p1, p2, a));
     57          d = min(d, segdist(p2, p3, a));
    5958
    60     float d = clamp(line_width - min(min(d0, d1), d2), 0.0, 1.0);
     59    /* Compute distance to dots */
     60    d = min(d, length(a - p0) - dot_size);
     61    d = min(d, length(a - p1) - dot_size);
     62    d = min(d, length(a - p2) - dot_size);
     63    d = min(d, length(a - p3) - dot_size);
     64
     65    /* Add line width */
     66    float lum = clamp(line_width - d, 0.0, 1.0);
     67
     68    /* Compensate for sRGB */
     69    lum = pow(1.0 - lum, 1.0 / 2.4);
    6170
    6271    /* Choose some funny colours */
    63     gl_FragColor = vec4(p.y, d, mix(p.x, 0.3, d), 1.0);
     72    gl_FragColor = vec4(mix(p.x, 1.0, lum), lum, lum, 1.0);
    6473}
    6574
Note: See TracChangeset for help on using the changeset viewer.