replaced bells, diffuse lighitng everywhere, started terrain, test puzzle swap

This commit is contained in:
wan-may 2025-03-19 19:03:55 -03:00
parent 533f1c5534
commit 5adca6b4fa
28 changed files with 720 additions and 236 deletions

View File

@ -26,5 +26,9 @@ ENTER TO KEEP]],
win = [[ZIMINIAR HAS ARRIVED. THE WORLD WILL NEVER BE THE SAME. win = [[ZIMINIAR HAS ARRIVED. THE WORLD WILL NEVER BE THE SAME.
RICHES TO THE CONJUROR! RICHES TO THE CONJUROR!
]] ]],
phoneRing = "THE PHONE RINGS IMPATIENTLY",
phonePickup = "[%s]: PICK UP",
phoneRedial = "[%s]: *69",
phoneClue = "THE TIME IS %dP.M. 🔔🔔🔔🔔🔔🔔🔔",
} }

20
src/level/light.lua Normal file
View File

@ -0,0 +1,20 @@
local function normal( a, b, c )
local norm = a*a+b*b+c*c
if norm < 0.0001 then return p end
norm = 1.0 / math.sqrt( norm )
return norm *a, norm *b, norm *c
end
local light = {}
light[1], light[2], light[3] = normal( 1.0, 1.0, 0.0 ) --direction TO the light btw
light.target = 1
local c, s, p = math.cos, math.sin, 2*math.pi
function light.setTarget( i )
light.target = light.target + 1
i = i - 1
light[1], light[2], light[3] = normal( c(i*p/7), 1, s(i*p/7) )
end
return light

View File

@ -1,25 +0,0 @@
local lg = assert( love.graphics )
local mesh = lg.newMesh(
{--attributes
{"VertexPosition", "float", 2},
{"VertexTexCoord", "float", 2},
},
{--vertices
{ 1, 0, -a,
1, 1, 1,
1, 0 },
{ -1, 0, -a,
1, 0, 0,
0, 0 },
{ 0, 1, a,
0, 1, 0,
1, 1, },
{ 0, -1, a,
0, 0, 1,
0, 1, },
},
"strip",
"static"
)
mesh:setVertexMap{ 1,2,3,4,1,2 }
return mesh

View File

@ -11,6 +11,8 @@ local debugTF = love.math.newTransform()
local sky local sky
local bell local bell
local contempra local contempra
local terrain
local light = require( "level.light" )
function t.start() function t.start()
canvas = { canvas = {
@ -22,6 +24,7 @@ function t.start()
sky = require( "models.sky" ) sky = require( "models.sky" )
bell = require( "models.bell" ) bell = require( "models.bell" )
contempra = require( "models.contempra" ) contempra = require( "models.contempra" )
terrain = require( "models.terrain" )
end end
function t.debug() function t.debug()
@ -52,9 +55,10 @@ function t.draw( view, proj )
love.graphics.replaceTransform( tf ) love.graphics.replaceTransform( tf )
love.graphics.setMeshCullMode( "back" ) love.graphics.setMeshCullMode( "back" )
sky.draw( view, proj ) sky.draw( view, proj, light )
bell.draw( view, proj ) terrain.draw( view, proj )
contempra.draw( view, proj ) bell.draw( view, proj, light )
contempra.draw( view, proj, light )
love.graphics.pop() love.graphics.pop()
@ -67,14 +71,20 @@ function t.draw( view, proj )
end end
end end
function t.update( mesh, modelMatrix ) function t.update( player )
meshes[mesh] = modelMatrix
end end
function t.add( mesh, shaderName ) function t.transposeBells( i, j )
shaderName = shaderName or "matte" return bell.transpose( i, j )
meshes[mesh] = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, {0, 0, 1, 0}, {0, 0, 0, 1} } end
drawLists[shaderName][mesh] = true
function t.targetLight( i )
return light.setTarget( i )
end
function t.pickupPhone()
return contempra.pickup()
end end
return t return t

View File

@ -16,6 +16,11 @@ function t.TRS( x, y, z, a, b, g, dx, dy, dz )
{dx, dy, dz, 1}} {dx, dy, dz, 1}}
end end
--gltf properties to matrix
function t.gltfTRS( scale, rotation, translation )
end
--position of camera x y z --position of camera x y z
--yaw a --yaw a
--pitch b --pitch b

BIN
src/models/bell-height.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 KiB

BIN
src/models/bell.bin Normal file

Binary file not shown.

137
src/models/bell.gltf Normal file
View File

