Without shaders, no. Shaders are at the core of Löve. They are always running, even if you don't define any.4aiman wrote: ↑Wed Feb 28, 2018 4:32 pm Thanks a lot for your answers!
I guess I should've been more specific, though.
Love3d and other projects I saw here (love2d forums & github) use shaders and/or ffi in order to achieve proper 3d representation. Heck, even raycasters tend to be hardware-dependent (can't find a single raycaster that have textured floor/ceiling AND works on Android).
My interest lies not in love3d (or any other specific lib for that matter) and certainly not in raycasting.
I'm just wondering if there some newly-introduced built-in features of love2d 0.11.x to make perspective textured planes in 3d.
TL;DR
Something like love.graphics.rectangle(x,y,z,width,heigth, length,...) is a distant dream, but is it possible to go 3d without ffi and shaders as of now? Note that I'm talking about a cross-platform solution.
To work in 3D with OpenGL, you need a vertex shader. I've looked more into love3d now, and it's now in my to-do list to try and make a raycasting-looking demo using actual GL 3D rendering. The key to obtain it is love.graphics.newMesh and an appropriate vertex and fragment ("pixel") shader, but especially vertex.
Now, take a look at this love3d demo: https://github.com/excessive/love3d-dem ... orward.lua
Pay special attention to how little it uses "l3d" and for what purpose. In that demo, it is used ONLY for two purposes: 1) to provide a depth buffer so that only the closest pixels are drawn, and 2) to not draw polygons that don't point to the camera. The rest is done with pure Löve. For something as simple as the raycasting-like demo I've mentioned earlier, you can do without both, and then you don't need love3d, just pure Löve 0.10. The love3d demo uses the IQM library, which in turn uses functions love.graphics.newMesh and Mesh:setVertexMap to create the mesh. IQM uses FFI to speed up loading of the file format it supports, but according to what I have seen so far, it seems to me that that loading could have been implemented in pure Lua with no problems. I am still studying it.
As I noted in a previous post, Löve 0.11 provides depth buffers, and that makes (1) unnecessary. It also introduces love.graphics.setMeshCullMode, which makes (2) unnecessary. This means that with 0.11, you don't need love3d to do real 3D like in that demo.
Have I answered your question now?
Edit: Simple proof of concept follows. I see no reason for it not to work in mobile. Note it does not use any libraries or FFI, but it uses a (trivial) vertex shader.
Code: Select all
local img, sb
-- Vertex shader code
local shader = [[
extern mat4 view;
vec4 position(mat4 transform, vec4 vertex) {
// ignore love's transform which is only for 2d and use our own matrix
return view * vertex;
}
]]
function love.load(args)
img = love.graphics.newImage('image1.jpg')
-- A spritebatch is a mesh, so let's use that for simplicity
sb = love.graphics.newSpriteBatch(img, 64)
-- Generate 8x8 quads (image is 640x480 which means each quad is 80x60)
local quads = {}
for y = 0, 7 do for x = 0, 7 do
quads[y * 8 + x + 1] = love.graphics.newQuad(x*80, y*60, 80, 60, 640, 480)
end end
-- Add some quads at random
for i = 1, 60 do
sb:add(quads[love.math.random(1, 64)],
love.math.random(0, 7) * 80,
love.math.random(0, 7) * 60)
end
-- Compile the shader in place
shader = love.graphics.newShader(shader)
end
local t = 0
function love.update(dt)
t = t + dt
end
function love.draw()
-- Use a preset matrix for demo purposes. A real matrix can be generated
-- with a 3D math library like CPML.
if love._version_major > 0 then
-- love 0.11 requires the matrix in row-major order
shader:send('view', {
1.3, 0, 0, -450,
0, 0, -1.7, -120,
0, 1, 0, 50,
0, 1, 0, 50,
})
else
-- send the matrix in column-major order
shader:send('view', {
1.3, 0, 0, 0,
0, 0, 1, 1,
0, -1.7, 0, 0,
-450, -120, 50, 50,
})
end
-- Toggle vertex shader on/off every second
if t >= 2 then
love.graphics.setShader()
t = 0
elseif t >= 1 then
love.graphics.setShader(shader)
end
-- Draw the spritebatch
love.graphics.draw(sb)
end
Edit3: Updated to 11.0