I have a 2d, orthographic game, but I would like to have an object hovering over/in-front of the game, that is drawn in perspective. The object rotates along the y-axis. I don’t think a special, perspective camera can affect a single game object, but perhaps I could write a shader to draw the pixels in perspective based on the z-value of the pixels.
I’m hoping for a straight-forward solution. Suggestions?
You need to assign a material with a different tag so that you can call render.draw() an extra time in your render script. Before you call render.draw() you also need to set a perspective view projection using API reference (vmath)
Thanks! Looks like it’s working.
I made a material with the tag “spinObj”. and assigned it to the sprite in the object I wanted drawn in perspective.
Here’s what I added to a copy of the default renderer.
--
-- projection that draws in perspective
--
local function persp_projection(near, far)
return vmath.matrix4_perspective(3.141592/6, 2, near, far)
end
-------- added this within init function
self.spinObj_pred = render.predicate({"spinObj"})
-------- added this within the update function.
-- draw spinning object in perspective
--
local oView = vmath.matrix4_look_at(vmath.vector3(0, 0, -900), vmath.vector3(0, 0, 0), vmath.vector3(0, 1, 0))
render.set_view(oView)
proj = persp_projection(self.near, self.far+200)
render.set_projection(proj)
render.draw(self.spinObj_pred, {frustum = proj * oView})