فهرست منبع

Add Triplanar_Mapping example;

bjorn 10 ماه پیش
والد
کامیت
92c456c689

BIN
examples/Environment/Triplanar_Mapping/dirt.png


BIN
examples/Environment/Triplanar_Mapping/grass.png


+ 41 - 0
examples/Environment/Triplanar_Mapping/main.lua

@@ -0,0 +1,41 @@
+function lovr.load()
+  grass = lovr.graphics.newTexture('grass.png')
+  rock = lovr.graphics.newTexture('rock.png')
+  dirt = lovr.graphics.newTexture('dirt.png')
+
+  triplanar = lovr.graphics.newShader('unlit', [[
+    uniform texture2D textureX;
+    uniform texture2D textureY;
+    uniform texture2D textureZ;
+    uniform float textureScale;
+
+    vec4 lovrmain() {
+      vec2 xscale = vec2(-sign(Normal.x), -1.);
+      vec2 yscale = vec2( sign(Normal.y), +1.);
+      vec2 zscale = vec2( sign(Normal.z), -1.);
+
+      vec3 colorX = getPixel(textureX, PositionWorld.zy * textureScale * xscale).rgb;
+      vec3 colorY = getPixel(textureY, PositionWorld.xz * textureScale * yscale).rgb;
+      vec3 colorZ = getPixel(textureZ, PositionWorld.xy * textureScale * zscale).rgb;
+
+      vec3 normal = abs(normalize(Normal));
+      vec3 weight = normal / (normal.x + normal.y + normal.z);
+      vec3 color = colorX * weight.x + colorY * weight.y + colorZ * weight.z;
+      
+      return Color * vec4(color, 1.);
+    }
+  ]])
+end
+
+function lovr.draw(pass)
+  pass:setShader(triplanar)
+  pass:send('textureScale', 1.0)
+  pass:send('textureX', rock)
+  pass:send('textureY', grass)
+  pass:send('textureZ', dirt)
+
+  local width = 4 + 2 * math.cos(lovr.timer.getTime())
+  local height = 3 + 2 * math.sin(lovr.timer.getTime())
+
+  pass:box(0, -2, -10, width, height, 3)
+end

BIN
examples/Environment/Triplanar_Mapping/rock.png


+ 1 - 0
examples/init.lua

@@ -25,6 +25,7 @@ return {
   'Environment/Skybox',
   'Environment/Skybox',
   'Environment/Terrain_-_Heightmap',
   'Environment/Terrain_-_Heightmap',
   'Environment/Terrain_-_Procedural',
   'Environment/Terrain_-_Procedural',
+  'Environment/Triplanar_Mapping',
   'Lighting/Cel_Shading',
   'Lighting/Cel_Shading',
   'Lighting/Circular_Shadows',
   'Lighting/Circular_Shadows',
   'Lighting/PBR_Materials',
   'Lighting/PBR_Materials',