I combed through the shaders and removed each one by one until I found the one that was the issue, my lighting shader.
I believe it is a casting issue, but I am not super sure. Any help would be appreciated.
Code: Select all
light_shader = love.graphics.newShader([[
#define NUM_LIGHTS 128
#define PI 3.14159265359
struct Light {
vec2 pos;
float range;
};
struct Line {
vec2 posA;
vec2 posB;
float range;
};
struct Player {
vec2 pos;
float width;
};
extern Light lights[NUM_LIGHTS];
extern int num_lights;
extern Line lines[NUM_LIGHTS];
extern int num_lines;
extern float time;
extern Player player;
extern float cutOff;
float rand(vec2 co){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}
float noise(vec2 p){
vec2 ip = floor(p);
vec2 u = fract(p);
u = u*u*(3.0-2.0*u);
float res = mix(
mix(rand(ip),rand(ip+vec2(1.0,0.0)),u.x),
mix(rand(ip+vec2(0.0,1.0)),rand(ip+vec2(1.0,1.0)),u.x),u.y);
return res*res;
}
float distPointToLine(vec2 p, vec2 l1, vec2 l2){
p.x +=noise(p+vec2(time/2.0,time/2.0))/2.0;
p.y +=noise(p+vec2(time/2.0,time/2.0))/2.0;
vec2 tempDist = vec2(l2.x-l1.x,l2.y-l1.y);
float len = pow(tempDist.x*tempDist.x+tempDist.y*tempDist.y,0.5);
tempDist.x/=len;
tempDist.y/=len;
float posOnLine = tempDist.x*(p.x-l1.x) + tempDist.y*(p.y-l1.y);
if (posOnLine < 0.0) {
tempDist.x = p.x-l1.x;
tempDist.y = p.y-l1.y;
return pow(tempDist.x*tempDist.x+tempDist.y*tempDist.y,0.5);
} else if (posOnLine > len) {
tempDist.x = p.x-l2.x;
tempDist.y = p.y-l2.y;
return pow(tempDist.x*tempDist.x+tempDist.y*tempDist.y,0.5);
} else {
return abs(tempDist.y*(p.x-l1.x) - tempDist.x*(p.y-l1.y));
}
}
float pointOnLine(vec2 p, vec2 l1, vec2 l2){
p.x +=noise(p+vec2(time/2.0,time/2.0))/2.0;
p.y +=noise(p+vec2(time/2.0,time/2.0))/2.0;
vec2 tempDist = vec2(l2.x-l1.x,l2.y-l1.y);
float len = pow(tempDist.x*tempDist.x+tempDist.y*tempDist.y,0.5);
tempDist.x/=len;
tempDist.y/=len;
float posOnLine = tempDist.x*(p.x-l1.x) + tempDist.y*(p.y-l1.y);
return posOnLine;
}
bool isAbove(vec2 a, vec2 b, vec2 c){ //line point for a and b
return ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) > 0.0;
}
vec4 effect(vec4 color, Image texture, vec2 t_c, vec2 s_c) {
int colType = 7;
int colIndex = 0;
int colList[NUM_LIGHTS*2];
for (int i = 0;i<num_lights;i++){
int colTemp = 7;
Light light = lights[i];
float dist2 = pow(pow(s_c.x-light.pos.x+noise(s_c+vec2(time/2.0,time/2.0)),2.0) + pow((s_c.y-light.pos.y+noise(s_c+vec2(time/2.0,time/2.0)))*1.6,2.0),0.5);
float ang = atan(s_c.y-light.pos.y,s_c.x-light.pos.x);
float pang = atan(player.pos.y-light.pos.y,player.pos.x+player.width/2.0-player.width*cutOff-light.pos.x);
float pang2 = atan(player.pos.y-light.pos.y,player.pos.x-player.width/2.0-light.pos.x);
float pdist = pow(pow(player.pos.x-light.pos.x,2.0) + pow(player.pos.y-light.pos.y,2.0)*2.6,0.5);
if (pang > pang2){
float temp = pang2;
pang2 = pang;
pang = temp;
}
bool changedValue = false;
if (dist2 < light.range) {
colTemp = 1;
changedValue = true;
} else if (dist2 < light.range*1.666666) {
colTemp = 2;
changedValue = true;
} else if (dist2 < light.range*2.5) {
colTemp = 3;
changedValue = true;
} else if (dist2 < light.range*3.333333) {
colTemp = 4;
changedValue = true;
} else if (dist2 < light.range*4.333333) {
colTemp = 5;
changedValue = true;
} else if (dist2 < light.range*5.333333) {
colTemp = 6;
changedValue = true;
}
if (changedValue){
if ((dist2 <= pdist) || (ang <= pang || ang >= pang2)){
} else {
colTemp++;
colTemp++;
}
}
colList[colIndex] = colTemp;
colIndex++;
}
for (int i = 0;i<num_lines;i++){
int colTemp = 7;
Line line = lines[i];
float dist2 = distPointToLine(s_c,line.posA,line.posB);
float point = pointOnLine(s_c,line.posA,line.posB);
float pPoint = pointOnLine(vec2(player.pos.x-player.width/2.0,player.pos.y),line.posA,line.posB);
float pPoint2 = pointOnLine(vec2(player.pos.x+player.width/2.0-player.width*cutOff,player.pos.y),line.posA,line.posB);
float pdist = distPointToLine(player.pos,line.posA,line.posB);
bool pside = isAbove(line.posA,line.posB,player.pos);
bool side = isAbove(line.posA,line.posB,s_c);
if (pPoint2 < pPoint){
float temp = pPoint2;
pPoint2 = pPoint;
pPoint = temp;
}
bool changedValue = false;
if (dist2 < line.range) {
colTemp = 1;
changedValue = true;
} else if (dist2 < line.range*1.666666) {
colTemp = 2;
changedValue = true;
} else if (dist2 < line.range*2.5) {
colTemp = 3;
changedValue = true;
} else if (dist2 < line.range*3.333333) {
colTemp = 4;
changedValue = true;
} else if (dist2 < line.range*4.333333) {
colTemp = 5;
changedValue = true;
} else if (dist2 < line.range*5.333333) {
colTemp = 6;
changedValue = true;
}
if (changedValue){
if ((dist2 <= pdist || pside != side) || (point <= pPoint || point >= pPoint2)){
} else {
colTemp++;
colTemp++;
}
}
colList[colIndex] = colTemp;
colIndex++;
}
for (int i = 0;i<colIndex;i++){
colType = int (min(float (colType),float (colList[i])));
}
if (colType == 1) {
return vec4(0.98039215686, 0.47058823529, 0.17647058823,1.0);
} else if (colType == 2) {
return vec4(0.87450980392, 0.30196078431, 0.2431372549,1.0);
} else if (colType == 3) {
return vec4(0.73725490196, 0.25882352941, 0.25490196078,1.0);
} else if (colType == 4) {
return vec4(0.4862745098, 0.29411764705, 0.38039215686,1.0);
} else if (colType == 5) {
return vec4(0.38823529411, 0.22352941176, 0.36470588235,1.0);
} else if (colType == 6) {
return vec4(0.21568627451, 0.16470588235, 0.23137254902,1.0);
}
return vec4(0.0431372549, 0.12156862745, 0.16470588235,1.0);
}
]])