@ -0,0 +1,137 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v4.2.70",
"version":"2.0"
},
"scene":0,
"scenes":[
{
"name":"Scene",
"nodes":[
0
]
}
],
"nodes":[
{
"mesh":0,
"name":"Plane"
}
],
"materials":[
{
"doubleSided":true,
"name":"Material.001",
"pbrMetallicRoughness":{
"baseColorTexture":{
"index":0
},
"metallicFactor":0,
"roughnessFactor":0.5
}
}
],
"meshes":[
{
"name":"Plane",
"primitives":[
{
"attributes":{
"POSITION":0,
"NORMAL":1,
"TEXCOORD_0":2
},
"indices":3,
"material":0
}
]
}
],
"textures":[
{
"sampler":0,
"source":0
}
],
"images":[
{
"mimeType":"image/jpeg",
"name":"bell-height",
"uri":"bell-height.jpg"
}
],
"accessors":[
{
"bufferView":0,
"componentType":5126,
"count":3775,
"max":[
0.9985347986221313,
1.7237859964370728,
0.9926199316978455
],
"min":[
-0.9985349774360657,
0.0007939338684082031,
-1.0005090236663818
],
"type":"VEC3"
},
{
"bufferView":1,
"componentType":5126,
"count":3775,
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5126,
"count":3775,
"type":"VEC2"
},
{
"bufferView":3,
"componentType":5123,
"count":5625,
"type":"SCALAR"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":45300,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":45300,
"byteOffset":45300,
"target":34962
},
{
"buffer":0,
"byteLength":30200,
"byteOffset":90600,
"target":34962
},
{
"buffer":0,
"byteLength":11250,
"byteOffset":120800,
"target":34963
}
],
"samplers":[
{
"magFilter":9729,
"minFilter":9987
}
],
"buffers":[
{
"byteLength":132052,
"uri":"bell.bin"
}
]
}

View File

