diff options
| author | Alexander M Pickering <alex@cogarr.net> | 2025-01-19 15:23:06 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2025-01-19 15:23:06 -0600 |
| commit | da9dd31f504d30f33922cdf362a7c01673a6b927 (patch) | |
| tree | 6e3247dc8f57c16fd02d7ac07246d82c8ab65ccb /src/shaders | |
| parent | 90ee66a3a6aae10fd84f3f43844db55229933e37 (diff) | |
| download | ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.tar.gz ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.tar.bz2 ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.zip | |
Last commit before theme release
Diffstat (limited to 'src/shaders')
| -rw-r--r-- | src/shaders/stars.lua | 2 | ||||
| -rw-r--r-- | src/shaders/world.frag | 1 | ||||
| -rw-r--r-- | src/shaders/world.moon | 138 | ||||
| -rw-r--r-- | src/shaders/world.vert | 10 |
4 files changed, 138 insertions, 13 deletions
diff --git a/src/shaders/stars.lua b/src/shaders/stars.lua index 111bef8..8d54b16 100644 --- a/src/shaders/stars.lua +++ b/src/shaders/stars.lua @@ -41,7 +41,7 @@ local node = am.use_program(am.program([[ void main() { float world_x_off = mod(world_x, world_x_period); float world_y_off = mod(world_y, world_y_period); - gl_Position = P * MV * vec4(stars.x - world_x_off, stars.y - world_y_off, 0.0, 1.0); + gl_Position = P * MV * vec4(stars.x - world_x_off, stars.y - world_y_off, 0., 1.0); float intensity = sin(stars.z + time) * cos(time) + 1.; gl_PointSize = pow(intensity, 2.) * stars.z * 0.3; } diff --git a/src/shaders/world.frag b/src/shaders/world.frag index ded8abb..15d7b27 100644 --- a/src/shaders/world.frag +++ b/src/shaders/world.frag @@ -1,5 +1,6 @@ precision mediump float; varying vec2 textureuv; // uv +varying float radius; uniform sampler2D textures; uniform sampler2D emissives; uniform sampler2D normals; 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! diff --git a/src/shaders/world.vert b/src/shaders/world.vert index 0e6747a..42276fe 100644 --- a/src/shaders/world.vert +++ b/src/shaders/world.vert @@ -1,7 +1,9 @@ precision highp float; attribute vec3 world; // position attribute vec2 texuv; +attribute float r; // for round objects, 0 for non-round varying vec2 textureuv; +varying float radius; varying mat3 light1; uniform vec4 color; varying vec4 v_color; @@ -13,10 +15,12 @@ void main() { v_color = vec4(world.xyz,1.); vec2 vxy = vec2(world.x - world_x, world.y - world_y); float z_scale = 0.5; - float xoff = world.z * vxy.x * z_scale; - float yoff = world.z * vxy.y * z_scale; + float xoff = clamp(world.z * vxy.x * z_scale, -32., 32.); + float yoff = clamp(world.z * vxy.y * z_scale, -32., 32.); textureuv=texuv; + //radius = r; // if z > 0 then // xoff = ceil(xoff, 0) - gl_Position = P * MV * vec4(vxy.x + xoff, vxy.y + yoff, 0., 1.0); + // add to the z coord so we don't intersect with the ui + gl_Position = P * MV * vec4(vxy.x + xoff, vxy.y + yoff, -world.z -1., 1.0); } |
