Strange cpml and vertex shader issue
Posted: Sun Oct 07, 2018 6:09 am
I'm not sure if this is a problem with cpml, or something weird with the rendering context internally in love2d, but I'm seeing a strange issue causing rendered geometry to disappear when using a model view matrix where the camera has a forward vector that points predominantly in the +X or -X direction, in otherwords 45 degrees off from an identity matrix.
I attached an example showing a view point rotating back and fourth and the geometry disappearing when the angle surpasses -45 or +45 degrees. Used with love-11.1.0-win64
Heres the source of the example:
I attached an example showing a view point rotating back and fourth and the geometry disappearing when the angle surpasses -45 or +45 degrees. Used with love-11.1.0-win64
Heres the source of the example:
Code: Select all
cpml = require "libraries/cpml"
color = cpml.color
mat4 = cpml.mat4
quat = cpml.quat
vec2 = cpml.vec2
vec3 = cpml.vec3
bound2 = cpml.bound2
bound3 = cpml.bound3
vec2.one = vec2(1, 1)
vec3.one = vec3(1, 1, 1)
local vertexShader= [[
extern mat4 modelViewMatrix;
extern mat4 projectionMatrix;
vec4 position(mat4 notUsedMatrix, vec4 vertexPosition)
{
vec4 vertex = projectionMatrix*modelViewMatrix*vertexPosition;
return vertex;
}
]]
local pixelShader = [[
vec4 effect(vec4 vertexColor, Image texture, vec2 textureCoords, vec2 screenCoords)
{
vec4 color = Texel(texture, textureCoords);
return color*vertexColor;
}
]]
local shader = love.graphics.newShader(pixelShader, vertexShader)
local vertexFormat = {
{"VertexPosition", "float", 3},
{"VertexTexCoord", "float", 2},
{"VertexColor", "byte", 4},
}
local vertexData = {
{
-0.5, 0, 0,
0, 0,
1, 0, 0, 1
},
{
0.5, 0, 0,
1, 0,
0, 1, 0, 1
},
{
0, 1, 0,
1, 1,
0, 0, 1, 1
}
}
local mesh = love.graphics.newMesh(vertexFormat, vertexData, "triangles", "dynamic")
function love.draw()
local yaw = math.cos(love.timer.getTime())*1
love.graphics.print("degrees "..math.floor(math.deg(yaw)), 10, 10)
local cameraMatrix = mat4():identity()
cameraMatrix:translate(cameraMatrix, vec3(0, 0, 4))
cameraMatrix:rotate(cameraMatrix, yaw, vec3.unit_y)
cameraMatrix = mat4.invert(cameraMatrix, cameraMatrix)
local projectionMatrix = mat4.from_perspective(70, 1.7777, 0.01, 1000)
shader:send("modelViewMatrix", "column", cameraMatrix)
shader:send("projectionMatrix", "column", projectionMatrix)
love.graphics.setShader(shader)
love.graphics.draw(mesh, 0, 0)
love.graphics.setShader()
end