Hello everyone!
Has anyone encountered a similar problem?
I wrote a simple shader that draws a filled figure on the screen.
On AppGameKit Classic it works perfectly, but on AppGameKit Studio the figure is deformed. I can't figure out the cause of this problem.
An array of points describing the contour is passed to the shader. Pixels that fall inside the contour should be drawn in color, and pixels that do not fall are rejected.
Why doesn't this work on Studio? I tried to enable Vulkan render, OpenGL, tried to split the array into two one-dimensional (float), tried to use gl_FragCoords instead of UV. Nothing helps. It seems that Studio passes incorrect data about the sprite to the shader...
Shader Code:
#define MAX_POINTS 1000 // maximum number of points at shader compilation time
varying mediump vec2 uvVarying; // we get the fragment coordinates from the vertex shader
uniform mediump float aleng; // we get the actual size of the array of contour point coordinates from the main program
uniform mediump vec2 arr[MAX_POINTS]; // we get an array of coordinates of contour points from the main program
uniform mediump vec4 color; // we get the fill color parameters from the main program
int fpoints=int(aleng); // actual size of the contour points array (convert to integer)
void main() // main shader loop
{
// coordinates of the current point p (using texture coordinates of the UV fragment)
vec2 p=uvVarying;
// resetting the status of the point falling inside the contour
bool p_status=false;
// index of the previous contour point
int j=fpoints;
// we iterate over all the points of the contour within the actual size of the array
for (int i=0; i<=fpoints; i++) {
// difference of x coordinates of two adjacent points of a contour
float dx=arr[j].x-arr[i].x;
// difference between the y-coordinates of two adjacent points of a contour
float dy=arr[j].y-arr[i].y;
// avoid division by zero
if (dy == 0.0) {dy += 0.00000000001;}
// contour segment gradient
float grad=dx/dy;
// we check the point p to see if it falls within the interval
if (((arr[i].y > p.y) != (arr[j].y > p.y)) && (p.x < (p.y - arr[i].y) * grad + arr[i].x)) {
p_status = !p_status;
}
// the current point of the contour becomes the previous one
j=i;
}
// if the current sprite fragment falls within the outline
if (p_status){
// paint the fragment with the given color
gl_FragColor=color;
// if the fragment does not fit
} else {
// we do not draw
discard;
}
}