@ -1,106 +1,148 @@
local dkjson = require( "lib.dkjson" )
local love = assert( love )
local lg = assert( love.graphics ) local lg = assert( love.graphics )
local math = math local math = math
local mat = require( "mat4" ) local mat = require( "mat4" )
local DETAIL = 15
local CURVE = 45
local vertices = {} local attributeNames = {
POSITION = "VertexPosition",
NORMAL = "VertexNormal",
TEXCOORD_0 = "VertexTexCoord",
}
local function dr( y ) local types = {
return -math.pow( 1-y, -2/3 ) * 0.6/3 ["SCALAR"] = 1,
end ["VEC3"] = 3,
["VEC2"] = 2,
}
local function radius( y ) local componentTypes = {
return math.pow( math.max( 0, [5121] = "byte",
0.6 * math.pow( (1-y), 1/3 ) + [5123] = "unorm16",
0.1 * math.exp( -5*y )), [5126] = "float",
0.8) }
end
local loops = {} local elementComponentTypes = {
for i = 1, CURVE do loops[i] = {} end [5123] = "uint16",
[5126] = "uint32",
}
local filterTypes = {
[9729] = "linear",
[9987] = "linear",
}
local asset
local buffer
do do
local c, s = math.cos( 2*math.pi / DETAIL ), -math.sin( 2*math.pi / DETAIL ) local fd = assert( love.filesystem.newFileData( "models/bell.gltf" ) )
local n = 1 asset = dkjson.decode( fd:getString() )
local y = 0 buffer = love.filesystem.newFileData( "models/bell.bin" )
for i, loop in ipairs( loops ) do
local x, z = 1, 0
y = y + 1 / #loops
local r = radius( y )
local dy = dr( y )
for j = 1, DETAIL + 1 do
--need the extra vertex so the texture wraps correctly
local u = 5 * ( j - 1 ) / DETAIL
local v = 3 * (1.0 - y) - 1.0
vertices[ n ] = { r * x, y, r * z, u, v, x, 0, z }
loop[j] = n
n = n + 1
x, z = c*x+s*z, c*z-s*x
end
end
end end
local function constructVertexMap() --load all the bufferViews
local map = {} local bufferViews = {}
local k = 1 for i, view in pairs( asset.bufferViews ) do
for i, loop in ipairs( loops ) do bufferViews[i] = love.data.newByteData( buffer, view.byteOffset, view.byteLength )
local nextLoop = loops[i+1]
if not nextLoop then return map end
for j, n in ipairs( loop ) do
map[k] = n
map[k+1] = nextLoop[j]
k=k+2
end
end
end end
local function attributeFormat( attributeName, accessor )
return {
assert(attributeNames[attributeName]),
assert(componentTypes[accessor.componentType]),
assert(types[accessor.type]) }
end
local bellMesh = lg.newMesh( local function lgTexture( matIdx )
{--attributes local tex = asset.textures[1+matIdx]
{"VertexPosition", "float", 3}, local img = asset.images[1+tex.source]
{"VertexTexCoord", "float", 2}, local smpl = asset.samplers[1+tex.sampler]
{"VertexNormal", "float", 3}, img = love.graphics.newImage( "tex/"..img.uri, { mipmaps = true } )
}, img:setWrap( "repeat", "repeat" )
vertices, img:setFilter( filterTypes[smpl.minFilter], filterTypes[smpl.magFilter] )
"strip", img:setMipmapFilter( filterTypes[smpl.minFilter] )
return img
end
local function lgMesh( primitive )
assert( not( primitive.mode ) ) --triangles only
local finalMesh
for name, accIdx in pairs( primitive.attributes ) do
local acc = asset.accessors[accIdx+1]
local mesh = love.graphics.newMesh(
{attributeFormat(name, acc)}, --vertexformat
acc.count,
"triangles",
"static" "static"
) )
local bellPositions = {} local bfv = bufferViews[1+acc.bufferView]
mesh:setVertices( bfv )
if finalMesh then
finalMesh:attachAttribute( attributeNames[name], mesh )
else
finalMesh = mesh
end
end
do
local acc = asset.accessors[1+primitive.indices]
local bfv = bufferViews[1+acc.bufferView]
finalMesh:setVertexMap(bfv, elementComponentTypes[acc.componentType] )
end
if primitive.material then finalMesh:setTexture( lgTexture( primitive.material ) ) end
return finalMesh
end
local bellMesh = lgMesh( asset.meshes[1].primitives[1] )
--each bell has the following positional data:
-- scale, x, z, colorparam
local bells = {}
local bellInstanceMesh
do do
local c, s = math.cos( 2*math.pi / 7 ), -math.sin( 2*math.pi / 7 ) local c, s = math.cos( 2*math.pi / 7 ), -math.sin( 2*math.pi / 7 )
local x, z = 1, 0 local x, z = 1, 0
local r = 15 local r = 15
for i = 1, 7 do for i = 1, 7 do
bellPositions[i] = { i / 2, r * x, r * z, (i-1)/6 } bells[i] = { i / 2, r * x, r * z, (i-1)/6 }
x, z = c*x+s*z, c*z-s*x x, z = c*x+s*z, c*z-s*x
end end
bellMesh:attachAttribute( "bellInstance", bellInstanceMesh = lg.newMesh({{"bellInstance","float",4}}, bells, nil, "static" )
lg.newMesh({{"bellInstance","float",4}}, bellPositions, nil, "static" ), bellMesh:attachAttribute( "bellInstance", bellInstanceMesh,
"perinstance" ) "perinstance" )
end end
bellMesh:setVertexMap( constructVertexMap() )
do
local bellTexture = lg.newImage( "tex/bell-height.png", {mipmaps = true} )
bellTexture:setWrap( "repeat", "clampzero" )
bellMesh:setTexture( bellTexture )
end
local t = {} local t = {}
t.shader = require( "shaders.bell" ) t.shader = require( "shaders.bell" )
t.mesh = bellMesh t.mesh = bellMesh
function t.draw( view, proj ) function t.draw( view, proj, light )
local s = t.shader local s = t.shader
s:send( "view", "column", view ) s:send( "view", "column", view )
s:send( "proj", "column", proj ) s:send( "proj", "column", proj )
s:send("light", light )
lg.setShader(s) lg.setShader(s)
lg.drawInstanced( t.mesh, 7 ) lg.drawInstanced( t.mesh, 7 )
end end
function t.transpose( i, j )
print( "transposing:", i, j )
io.flush()
bells[i][2], bells[i][3], bells[j][2], bells[j][3] =
bells[j][2], bells[j][3], bells[i][2], bells[i][3]
bellInstanceMesh:setVertices( bells )
bellMesh:attachAttribute( "bellInstance", bellInstanceMesh,
"perinstance" )
end
return t return t

Binary file not shown.

View File

