[Glamor] diagonal line fragment shaders

Conn Clark conn.o.clark at gmail.com
Mon Mar 31 12:29:09 PDT 2014


I have been looking at doing diagonal line acceleration with fragment
shaders. This is what I have come up with so far. We need one for
steep lines and one for shallow lines. It can be similar to how we use
our vertical and horizontal lines.

We calculate the slope  and intercept then run it across the the
rectangle defined by the two end points.

The AMD shaderAnalyzer says it will take about 5 clocks per pixel on a
lower end r600.

Thoughts and Comments?


//Steep shader

uniform sampler2D textures[2];
uniform  float xintercept;
uniform float slope;
uniform vec2 texcoord;



void main()
{
    gl_FragColor = mix(
        texture2D(textures[0], texcoord),
        texture2D(textures[1], texcoord),
         float(round(texcoord.y*slope+xintercept) == texcoord.x)
    );
}



//shallow shader

uniform sampler2D textures[2];
uniform  float yintercept;
uniform float slope;
uniform vec2 texcoord;



void main()
{
    gl_FragColor = mix(
        texture2D(textures[0], texcoord),
        texture2D(textures[1], texcoord),
         float(round(texcoord.x*slope+yintercept) == texcoord.y)
    );
}



-- 

Conn O. Clark

Observation: In formal computer science advances are made
by standing on the shoulders of giants. Linux has proved
that if there are enough of you, you can advance just as
far by stepping on each others toes.


More information about the Glamor mailing list