This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local cam = require'cam' -- https://github.com/jmiskovic/lovr-cam | |
local player_pos = Vec3() | |
local player_vel = Vec3(0, 0, -0.01) | |
local function getWorldFromScreen(pass) | |
local w, h = pass:getDimensions() | |
local clip_from_screen = mat4(-1, -1, 0):scale(2 / w, 2 / h, 1) | |
local view_pose = mat4(pass:getViewPose(1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- directional light shadow mapping for lovr 0.18 (currenly on post 0.17.1 dev branch) | |
local m = {} | |
m.near = 0.01 | |
m.far = 500 | |
m.orthographic_span = 40 | |
m.perspective_fov = 90 | |
m.view_pose = lovr.math.newMat4() | |
:lookAt( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- manages "stages" with a stack interface | |
-- stage is Lua module with callbacks (load, update, draw, keypress...) | |
-- only single stage is active, one on top of the stack | |
-- after push and pop operation another stage takes over the callbacks | |
-- example stack: os > main_menu > level_selection > game_play > overlay_menu | |
-- example usage: | |
-- local stagestack = require'stagestack' | |
-- stagestack.push(require'main_menu') | |
local m = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Creates a few hundred colliders which can be dragged around with right mouse button | |
-- Uses phywire.lua from https://github.com/jmiskovic/lovr-phywire | |
local phywire = require'phywire' | |
local world = lovr.physics.newWorld(0,0,0, false) | |
world:setLinearDamping(0.1) | |
world:setAngularDamping(0.1) | |
local mouse_collider = world:newSphereCollider(0,0,0, 0.001) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ Point light shaddow mapping | |
This is obsolete version that requires few modifications to work on post 0.17 lovr | |
See this updated version: https://github.com/Tackyflea/lovrShadows/ | |
-- usage snippets | |
local point_light = require('point_light') | |
point_light.load(1024, vec3(0, 1, 0)) -- depth texture resolution & position | |
-- in lovr.update(dt), or at start of lovr.draw(pass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- LOVR demo: Creates a few hundred colliders and allows to drag them around using the right mouse button | |
-- Dependencies: | |
-- lovr-mouse.lua from https://github.com/bjornbytes/lovr-mouse/ | |
-- mousearm.lua from https://github.com/jmiskovic/lovr-mousearm | |
-- phywire.lua from https://github.com/jmiskovic/lovr-phywire | |
local mousearm = require'mousearm' | |
local phywire = require'phywire' | |
local world = lovr.physics.newWorld(0,0,0, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local skybox = {} -- from https://github.com/jmiskovic/lovr-atmo | |
skybox.__index = skybox | |
function skybox.new(resolution) | |
local self = setmetatable({}, skybox) | |
self.resolution = math.floor(resolution or 256) | |
assert(self.resolution > 0 and self.resolution < 6000) | |
self.cubetex = lovr.graphics.newTexture( | |
self.resolution, self.resolution, 6, | |
{type='cube', mipmaps=false, usage = {'render', 'sample', 'transfer'}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local resolution = 1024 | |
local group_size = 16 | |
local tex1 = lovr.graphics.newTexture(resolution, resolution, {mipmaps = false, usage = {'render', 'sample', 'storage', 'transfer'}, linear = true}) | |
local tex2 = lovr.graphics.newTexture(resolution, resolution, {mipmaps = false, usage = {'render', 'sample', 'storage', 'transfer'}, linear = true}) | |
local tex = lovr.graphics.newTexture(resolution, resolution, {mipmaps = false, usage = {'render', 'sample', 'storage', 'transfer'}, linear = true}) | |
local projection = lovr.math.newMat4():perspective(math.rad(110), 1, .1, 0) | |
local palette = {0xded4c8, 0xbeaa9c, 0x94837a, 0x645c59, 0x181e28, 0xdbaf88, 0xb8926f, 0x987052, 0x624a30, 0x2f2114, 0xdf8b79, 0xe26560, 0xb0454c, 0x5b3636, 0xe5be3e, 0xbe8e03, 0x916803, 0x644507, 0xf18b49, 0xd46b2b, 0xba5113, 0x7a3412, 0xeb8281, 0xd95b5b, 0xbf2f37, 0x64272c, 0xb58fb6, 0x7e638e, 0x594a66, 0x3c3145, 0x30bab3, 0x1390ac, 0x0b5472, 0x233552, 0xabcf5f, 0x789949, 0x39681d, 0x084739} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local light_pose = lovr.math.newMat4() | |
local light_view = lovr.math.newMat4() | |
local light_projection = lovr.math.newMat4():perspective(math.rad(120), 1, 0.01) | |
--light_projection:orthographic(-5, 5, -5, 5, 100, -100) -- why is near and far inverted? ¯\_(ツ)_/¯ | |
local depthBufferSize = 1024 | |
local depthtex = lovr.graphics.newTexture(depthBufferSize, depthBufferSize, {format = 'd32f', mipmaps = false, usage = {'render', 'sample'}}) | |
local shadowmapper = lovr.graphics.newShader( | |
[[ |