@ -10,23 +10,60 @@
"name":"Scene", "name":"Scene",
"nodes":[ "nodes":[
0, 0,
1 1,
2
] ]
} }
], ],
"nodes":[ "nodes":[
{ {
"mesh":0, "mesh":0,
"name":"Phone" "name":"Table"
}, },
{ {
"mesh":1, "mesh":1,
"name":"Handset" "name":"Handset",
"rotation":[
0,
0.9925320744514465,
0,
0.12198396772146225
],
"scale":[
0.2577824592590332,
0.2577824592590332,
0.2577824592590332
],
"translation":[
-0.5825188159942627,
1,
0
]
},
{
"mesh":2,
"name":"Phone",
"rotation":[
0,
0.9925320744514465,
0,
0.12198396772146225
],
"scale":[
0.2577824592590332,
0.2577824592590332,
0.2577824592590332
],
"translation":[
-0.5825188159942627,
1,
0
]
} }
], ],
"meshes":[ "meshes":[
{ {
"name":"Phone", "name":"Table",
"primitives":[ "primitives":[
{ {
"attributes":{ "attributes":{
@ -48,12 +85,80 @@
"indices":5 "indices":5
} }
] ]
},
{
"name":"Phone",
"primitives":[
{
"attributes":{
"POSITION":6,
"NORMAL":7
},
"indices":8
}
]
} }
], ],
"accessors":[ "accessors":[
{ {
"bufferView":0, "bufferView":0,
"componentType":5126, "componentType":5126,
"count":1838,
"max":[
1.100633144378662,
0.9967015981674194,
1.100633144378662
],
"min":[
-1.100633144378662,
0.0033593475818634033,
-1.100633144378662
],
"type":"VEC3"
},
{
"bufferView":1,
"componentType":5126,
"count":1838,
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5123,
"count":2868,
"type":"SCALAR"
},
{
"bufferView":3,
"componentType":5126,
"count":396,
"max":[
1.3204938173294067,
0.7231597304344177,
-0.10927927494049072
],
"min":[
-1.4686684608459473,
0.10958258807659149,
-0.8433066010475159
],
"type":"VEC3"
},
{
"bufferView":4,
"componentType":5126,
"count":396,
"type":"VEC3"
},
{
"bufferView":5,
"componentType":5123,
"count":600,
"type":"SCALAR"
},
{
"bufferView":6,
"componentType":5126,
"count":260, "count":260,
"max":[ "max":[
1.3268864154815674, 1.3268864154815674,
@ -68,87 +173,77 @@
"type":"VEC3" "type":"VEC3"
}, },
{ {
"bufferView":1, "bufferView":7,
"componentType":5126, "componentType":5126,
"count":260, "count":260,
"type":"VEC3" "type":"VEC3"
}, },
{ {
"bufferView":2, "bufferView":8,
"componentType":5123, "componentType":5123,
"count":546, "count":546,
"type":"SCALAR" "type":"SCALAR"
},
{
"bufferView":3,
"componentType":5126,
"count":76,
"max":[
1.3234574794769287,
0.728451132774353,
-0.10927927494049072
],
"min":[
-1.482479214668274,
0.10958258807659149,
-0.8433066010475159
],
"type":"VEC3"
},
{
"bufferView":4,
"componentType":5126,
"count":76,
"type":"VEC3"
},
{
"bufferView":5,
"componentType":5123,
"count":120,
"type":"SCALAR"
} }
], ],
"bufferViews":[ "bufferViews":[
{ {
"buffer":0, "buffer":0,
"byteLength":3120, "byteLength":22056,
"byteOffset":0, "byteOffset":0,
"target":34962 "target":34962
}, },
{
"buffer":0,
"byteLength":22056,
"byteOffset":22056,
"target":34962
},
{
"buffer":0,
"byteLength":5736,
"byteOffset":44112,
"target":34963
},
{
"buffer":0,
"byteLength":4752,
"byteOffset":49848,
"target":34962
},
{
"buffer":0,
"byteLength":4752,
"byteOffset":54600,
"target":34962
},
{
"buffer":0,
"byteLength":1200,
"byteOffset":59352,
"target":34963
},
{ {
"buffer":0, "buffer":0,
"byteLength":3120, "byteLength":3120,
"byteOffset":3120, "byteOffset":60552,
"target":34962
},
{
"buffer":0,
"byteLength":3120,
"byteOffset":63672,
"target":34962 "target":34962
}, },
{ {
"buffer":0, "buffer":0,
"byteLength":1092, "byteLength":1092,
"byteOffset":6240, "byteOffset":66792,
"target":34963
},
{
"buffer":0,
"byteLength":912,
"byteOffset":7332,
"target":34962
},
{
"buffer":0,
"byteLength":912,
"byteOffset":8244,
"target":34962
},
{
"buffer":0,
"byteLength":240,
"byteOffset":9156,
"target":34963 "target":34963
} }
], ],
"buffers":[ "buffers":[
{ {
"byteLength":9396, "byteLength":67884,
"uri":"contempra.bin" "uri":"contempra.bin"
} }
] ]

View File

@ -76,8 +76,23 @@ local function lgMesh( primitive )
return finalMesh return finalMesh
end end
local phone = lgMesh( asset.meshes[1].primitives[1] ) --flat hierarchy only, ignores rotation. quaternions, man :(
local handset = lgMesh( asset.meshes[2].primitives[1] ) local function getNodeTransform( node )
if not node.scale then return end
return mat.TRS(
node.scale[1], node.scale[2], node.scale[3],
0, 0, 0,
node.translation[1], node.translation[2], node.translation[3] )
end
local meshes = {}
local transforms = { mat.id() }
for _, nodeIdx in pairs( asset.scenes[1].nodes ) do
local node = asset.nodes[1+nodeIdx]
local mesh = asset.meshes[1+node.mesh]
meshes[mesh.name] = lgMesh( mesh.primitives[1] )
transforms[mesh.name] = getNodeTransform( node ) or transforms[1]
end
local obj = { local obj = {
@ -89,34 +104,37 @@ local obj = {
size = 0.1, size = 0.1,
} }
local phoneTF = mat.TRS(
obj.size,obj.size,obj.size,
0,0.12,0,
obj.x, obj.y, obj.z)
local lx, lz = 1, 0 local colors = setmetatable(
local c, s = math.cos( 0.01 ), math.sin( 0.01 ) {
function obj.draw( view, proj ) Handset = {0.9, 0.1, 0.1 },
Phone = {0.85, 0.1, 0.1 },
Table = {0.30, 0.1, 0.1 },
},
{__index = { 0, 0, 0 } }
)
love.graphics.setColor( 1,0.2,0.2,1 ) function obj.draw( view, proj, light )
love.graphics.setMeshCullMode( "none" ) --debug love.graphics.setMeshCullMode( "none" ) --debug
shader:send( "view", "column", view ) shader:send( "view", "column", view )
shader:send( "proj", "column", proj ) shader:send( "proj", "column", proj )
shader:send( "light", light )
lx, lz = c*lx+s*lz,c*lz-s*lx
shader:send( "light", {0, 1, 0} )
love.graphics.setShader( shader ) love.graphics.setShader( shader )
shader:send( "mdl", "column", phoneTF ) for name, mesh in pairs( meshes ) do
love.graphics.draw( phone ) if ( name ~= "Handset" or not obj.pickedUp ) then
love.graphics.draw( handset ) love.graphics.setColor( colors[name] )
shader:send( "mdl", "column", transforms[name] )
love.graphics.draw( mesh )
end
end
end end
function obj.ring() function obj.update( player )
end end
function obj.answer() function obj.pickup( )
obj.pickedUp = true
end end
return obj return obj

View File

@ -27,25 +27,15 @@ mesh:setVertexMap{
5, 1, 7, 5, 1, 7,
1, 7, 3, 1, 7, 3,
} }
local cubemap = lg.newCubeImage(
{
"tex/cubemap_5.png",
"tex/cubemap_4.png",
"tex/cubemap_2.png",
"tex/cubemap_3.png",
"tex/cubemap_0.png",
"tex/cubemap_1.png",
},
{mipmaps = true} )
local shader = require( "shaders.sky" ) local shader = require( "shaders.sky" )
shader:send( "cube", cubemap )
local function draw( view, proj ) local function draw( view, proj, light )
lg.push( "all" ) lg.push( "all" )
lg.setDepthMode( "always", false ) lg.setDepthMode( "always", false )
lg.setMeshCullMode( "none" ) lg.setMeshCullMode( "none" )
--get view matrix without translation --get view matrix without translation
shader:send( "light", light )
shader:send( "proj", "column", proj ) shader:send( "proj", "column", proj )
shader:send( "view", "column", {view[1], view[2], view[3], {0, 0, 0, 1}} ) shader:send( "view", "column", {view[1], view[2], view[3], {0, 0, 0, 1}} )
lg.setShader( shader ) lg.setShader( shader )

View File

@ -1,23 +1,112 @@
local lg = assert( love.graphics ) local love = assert( love )
local math = math local math = math
local mat = require( "mat4" )
local dkjson = require( "lib.dkjson" )
local shader = require( "shaders.spike" )
local vertices = {{0, 1, 0, 1/2, 3}} local attributeNames = {
POSITION = "VertexPosition",
NORMAL = "VertexNormal",
TEXCOORD_0 = "VertexTexCoord",
}
local c, s = math.cos( math.pi / 8 ), math.sin( math.pi / 8 ) local types = {
local x, z = 1, 0 ["SCALAR"] = 1,
for i = 1, 17 do ["VEC3"] = 3,
local u, v = i / 17, 1 - i / 17 ["VEC2"] = 2,
vertices[ i + 1 ] = { x, 0, z, u, 0} }
x, z = c*x+s*z, c*z-s*x
local componentTypes = {
[5121] = "byte",
[5123] = "unorm16",
[5126] = "float",
}
local elementComponentTypes = {
[5123] = "uint16",
[5126] = "uint32",
}
local filterTypes = {
[9729] = "linear",
[9987] = "linear",
}
local asset
local buffer
do
local fd = assert( love.filesystem.newFileData( "models/bell.gltf" ) )
asset = dkjson.decode( fd:getString() )
buffer = love.filesystem.newFileData( "models/bell.bin" )
end end
local mesh = lg.newMesh( --load all the bufferViews
{--attributes local bufferViews = {}
{"VertexPosition", "float", 3}, for i, view in pairs( asset.bufferViews ) do
{"VertexTexCoord", "float", 2}, bufferViews[i] = love.data.newByteData( buffer, view.byteOffset, view.byteLength )
}, end
vertices,
"fan", local function attributeFormat( attributeName, accessor )
return {
assert(attributeNames[attributeName]),
assert(componentTypes[accessor.componentType]),
assert(types[accessor.type]) }
end
local function lgTexture( matIdx )
local tex = asset.textures[1+matIdx]
local img = asset.images[1+tex.source]
local smpl = asset.samplers[1+tex.sampler]
img = love.graphics.newImage( "tex/"..img.uri, { mipmaps = true } )
img:setWrap( "repeat", "repeat" )
img:setFilter( filterTypes[smpl.minFilter], filterTypes[smpl.magFilter] )
img:setMipmapFilter( filterTypes[smpl.minFilter] )
return img
end
local function lgMesh( primitive )
assert( not( primitive.mode ) ) --triangles only
local finalMesh
for name, accIdx in pairs( primitive.attributes ) do
local acc = asset.accessors[accIdx+1]
local mesh = love.graphics.newMesh(
{attributeFormat(name, acc)}, --vertexformat
acc.count,
"triangles",
"static" "static"
) )
return mesh
local bfv = bufferViews[1+acc.bufferView]
mesh:setVertices( bfv )
if finalMesh then
finalMesh:attachAttribute( attributeNames[name], mesh )
else
finalMesh = mesh
end
end
do
local acc = asset.accessors[1+primitive.indices]
local bfv = bufferViews[1+acc.bufferView]
finalMesh:setVertexMap(bfv, elementComponentTypes[acc.componentType] )
end
if primitive.material then finalMesh:setTexture( lgTexture( primitive.material ) ) end
return finalMesh
end
local spike = lgMesh( asset.meshes[1].primitives[1] )
local spikeInstanceMesh = {}
local spikes = {}
function spikes.draw( view, proj, light )
end
return spikes

71
src/models/terrain.lua Normal file
View File

@ -0,0 +1,71 @@
local love = assert( love )
local ffi = require( "ffi" )
local sideLength = 256
local vertexCount = sideLength * sideLength
local vertices = love.data.newByteData( 4 * vertexCount )
local vertexMap = love.data.newByteData( 2 * vertexCount )
local height = love.graphics.newImage( "tex/terrain.png" )
local mesh = love.graphics.newMesh(
{{"VertexPosition", "float", 1 }},
vertexCount,
"strip",
"static"
)
mesh:setTexture( height )
do
local p = vertexMap:getFFIPointer()
local ptr = ffi.cast( "uint16_t *", p)
for i = 0, vertexCount - 1 do
ptr[i] = i
end
mesh:setVertexMap( vertexMap, "uint16" )
do local _ = p end --keep alive?
end
local shader = love.graphics.newShader[[
#pragma glsl3
#define fog vec4( 0.85, 0.85, 1.0, 1.0 )
#define fogHigh vec4( 1.0, 1.0, 0.9, 1.0 )
varying float depth;
//varying vec3 normal;
varying vec4 world;
#ifdef VERTEX
uniform mat4 view;
uniform mat4 proj;
// attribute vec3 VertexNormal;
vec4 position( mat4 _, vec4 pos ){
//normal = VertexNormal;
world = pos;
vec4 eye = view * world;
depth = -eye.z;
return proj*eye;
}
#endif
#ifdef PIXEL
//uniform vec3 light;
vec4 effect( vec4 color, Image tex, vec2 texuv, vec2 scruv) {
// vec3 norm = normalize( normal );
// vec3 toLight = normalize( light - world.xyz );
// float diff = max( dot( norm, light ), 0.5 );
// vec4 mainColor = vec4( diff * color.rgb, color.a );
return mix( mix( color * Texel( tex, texuv ), fog,
clamp( depth / 80.0, 0.0, 1.0)), fogHigh,
clamp( world.y / 20.0, 0.0, 1.0)) ;
}
#endif
]]
local obj = { height = height }
function obj.draw( view, proj )
shader:send( "view", "column", view )
shader:send( "proj", "column", proj )
love.graphics.setShader( shader )
love.graphics.draw( mesh )
end
return obj

View File

@ -14,7 +14,7 @@ local player = {
rate = 0.01, --tick rate rate = 0.01, --tick rate
speed = 2, --movement speed m/s speed = 2, --movement speed m/s
x = 0, x = 0,
y = 0.5, y = 1.5,
z = 3, z = 3,
vx = 0, vx = 0,
vz = 0, vz = 0,
@ -75,7 +75,8 @@ end
local function collide( ix, iz, fx, fz, circles, lines ) local function collide( ix, iz, fx, fz, circles, lines )
local x, z = ix, iz local x, z = ix, iz
for _, circle in pairs( circles ) do for _, circle in pairs( circles ) do
if distanceToSegment( ix, iz, fx, fz ) then if distanceToSegment( ix, iz, fx, fz, circle.x, circle.z ) <
circle.r * circle.r then
end end
end end

View File

@ -58,6 +58,7 @@ function t.update( dt )
player:update() player:update()
end end
world.update( player )
end end
function t.mousepressed( x, y, button, isTouch, presses ) function t.mousepressed( x, y, button, isTouch, presses )
@ -73,11 +74,20 @@ function t.keypressed( key, code, isrepeat )
if code == settings.keyUse.val then if code == settings.keyUse.val then
end end
if code == "q" then if code == "2" then
local strings = require( "i18n" ) local strings = require( "i18n" )
local slideshow = require( "scenes.slideshow" ) local slideshow = require( "scenes.slideshow" )
return slideshow.play( strings.win, love.event.quit, "tex/win.jpg" ) return slideshow.play( strings.win, love.event.quit, "tex/win.jpg" )
end end
if code == "3" then
return world.targetLight( math.random( 1, 7 ) )
end
if code == "4" then
return world.pickupPhone()
end
if code == "1" then
return world.transposeBells( 2, 7 )
end
end end
function t.keyreleased( key, code ) function t.keyreleased( key, code )

View File

@ -45,7 +45,7 @@ function t.keypressed( key, code, isRepeat )
if code == "return" then if code == "return" then
local slideshow = require( "scenes.slideshow" ) local slideshow = require( "scenes.slideshow" )
local main = require( "scenes.main" ) local main = require( "scenes.main" )
return slideshow.play( strings.intro, main.play, "tex/jared.jpg" ) return slideshow.play( strings.intro, main.play )
end end
end end

View File

@ -1,6 +1,6 @@
local sfx = {} local sfx = {}
function sfx.playFootstep() function sfx.playFootstep()
print( "step" ) --print( "step" )
end end
return sfx return sfx

View File

@ -3,32 +3,48 @@ return love.graphics.newShader[[
#define fogHigh vec4( 1.0, 1.0, 0.85, 1.0 ) #define fogHigh vec4( 1.0, 1.0, 0.85, 1.0 )
#define sunDir 0.1 * vec3( 0.9, 0.2, 0.5 ) #define sunDir 0.1 * vec3( 0.9, 0.2, 0.5 )
varying float depth; varying float depth;
varying float height; varying vec3 normal;
varying vec4 world;
varying float instanceColor; varying float instanceColor;
#ifdef VERTEX #ifdef VERTEX
//per instance: (uniform) scale and xz position //per instance: (uniform) scale and xz position
attribute vec4 bellInstance; attribute vec4 bellInstance;
attribute vec3 vertexNormal; attribute vec3 VertexNormal;
uniform mat4 view; uniform mat4 view;
uniform mat4 proj; uniform mat4 proj;
vec4 position( mat4 _, vec4 pos ){ vec4 position( mat4 _, vec4 pos ){
normal = (view*vec4(VertexNormal,1.0)).rgb;
instanceColor = bellInstance.a; instanceColor = bellInstance.a;
pos.xyz *= bellInstance.r; pos.xyz *= bellInstance.r;
pos.xz += bellInstance.gb; pos.xz += bellInstance.gb;
height = pos.y; world = pos;
vec4 eye = view * pos; vec4 eye = view * pos;
depth = -eye.z; depth = -eye.z;
return proj*eye; return proj*eye;
} }
#endif #endif
#ifdef PIXEL #ifdef PIXEL
uniform vec3 light;
vec4 effect( vec4 color, Image tex, vec2 texuv, vec2 scruv) { vec4 effect( vec4 color, Image tex, vec2 texuv, vec2 scruv) {
vec4 icolor = mix( vec4(1.0,1.0,1.0,1.0), vec4(0.5,0.0,0.0,1.0), instanceColor ); vec4 icolor = mix( vec4(1.0,1.0,1.0,1.0), vec4(0.5,0.0,0.0,1.0), instanceColor );
vec4 texel = Texel( tex, texuv ); vec4 texel = Texel( tex, texuv );
vec4 bellColor = icolor * (texel + (1.0 - texel.a)); float y = texuv.y;
return color * mix( mix( bellColor, y = max( 0.1,
1.4 * pow( 0.9*y*(1.0-0.9*y) , 0.25));
texel.rgb *= y;
texel.gb *= 0.5 * instanceColor + 0.75;
//diffuse light
vec3 norm = normalize( normal );
vec3 toLight = normalize( light - world.xyz );
float diff = max( dot( norm, light ), 0.1 );
vec4 mainColor = vec4( diff * texel.rgb, texel.a );
return color * mix( mix( mainColor,
fog, clamp( depth / 80.0, 0.0, 1.0)), fog, clamp( depth / 80.0, 0.0, 1.0)),
fogHigh, clamp( height / 20.0, 0.0, 1.0)); fogHigh, clamp(world.y / 20.0, 0.0, 1.0));
} }
#endif #endif
]] ]]

View File

@ -22,7 +22,7 @@ return love.graphics.newShader[[
vec4 effect( vec4 color, Image tex, vec2 texuv, vec2 scruv) { vec4 effect( vec4 color, Image tex, vec2 texuv, vec2 scruv) {
vec3 norm = normalize( normal ); vec3 norm = normalize( normal );
vec3 toLight = normalize( light - world.xyz ); vec3 toLight = normalize( light - world.xyz );
float diff = max( dot( norm, light ), 0.5 ); float diff = max( dot( norm, light ), 0.1 );
vec4 mainColor = vec4( diff * color.rgb, color.a ); vec4 mainColor = vec4( diff * color.rgb, color.a );

View File

@ -1,22 +1,23 @@
return love.graphics.newShader[[ return love.graphics.newShader[[
#define fog vec4( 0.85, 0.85, 1.0, 1.0 ) #define fog vec4( 0.85, 0.85, 1.0, 1.0 )
#define yellow vec4( 0.9, 0.9, 0.7, 1.0 )
#define blue vec4( 0.6, 0.6, 0.7, 1.0 )
varying vec3 viewDir; varying vec3 viewDir;
#ifdef VERTEX #ifdef VERTEX
uniform mat4 view; uniform mat4 view;
uniform mat4 proj; uniform mat4 proj;
vec4 position( mat4 _, vec4 pos ){ vec4 position( mat4 _, vec4 pos ){
viewDir = pos.xyz; viewDir = pos.xyz;
viewDir.y -= 0.5;
return proj*view*pos; return proj*view*pos;
} }
#endif #endif
#ifdef PIXEL #ifdef PIXEL
uniform samplerCube cube; uniform vec3 light;
vec4 effect( vec4 color, Image _, vec2 __, vec2 ___) { vec4 effect( vec4 color, Image _, vec2 __, vec2 ___) {
return color * Texel( cube, viewDir ) + 0.5 * dot( viewDir, vec3( 0.0, 1.0, 0.0 )); float d = dot( normalize( viewDir ), light );
//mix( fog, d = 0.5+0.5*d;
//Texel( cube, viewDir ), d = pow(d, 45);
//dot(viewDir, vec3(0.0, 0.0, 1.0 )));; return mix( blue, mix( yellow, color, d * 2 ) , d );
} }
#endif #endif
]] ]]

0
src/shaders/spike.lua Normal file
View File

BIN
src/tex/bell-height.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 55 KiB