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
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks. | |
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/) | |
(() => { | |
const SHOW_SIDES = false; // color sides of DOM nodes? | |
const COLOR_SURFACE = true; // color tops of DOM nodes? | |
const COLOR_RANDOM = false; // randomise color? | |
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com) | |
const MAX_ROTATION = 180; // set to 360 to rotate all the way round | |
const THICKNESS = 20; // thickness of layers | |
const DISTANCE = 10000; // ¯\\_(ツ)_/¯ |
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
// What we want is the mouse position to stay the same relative to the zoomable object (it's a map in this example) | |
// To do that we solve the equation "oldMouseRelativePos = newMouseRelativePos" to find the value of newMapOffset. | |
// We know the values of oldZoom, newZoom, oldMapOffset and mousePos | |
// | |
// It is assumed that canvas->screen (something you would use in OpenGL, for example) transform is "(p - offset) / zoom", | |
// meaning screen->canvas (something you would use in Canvas2D) transform is "p / zoom - offset". | |
// mousePos is assumed to be in some kind of screen coordinates | |
// mapZoom is assumed to be zooming relative to the top left corner of the map | |
// | |
// "map relative mouse position" is: |
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( | |
[[ |
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
// | |
struct TerminalCell | |
{ | |
// cell index into GlyphTexture, should be two 16-bit (x,y) values packed: "x | (y << 16)" | |
uint GlyphIndex; | |
// 0xAABBGGRR encoded colors, nonzero alpha for Foreground indicates to render colored-glyph | |
// which means use RGB values from GlyphTexture directly as output, not as ClearType blending weights | |
uint Foreground; |