Okay, some good people helped me on love's discord server (thank you again
)
As expected problem was in my perspective matrix. It was column-major, not row-major.
There is a multiple variants to resolve this priblem:
a) In shader:send use "column" parameter instead "row"
b) Use row-major perspective projection matrix:
Code: Select all
function perspective_projection(fov, aspect, near, far)
local t = tan(rad(fov)/2)
return mat4(1/(aspect*t),0,0,0,
0,1/t,0,0,
0,0,-(far+near)/(far-near),-(2*far*near)/(far-near),
0,0,-1,0)
end
c) Convert matrix from column-major to row-major like this:
Code: Select all
projection = columnToRow(projection:unpack())
shader:send("proj", projection)
function columnToRow(matrix)
-- Column -> Row major
if love._version_major > 0 then
matrix[2], matrix[5] = matrix[5], matrix[2]
matrix[3], matrix[9] = matrix[9], matrix[3]
matrix[4], matrix[13] = matrix[13], matrix[4]
matrix[7], matrix[10] = matrix[10], matrix[7]
matrix[8], matrix[14] = matrix[14], matrix[8]
matrix[12], matrix[15] = matrix[15], matrix[12]
end
return matrix
end
And also need to change model position -10 units by z-axis to make sure it's in front of the camera