Browse Source

fix minor buffer bug

bstouls 10 years ago
parent
commit
44ab338adb
2 changed files with 24 additions and 4 deletions
  1. 4 0
      h3d/scene/World.hx
  2. 20 4
      samples/world/Main.hx

+ 4 - 0
h3d/scene/World.hx

@@ -230,11 +230,14 @@ class World extends Object {
 		soil.x = c.x;
 		soil.x = c.x;
 		soil.y = c.y;
 		soil.y = c.y;
 		soil.material.texture = h3d.mat.Texture.fromColor(soilColor);
 		soil.material.texture = h3d.mat.Texture.fromColor(soilColor);
+		soil.material.shadows = true;
 	}
 	}
 
 
 	function initMaterial( mesh : h3d.scene.Mesh, mat : WorldModelMaterial ) {
 	function initMaterial( mesh : h3d.scene.Mesh, mat : WorldModelMaterial ) {
 		mesh.material.blendMode = mat.t.blend;
 		mesh.material.blendMode = mat.t.blend;
 		mesh.material.texture = mat.t.t.tex;
 		mesh.material.texture = mat.t.t.tex;
+		mesh.material.mainPass.enableLights = true;
+		mesh.material.shadows = true;
 	}
 	}
 
 
 	override function dispose() {
 	override function dispose() {
@@ -252,6 +255,7 @@ class World extends Object {
 			var b = c.buffers.get(mat.bits);
 			var b = c.buffers.get(mat.bits);
 			if( b == null ) {
 			if( b == null ) {
 				b = new h3d.scene.Mesh(new h3d.prim.BigPrimitive(model.stride, true), c.root);
 				b = new h3d.scene.Mesh(new h3d.prim.BigPrimitive(model.stride, true), c.root);
+				c.buffers.set(mat.bits, b);
 				initMaterial(b, mat);
 				initMaterial(b, mat);
 			}
 			}
 			var p = Std.instance(b.primitive, h3d.prim.BigPrimitive);
 			var p = Std.instance(b.primitive, h3d.prim.BigPrimitive);

+ 20 - 4
samples/world/Main.hx

@@ -1,19 +1,35 @@
 class Main extends hxd.App {
 class Main extends hxd.App {
 
 
 	var world : h3d.scene.World;
 	var world : h3d.scene.World;
+	var shadow :h3d.pass.ShadowMap;
 
 
 	override function init() {
 	override function init() {
+
 		world = new h3d.scene.World(64, 128, s3d);
 		world = new h3d.scene.World(64, 128, s3d);
 		var t = world.loadModel(hxd.Res.tree);
 		var t = world.loadModel(hxd.Res.tree);
 		var r = world.loadModel(hxd.Res.rock);
 		var r = world.loadModel(hxd.Res.rock);
 
 
 		for( i in 0...1000 )
 		for( i in 0...1000 )
-			world.add(Std.random(2) == 0 ? t : r, Math.random() * 100, Math.random() * 100, 0);
-
-		s3d.camera.pos.set(0, 0, 120);
-		s3d.camera.target.set(64, 64, 0);
+			world.add(Std.random(2) == 0 ? t : r, Math.random() * 128, Math.random() * 128, 0, 1.2 + hxd.Math.srand(0.4), hxd.Math.srand(Math.PI));
 
 
 		world.done();
 		world.done();
+
+		//
+		new h3d.scene.DirLight(new h3d.Vector( 0.3, -0.4, -0.9), s3d);
+		s3d.lightSystem.ambientLight.setColor(0x909090);
+
+		s3d.camera.target.set(72, 72, 0);
+		s3d.camera.pos.set(120, 120, 120);
+
+		shadow = Std.instance(s3d.renderer.getPass("shadow"), h3d.pass.ShadowMap);
+		shadow.size = 2048;
+		shadow.power = 200;
+		shadow.blur.passes = 0;
+		shadow.bias *= 0.1;
+		shadow.color.set(0.7, 0.7, 0.7);
+		shadow.calcShadowBounds = function(cam) {
+			cam.orthoBounds = h3d.col.Bounds.fromValues( -128, -128, -64, 256, 256, 128);
+		};
 	}
 	}
 
 
 	static function main() {
 	static function main() {