[drape] line shaders.

This commit is contained in:
Dmitry Kunin 2014-02-04 12:48:03 +03:00 committed by Alex Zolotarev
parent eb544a859e
commit 295b7d2a53
3 changed files with 103 additions and 5 deletions

View file

@ -0,0 +1,66 @@
uniform lowp vec4 color;
varying highp vec4 v_vertType;
varying highp vec4 v_distanceInfo;
highp float cap(highp float type, highp float dx, highp float dy, highp float width)
{
highp float hw = width/2.0;
if (type == 0.0)
return -(dx*dx + dy*dy) + hw*hw;
else
return 1.0;
}
highp float join(int type, highp float dx, highp float dy, highp float width)
{
return 1.0;
}
void main(void)
{
highp float vertType = v_vertType.x;
if (vertType == 0.0)
{
gl_FragColor = color;
return;
}
else if (vertType > 0.0)
{
highp float joinType = v_vertType.z;
highp float dx = v_distanceInfo.z - v_distanceInfo.x;
highp float dy = v_distanceInfo.w - v_distanceInfo.y;
highp float width = v_vertType.w;
if (join(int(joinType), dx, dy, width) > 0.0)
{
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
return;
}
else
{
discard;
}
}
else if (vertType < 0.0)
{
highp float capType = v_vertType.y;
highp float dx = v_distanceInfo.z - v_distanceInfo.x;
highp float dy = v_distanceInfo.w - v_distanceInfo.y;
highp float width = v_vertType.w;
if ( cap(capType, dx, dy, width) > 0.0 )
{
gl_FragColor = color;
return;
}
else
{
discard;
}
}
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

View file

@ -1,13 +1,45 @@
attribute highp vec4 position;
attribute highp vec4 direction;
attribute highp vec4 a_vertType;
varying highp vec4 v_vertType;
varying highp vec4 v_distanceInfo;
uniform highp mat4 modelView;
uniform highp mat4 projection;
void main(void)
{
float width = direction.z;
vec4 n = vec4(-direction.y, direction.x, 0, 0);
vec4 pn = normalize(n * modelView) * width;
gl_Position = (pn + position * modelView) * projection;
highp float half_w = direction.z;
highp float vertexType = a_vertType.x;
highp vec4 pos;
highp vec4 pivot = position * modelView;
if (vertexType < 0.0)
{
highp vec4 n = vec4(-direction.y, direction.x, 0, 0);
highp vec4 d = vec4( direction.x, direction.y, 0, 0);
highp vec4 pn = normalize(n * modelView) * half_w;
highp float quadWidth = a_vertType.y <= 0.0 ? 2.0 * abs(half_w) : abs(half_w);
highp vec4 pd = normalize(d * modelView) * quadWidth;
pos = (pn - pd + pivot);
}
else
{
highp vec4 n = vec4(-direction.y, direction.x, 0, 0);
highp vec4 pn = normalize(n * modelView) * half_w;
pos = (pn + pivot);
}
v_distanceInfo = vec4(pivot.x, pivot.y, pos.x, pos.y);
v_vertType = a_vertType;
v_vertType.w = 2.0 * abs(half_w);
gl_Position = pos * projection;
}

View file

@ -1,3 +1,3 @@
SOLID_AREA_PROGRAM simple_vertex_shader.vsh solid_color_fragment_shader.fsh
TEXTURING_PROGRAM texturing_vertex_shader.vsh texturing_fragment_shader.fsh
SOLID_LINE_PROGRAM line_vertex_shader.vsh solid_color_fragment_shader.fsh
SOLID_LINE_PROGRAM line_vertex_shader.vsh line_fragment_shader.fsh