summaryrefslogtreecommitdiff
path: root/src/shaders/world.moon
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2025-01-19 15:23:06 -0600
committerAlexander M Pickering <alex@cogarr.net>2025-01-19 15:23:06 -0600
commitda9dd31f504d30f33922cdf362a7c01673a6b927 (patch)
tree6e3247dc8f57c16fd02d7ac07246d82c8ab65ccb /src/shaders/world.moon
parent90ee66a3a6aae10fd84f3f43844db55229933e37 (diff)
downloadggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.tar.gz
ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.tar.bz2
ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.zip
Last commit before theme release
Diffstat (limited to 'src/shaders/world.moon')
-rw-r--r--src/shaders/world.moon138
1 files changed, 129 insertions, 9 deletions
diff --git a/src/shaders/world.moon b/src/shaders/world.moon
index ad40cb9..e9ddcc9 100644
--- a/src/shaders/world.moon
+++ b/src/shaders/world.moon
@@ -3,10 +3,9 @@ color = require("color")
world = require("world")
sprites = require("world.sprites")
shader_shim = require("shader_shim")
-hc = require("party.hardoncollider.init")
+hc = require("party.hc.init")
-- Process the world into buffers to send to the shader
-error("Who is including world?")
print("sprites:",sprites,getmetatable(sprites))
print("sprites.floor1_diffuse",sprites["floor1_diffuse"])
view_angle = math.pi / 4
@@ -26,6 +25,9 @@ p_mv = mat4(
0, 0,(-far_plane * near_plane)/(far_plane - near_plane), 0
)
+sd = sprites.floor1_diffuse
+w1 = sprites.wall1_diffuse
+
-- Each point needs:
-- vec3 position (x,y,z)
-- vec2 (u,v)
@@ -57,8 +59,84 @@ up_down_hall = (x,y) ->
}
r
-sd = sprites.floor1_diffuse
-w1 = sprites.wall1_diffuse
+room = (x,y,w,h,left_holes,right_holes,top_holes,bottom_holes) ->
+ left_holes\sort()
+ right_holes\sort()
+ top_holes\sort()
+ bottom_holes\sort()
+ r = {
+ --floor
+ vec3(x,y,0)
+ vec3(x+w,y,0),
+ vec3(x+w,y-h,0),
+ vec3(x+w,y-h,0),
+ vec3(x,y-h,0),
+ vec3(x,y,0),
+
+ --left wall
+ }
+ r
+
+barrel = (x,y,w,h) ->
+ tris = 18
+ rad = (w/2)
+ l = x - (w/2)
+ j = x + (w/2)
+ t = h
+ b = 0
+ f = y - (w/2)
+ n = y + (w/2)
+ r = {
+ --top
+ vec3(l,f,h),
+ vec3(l,n,h),
+ vec3(j,n,h),
+ vec3(j,n,h),
+ vec3(j,f,h),
+ vec3(l,f,h),
+ }
+ step = (2*math.pi)/tris
+ for i = 0,2*math.pi,step
+ r[#r+1] =vec3(x + math.cos(i)*rad,y + math.sin(i)*n,h)
+ r[#r+1] =vec3(x + math.cos(i+step)*rad,math.sin(i+step)*n,h)
+ r[#r+1] =vec3(x + math.cos(i+step)*rad,math.sin(i+step)*n,0)
+ r[#r+1] =vec3(x + math.cos(i+step)*rad,math.sin(i+step)*n,0)
+ r[#r+1] =vec3(x + math.cos(i)*rad,math.sin(i)*n,0)
+ r[#r+1] =vec3(x + math.cos(i)*rad,math.sin(i)*n,h)
+ r
+
+barrel_uv = (x,y,w,h) ->
+ tris = 18
+ r = {
+ vec4(w1.s1,w1.t1,1,1),
+ vec4(w1.s1,w1.t2,1,1),
+ vec4(w1.s2,w1.t2,1,1),
+ vec4(w1.s2,w1.t2,1,1),
+ vec4(w1.s2,w1.t1,1,1),
+ vec4(w1.s1,w1.t1,1,1),
+ }
+ step = (2*math.pi)/tris
+ for i = 0,2*math.pi,step
+ perc = (i / (2*math.pi))
+ nextperc = ((i+step) / (2*math.pi))
+ srange = w1.s2 - w1.s1
+ trange = w1.t2 - w1.t1
+ sstart = w1.s1 + (srange * perc)
+ send = w1.s1 + (srange * nextperc)
+ tstart = w1.t1
+ tend = w1.t2
+ r[#r+1] = vec4(sstart ,tstart,1,1)
+ r[#r+1] = vec4(sstart ,tend,1,1)
+ r[#r+1] = vec4(send ,tend,1,1)
+ r[#r+1] = vec4(send ,tend,1,1)
+ r[#r+1] = vec4(send ,tstart,1,1)
+ r[#r+1] = vec4(sstart ,tstart,1,1)
+ r
+
+barrel_r = (x,y,w,h) ->
+ r = {-1,-1,1,1,1,-1,0,0,0,0,0,0}
+ r
+
-- uvs are s,t,smult, tmult
up_down_hall_uv = (x,y) ->
@@ -88,31 +166,73 @@ up_down_hall_uv = (x,y) ->
}
r
+up_down_hall_r = (x,y) ->
+ r = {
+ 0,0,0,0,0,0
+ 0,0,0,0,0,0
+ 0,0,0,0,0,0
+ 0,0,0,0,0,0
+ 0,0,0,0,0,0
+ 0,0,0,0,0,0
+ }
+ r
+
+-- Barrel?
+
+
add_verts = (tbl, new) ->
for i = 1, #new
tbl[#tbl+1] = new[i]
world_geom = {}
world_uv = {}
-add_verts(world_geom, up_down_hall(0,0))
+world_r = {}
+add_verts(world_geom, up_down_hall(0,-1))
add_verts(world_uv, up_down_hall_uv(0,0))
+add_verts(world_r, up_down_hall_r(0,0))
add_verts(world_geom, up_down_hall(0,1))
add_verts(world_uv, up_down_hall_uv(0,0))
-add_verts(world_geom, up_down_hall(0,-1))
+add_verts(world_r, up_down_hall_r(0,0))
+add_verts(world_geom, up_down_hall(0,0))
add_verts(world_uv, up_down_hall_uv(0,0))
+add_verts(world_r, up_down_hall_r(0,0))
+add_verts(world_geom, barrel(-1,0,0.5,0.5))
+add_verts(world_uv, barrel_uv(-1,0,0.5,0.5))
+add_verts(world_r, barrel_r(-1,0,0.5,0.5))
+--add_verts(world_geom, barrel(0.5,0.5,0.5,0.5))
+--add_verts(world_uv, barrel_uv(0.5,0.5,0.5,0.5))
+--add_verts(world_r, barrel_r(0.5,0.5,0.5,0.5))
--sprites["diffuse"].texture.wrap = "repeat"
--sprites["normals"].texture.wrap = "repeat"
-node = shader_shim.world\append(am.cull_face("front")\append(am.bind({
+
+test_world = {
+ vec3(0,0,0),
+ vec3(1,0,0),
+ vec3(0,1,0)
+}
+test_uvs = {
+ vec4(sd.s1,sd.t1,1,1),
+ vec4(sd.s2,sd.t1,1,1),
+ vec4(sd.s2,sd.t2,1,1),
+}
+test_r = {
+ 0,0,0
+}
+node = shader_shim.world\append(am.depth_test("less")\append(am.cull_face("front")\append(am.bind({ -- should cull front
MV: s_mv
P: mat4(1)
color: color.am_color.highlight,
world_x: 0,
world_y: 0,
world: am.vec3_array(world_geom)
+ texuv: am.vec4_array(world_uv)
+ r: am.float_array(world_r)
+ --world:am.vec3_array(test_world)
+ --texuv: am.vec4_array(test_uvs)
+ --r: am.float_array(test_r)
time: am.current_time(),
textures: sprites.floor1_diffuse.texture
- texuv: am.vec4_array(world_uv)
-})\append(am.draw("triangles"))))
+})\append(am.draw("triangles")))))
node\action(() =>
bind = self("bind")
bind.time = am.current_time!