diff options
Diffstat (limited to 'src/shaders/world.moon')
| -rw-r--r-- | src/shaders/world.moon | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/src/shaders/world.moon b/src/shaders/world.moon new file mode 100644 index 0000000..ad40cb9 --- /dev/null +++ b/src/shaders/world.moon @@ -0,0 +1,125 @@ +win = require("window") +color = require("color") +world = require("world") +sprites = require("world.sprites") +shader_shim = require("shader_shim") +hc = require("party.hardoncollider.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 +near_plane = 1 +far_plane = 2 +aspect = win.width / win.height +s_mv = mat4( + 1, 0, 0, 0, + 0, aspect, 0, 0, + 0, 0, 1, 0, + -0.5, 0.5, 0, 4 + ) +p_mv = mat4( + 1 / ((win.width / win.height) * math.tan(view_angle / 2)), 0, 0, 0, + 0, 1/math.tan(view_angle/2), 0, 0, + 0, 0, far_plane / (far_plane - near_plane), 1, + 0, 0,(-far_plane * near_plane)/(far_plane - near_plane), 0 +) + +-- Each point needs: +-- vec3 position (x,y,z) +-- vec2 (u,v) +up_down_hall = (x,y) -> + r = { + --floor + vec3(x,y,0), + vec3(x+1,y,0), + vec3(x+1,y-1,0), + vec3(x+1,y-1,0), + vec3(x,y-1,0), + vec3(x,y,0), + + -- Left wall + vec3(x,y,1), + vec3(x,y,0), + vec3(x,y-1,0), + vec3(x,y-1,0), + vec3(x,y-1,1), + vec3(x,y,1), + + --Right wall + vec3(x+1,y,0), + vec3(x+1,y,1), + vec3(x+1,y-1,1), + vec3(x+1,y-1,1), + vec3(x+1,y-1,0), + vec3(x+1,y,0), + } + r + +sd = sprites.floor1_diffuse +w1 = sprites.wall1_diffuse + +-- uvs are s,t,smult, tmult +up_down_hall_uv = (x,y) -> + r = { + --floor + vec4(sd.s1,sd.t1,1,1), + vec4(sd.s2,sd.t1,1,1), + vec4(sd.s2,sd.t2,1,1), + vec4(sd.s2,sd.t2,1,1), + vec4(sd.s1,sd.t2,1,1), + vec4(sd.s1,sd.t1,1,1), + -- left wall + 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), + -- right wall + vec4(w1.s2,w1.t2,1,1), + vec4(w1.s2,w1.t1,1,1), + vec4(w1.s1,w1.t1,1,1), + vec4(w1.s1,w1.t1,1,1), + vec4(w1.s1,w1.t2,1,1), + vec4(w1.s2,w1.t2,1,1), + + } + r + +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)) +add_verts(world_uv, up_down_hall_uv(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_uv, up_down_hall_uv(0,0)) +--sprites["diffuse"].texture.wrap = "repeat" +--sprites["normals"].texture.wrap = "repeat" +node = shader_shim.world\append(am.cull_face("front")\append(am.bind({ + MV: s_mv + P: mat4(1) + color: color.am_color.highlight, + world_x: 0, + world_y: 0, + world: am.vec3_array(world_geom) + time: am.current_time(), + textures: sprites.floor1_diffuse.texture + texuv: am.vec4_array(world_uv) +})\append(am.draw("triangles")))) +node\action(() => + bind = self("bind") + bind.time = am.current_time! + bind.world_x = math.sin(am.current_time!) * 2 + bind.world_y = math.cos(am.current_time!) * 2 +) +{ + node: node + bind: node("bind") +} |
