Browse Source

Port more examples;

bjorn 2 years ago
parent
commit
021ec1d4a8

File diff suppressed because it is too large
+ 1 - 26
api/init.lua


+ 0 - 74
api/lovr/headset/getDisplayMask.lua

@@ -1,74 +0,0 @@
-return {
-  tag = 'headset',
-  summary = 'Get a mesh that masks out the visible display area.',
-  description = [[
-    Returns 2D triangle vertices that represent areas of the headset display that will never be seen
-    by the user (due to the circular lenses).  This area can be masked out by rendering it to the
-    depth buffer or stencil buffer.  Then, further drawing operations can skip rendering those
-    pixels using the depth test (`lovr.graphics.setDepthTest`) or stencil test
-    (`lovr.graphics.setStencilTest`), which improves performance.
-  ]],
-  arguments = {},
-  returns = {
-    points = {
-      type = 'table',
-      description = 'A table of points.  Each point is a table with two numbers between 0 and 1.'
-    }
-  },
-  variants = {
-    {
-      arguments = {},
-      returns = { 'points' }
-    }
-  },
-  example = [=[
-    function lovr.load()
-      lovr.graphics.setBackgroundColor(1, 1, 1)
-
-      shader = lovr.graphics.newShader([[
-        vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
-
-          // Rescale mesh coordinates from (0,1) to (-1,1)
-          vertex.xy *= 2.;
-          vertex.xy -= 1.;
-
-          // Flip the mesh if it's being drawn in the right eye
-          if (lovrViewID == 1) {
-            vertex.x = -vertex.x;
-          }
-
-          return vertex;
-        }
-      ]], [[
-        // The fragment shader returns solid black for illustration purposes.  It could be transparent.
-        vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
-          return vec4(0., 0., 0., 1.);
-        }
-      ]])
-
-      mask = lovr.headset.getDisplayMask()
-
-      if mask then
-        mesh = lovr.graphics.newMesh({ { 'lovrPosition', 'float', 2 } }, mask, 'triangles')
-      end
-    end
-
-    function lovr.draw()
-      if mask then
-        -- Mask out parts of the display that aren't visible to skip rendering those pixels later
-        lovr.graphics.setShader(shader)
-        mesh:draw()
-        lovr.graphics.setShader()
-
-        -- Draw a red cube
-        lovr.graphics.setColor(0xff0000)
-        lovr.graphics.cube('fill', 0, 1.7, -1, .5, lovr.timer.getTime())
-        lovr.graphics.setColor(0xffffff)
-      else
-        lovr.graphics.setColor(0x000000)
-        lovr.graphics.print('No mask found.', 0, 1.7, -3, .2)
-        lovr.graphics.setColor(0xffffff)
-      end
-    end
-  ]=]
-}

+ 2 - 2
api/lovr/headset/newModel.lua

@@ -40,13 +40,13 @@ return {
   example = [[
   example = [[
     local models = {}
     local models = {}
 
 
-    function lovr.draw()
+    function lovr.draw(pass)
       for i, hand in ipairs(lovr.headset.getHands()) do
       for i, hand in ipairs(lovr.headset.getHands()) do
         models[hand] = models[hand] or lovr.headset.newModel(hand)
         models[hand] = models[hand] or lovr.headset.newModel(hand)
 
 
         if models[hand] then
         if models[hand] then
           local x, y, z, angle, ax, ay, az = lovr.headset.getPose(hand)
           local x, y, z, angle, ax, ay, az = lovr.headset.getPose(hand)
-          models[hand]:draw(x, y, z, 1, angle, ax, ay, az)
+          pass:draw(models[hand], x, y, z, 1, angle, ax, ay, az)
         end
         end
       end
       end
     end
     end

+ 2 - 2
api/lovr/math/Vectors/init.lua

@@ -21,9 +21,9 @@ return {
     Most LÖVR functions that accept positions, orientations, transforms, velocities, etc. also accept
     Most LÖVR functions that accept positions, orientations, transforms, velocities, etc. also accept
     vector objects, so they can be used interchangeably with numbers:
     vector objects, so they can be used interchangeably with numbers:
 
 
-        function lovr.draw()
+        function lovr.draw(pass)
           -- position and size are vec3's, rotation is a quat
           -- position and size are vec3's, rotation is a quat
-          lovr.graphics.box('fill', position, size, rotation)
+          pass:box(position, size, rotation)
         end
         end
 
 
     ### Temporary vs. Permanent
     ### Temporary vs. Permanent

+ 36 - 38
examples/Lighting/Circular_Shadows/main.lua

@@ -1,31 +1,25 @@
 function lovr.load()
 function lovr.load()
   -- shadow shader
   -- shadow shader
-  shadowVertex = [[
-    out vec3 fragPos;
-
-    vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
-      fragPos = vec3(lovrModel * vertex);
-      return projection * transform * vertex;
-    }
-  ]]
+  shadowVertex = 'unlit'
   shadowFragment = [[
   shadowFragment = [[
-    in vec3 fragPos;
-    uniform vec4 left;
-    uniform vec4 right;
-    uniform vec4 head;
+    Constants {
+      vec4 left;
+      vec4 right;
+      vec4 head;
+    };
 
 
-    vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
+    vec4 lovrmain() {
       vec4 shadowColor;
       vec4 shadowColor;
-      if (                                       // w is radius
-        (length( left.xz - fragPos.xz) <  left.w   &&    left.y > fragPos.y) ||
-        (length(right.xz - fragPos.xz) < right.w   &&   right.y > fragPos.y) ||
-        (length( head.xz - fragPos.xz) <  head.w   &&    head.y > fragPos.y)
+      if (
+        (length( left.xz - PositionWorld.xz) <  left.w   &&    left.y > PositionWorld.y) ||
+        (length(right.xz - PositionWorld.xz) < right.w   &&   right.y > PositionWorld.y) ||
+        (length( head.xz - PositionWorld.xz) <  head.w   &&    head.y > PositionWorld.y)
       ) {
       ) {
         shadowColor = vec4(.25, .625, 1, 1);
         shadowColor = vec4(.25, .625, 1, 1);
       } else {
       } else {
         shadowColor = vec4(1, 1, 1, 1);
         shadowColor = vec4(1, 1, 1, 1);
       }
       }
-      return shadowColor * graphicsColor * lovrDiffuseColor * vertexColor * texture(image, uv);
+      return shadowColor * Color * getPixel(ColorTexture, UV);
     }
     }
   ]]
   ]]
   shadowShader = lovr.graphics.newShader(shadowVertex, shadowFragment)
   shadowShader = lovr.graphics.newShader(shadowVertex, shadowFragment)
@@ -43,8 +37,6 @@ function lovr.load()
     end
     end
   end
   end
   grassTexture = lovr.graphics.newTexture(grassImage)
   grassTexture = lovr.graphics.newTexture(grassImage)
-  grassTexture:setFilter('nearest')
-  grassMaterial = lovr.graphics.newMaterial(grassTexture)
 
 
   -- boxes
   -- boxes
   boxes = {}
   boxes = {}
@@ -61,38 +53,44 @@ function lovr.load()
       b      = lovr.math.random()
       b      = lovr.math.random()
     })
     })
   end
   end
