Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Distance to lines results in inlets at line crossings

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Newbie Newbie
    Join Date
    Jun 2014

    Distance to lines results in inlets at line crossings


    I have a problem with the result that I get when calculating distances to lines in a shader program, specifically distances to multiple lines.

    Click image for larger version. 

Name:	cross_artifact.jpg 
Views:	153 
Size:	12.3 KB 
ID:	1325

    As you can see from the screenshots there is no problem with single lines, but when combined in the calculation inlets are visible at the line crossing that I do not understand and would like to get rid of. If this is some sort of optical illusion, then I still would like to know how to avoid this.
    (background: I want to create a soft shadow effect from a polygon silhouette that gets passed to the fragment shader)

    Part of the fragment shader code that is used to calculate the combined distance:

    Code :
    void main(void) {
        outputColor = vec4(1f, 1f, 0f, 1f);
        bool bands = false;
        float len = 0.2;        
        float distHorizontalLine = getDistanceToLine(vec3(0f, 0f, 0f), vec3(len, 0f, 0f), currentPoint);    
        float distVerticalLine =   getDistanceToLine(vec3(0f, 0f, 0f), vec3(0f, len, 0f), currentPoint);   
        float dist = distHorizontalLine;                   // [A] distance to horizontal line
        dist = distVerticalLine;                           // [B] distance to vertical line
        // dist = min(distVerticalLine, distHorizontalLine);  // [C] distance to cross
        float radius = 0.25f;
        if (dist<radius) {
            float ratio = dist/radius;        
            vec4 distColor = vec4(0f, 0f, 1f, 1f);        
            outputColor = mix(distColor, outputColor, ratio);
            if (bands) {
                // debug: display bands
                float band = (ceil(fract(ratio)*10f))/10f;
                outputColor = vec4(band, band, 1-band, 1f);

    The complete project (java (lwjgl) + shaders sources):
    Attached Files Attached Files
    Last edited by nospoon2014; 06-01-2014 at 08:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts