Browse Source

Add Environment/Grid example;

bjorn 5 years ago
parent
commit
bade888e4e
2 changed files with 34 additions and 0 deletions
  1. 33 0
      examples/Environment/Grid/main.lua
  2. 1 0
      examples/init.lua

+ 33 - 0
examples/Environment/Grid/main.lua

@@ -0,0 +1,33 @@
+function lovr.load()
+  shader = lovr.graphics.newShader([[
+    vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
+      return projection * transform * vertex;
+    }
+  ]], [[
+    const float gridSize = 25.;
+    const float cellSize = .5;
+
+    vec4 color(vec4 gcolor, sampler2D image, vec2 uv) {
+
+      // Distance-based alpha (1. at the middle, 0. at edges)
+      float alpha = 1. - smoothstep(.15, .50, distance(uv, vec2(.5)));
+
+      // Grid coordinate
+      uv *= gridSize;
+      uv /= cellSize;
+      vec2 c = abs(fract(uv - .5) - .5) / fwidth(uv);
+      float line = clamp(1. - min(c.x, c.y), 0., 1.);
+      vec3 value = mix(vec3(.01, .01, .011), (vec3(.04)), line);
+
+      return vec4(vec3(value), alpha);
+    }
+  ]], { flags = { highp = true } })
+
+  lovr.graphics.setBackgroundColor(.05, .05, .05)
+end
+
+function lovr.draw()
+  lovr.graphics.setShader(shader)
+  lovr.graphics.plane('fill', 0, 0, 0, 25, 25, -math.pi / 2, 1, 0, 0)
+  lovr.graphics.setShader()
+end

+ 1 - 0
examples/init.lua

@@ -8,6 +8,7 @@ return {
   'Interaction/Pointer_UI',
   'Interaction/Pointer_UI',
   'Interaction/Physics_Pointer',
   'Interaction/Physics_Pointer',
   'Interaction/Controller_Models',
   'Interaction/Controller_Models',
+  'Environment/Grid',
   'Custom_Mesh',
   'Custom_Mesh',
   'Animation',
   'Animation',
   'Physics',
   'Physics',