+
+  -- sky
+  lovr.graphics.setBackgroundColor(0,.5,1)
 end
 end
 
 
 function lovr.update()
 function lovr.update()
   left = vec3(lovr.headset.getPosition('left'))
   left = vec3(lovr.headset.getPosition('left'))
   right = vec3(lovr.headset.getPosition('right'))
   right = vec3(lovr.headset.getPosition('right'))
   head = vec3(mat4(lovr.headset.getPose('head')):translate(0, -.1, -.1))
   head = vec3(mat4(lovr.headset.getPose('head')):translate(0, -.1, -.1))
-
-  shadowShader:send('left',  { left.x,  left.y,  left.z, .05}) -- x, y, z, radius
-  shadowShader:send('right', {right.x, right.y, right.z, .05})
-  shadowShader:send('head',  { head.x,  head.y,  head.z, .1 })
 end
 end
 
 
-function lovr.draw()
-  -- sky
-  lovr.graphics.setBackgroundColor(0,.5,1)
+function lovr.draw(pass)
 
 
   -- grass
   -- grass
-  lovr.graphics.setColor(1, 1, 1)
-  lovr.graphics.setShader(shadowShader)
-  lovr.graphics.box(grassMaterial, 0, 0, 0, 10, 1, 10)
-  lovr.graphics.setShader()
+  pass:setShader(shadowShader)
+  pass:send('left',  { left.x,  left.y,  left.z, .05}) -- x, y, z, radius
+  pass:send('right', {right.x, right.y, right.z, .05})
+  pass:send('head',  { head.x,  head.y,  head.z, .1 })
+  pass:setMaterial(grassTexture)
+  pass:setSampler('nearest')
+  pass:box(0, 0, 0, 10, 1, 10)
+  pass:setMaterial()
+  pass:setSampler()
+  pass:setShader()
 
 
   -- boxes
   -- boxes
-  lovr.graphics.setShader(shadowShader)
+  pass:setShader(shadowShader)
+  pass:send('left',  { left.x,  left.y,  left.z, .05}) -- x, y, z, radius
+  pass:send('right', {right.x, right.y, right.z, .05})
+  pass:send('head',  { head.x,  head.y,  head.z, .1 })
   for _, box in pairs(boxes) do
   for _, box in pairs(boxes) do
-    lovr.graphics.setColor(box.r, box.g, box.b)
-    lovr.graphics.box('fill', box.x, box.y, box.z, box.width, box.height, box.depth)
+    pass:setColor(box.r, box.g, box.b)
+    pass:box(box.x, box.y, box.z, box.width, box.height, box.depth)
   end
   end
-  lovr.graphics.setShader()
+  pass:setShader()
 
 
   -- hands
   -- hands
-  lovr.graphics.setColor(.9, .7, .1)
-  lovr.graphics.sphere(vec3(lovr.headset.getPosition('left')), .05)
-  lovr.graphics.sphere(vec3(lovr.headset.getPosition('right')), .05)
+  pass:setColor(.9, .7, .1)
+  pass:sphere(vec3(lovr.headset.getPosition('left')), .05)
+  pass:sphere(vec3(lovr.headset.getPosition('right')), .05)
 end
 end

Some files were not shown because too many files changed in this diff