#version 310 es precision mediump float; layout(std430) buffer; struct vertex { vec2 pos; vec4 cubic; vec2 uv; vec4 color; vec4 clip; int zIndex; }; layout(binding = 0) buffer vertexBufferSSBO { vertex elements[]; } vertexBuffer ; layout(binding = 1) buffer indexBufferSSBO { uint elements[]; } indexBuffer ; layout(location = 0) uniform int indexCount; layout(location = 0) out vec4 fragColor; bool is_top_left(vec2 a, vec2 b) { return( (a.y == b.y && b.x < a.x) ||(b.y < a.y)); } float orient2d(vec2 a, vec2 b, vec2 c) { ////////////////////////////////////////////////////////////////////////////////////////// //TODO(martin): FIX this. This is a **horrible** quick hack to fix the precision issues // arising when a, b, and c are close. But it degrades when a, c, and c // are big. The proper solution is to change the expression to avoid // precision loss but I'm too busy/lazy to do it now. ////////////////////////////////////////////////////////////////////////////////////////// a *= 10.; b *= 10.; c *= 10.; return((b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x)); } void main() { vec4 pixelColor = vec4(0.0, 1.0, 0.0, 1.0); vec4 currentColor = vec4(0., 0., 0., 1.0); vec2 samplePoint = gl_FragCoord.xy; int currentZIndex = -1; int flipCount = 0; for(int i=0; i= 0 && (int(w1)+bias1) >= 0 && (int(w2)+bias2) >= 0) { //TODO check cubic vec4 cubic = (cubic0*w0 + cubic1*w1 + cubic2*w2)/(w0+w1+w2); float eps = 0.0001; if(cubic.w*(cubic.x*cubic.x*cubic.x - cubic.y*cubic.z) <= eps) { if(zIndex == currentZIndex) { flipCount++; } else { if((flipCount & 0x01) != 0) { pixelColor = currentColor; } currentColor = pixelColor*(1.-color.a) + color.a*color; currentZIndex = zIndex; flipCount = 1; } } } } if((flipCount & 0x01) != 0) { pixelColor = currentColor; } fragColor = pixelColor; }