Explorar o código

Remove direction from lights, now using front vector

trethaller %!s(int64=7) %!d(string=hai) anos
pai
achega
2c669e6ae1
Modificáronse 3 ficheiros con 10 adicións e 28 borrados
  1. 2 23
      h3d/scene/DirLight.hx
  2. 6 1
      h3d/scene/Light.hx
  3. 2 4
      h3d/scene/pbr/DirLight.hx

+ 2 - 23
h3d/scene/DirLight.hx

@@ -3,11 +3,9 @@ package h3d.scene;
 class DirLight extends Light {
 class DirLight extends Light {
 
 
 	var dshader : h3d.shader.DirLight;
 	var dshader : h3d.shader.DirLight;
-	public var direction : h3d.Vector;
 
 
-	public function new(dir, ?parent) {
+	public function new(?parent) {
 		dshader = new h3d.shader.DirLight();
 		dshader = new h3d.shader.DirLight();
-		direction = dir;
 		super(dshader, parent);
 		super(dshader, parent);
 		priority = 100;
 		priority = 100;
 	}
 	}
@@ -28,28 +26,9 @@ class DirLight extends Light {
 		return dshader.enableSpecular = b;
 		return dshader.enableSpecular = b;
 	}
 	}
 
 
-	override function getShadowDirection() {
-		return direction;
-	}
-
 	override function emit(ctx) {
 	override function emit(ctx) {
-		dshader.direction.set(direction.x, direction.y, direction.z);
+		dshader.direction.load(absPos.front());
 		dshader.direction.normalize();
 		dshader.direction.normalize();
 		super.emit(ctx);
 		super.emit(ctx);
 	}
 	}
-
-	#if hxbit
-	override function customSerialize(ctx:hxbit.Serializer) {
-		super.customSerialize(ctx);
-		ctx.addDouble(direction.x);
-		ctx.addDouble(direction.y);
-		ctx.addDouble(direction.z);
-	}
-	override function customUnserialize(ctx:hxbit.Serializer) {
-		shader = dshader = new h3d.shader.DirLight();
-		super.customUnserialize(ctx);
-		direction = new h3d.Vector(ctx.getDouble(), ctx.getDouble(), ctx.getDouble());
-	}
-	#end
-
 }
 }

+ 6 - 1
h3d/scene/Light.hx

@@ -39,7 +39,12 @@ class Light extends Object {
 	}
 	}
 
 
 	function getShadowDirection() : h3d.Vector {
 	function getShadowDirection() : h3d.Vector {
-		return null;
+		return absPos.front();
+	}
+
+	public function setDirection(x: Float, y: Float, z: Float) {
+		qRot.initDirection(new h3d.Vector(x, y, z));
+		posChanged = true;
 	}
 	}
 
 
 	#if hxbit
 	#if hxbit

+ 2 - 4
h3d/scene/pbr/DirLight.hx

@@ -3,12 +3,10 @@ package h3d.scene.pbr;
 class DirLight extends Light {
 class DirLight extends Light {
 
 
 	var pbr : h3d.shader.pbr.Light.DirLight;
 	var pbr : h3d.shader.pbr.Light.DirLight;
-	public var direction : h3d.Vector;
 
 
-	public function new(?direction, ?parent) {
+	public function new(?parent) {
 		pbr = new h3d.shader.pbr.Light.DirLight();
 		pbr = new h3d.shader.pbr.Light.DirLight();
 		super(pbr,parent);
 		super(pbr,parent);
-		this.direction = direction == null ? new h3d.Vector(0,0,-1) : direction;
 	}
 	}
 
 
 	override function get_isSun() {
 	override function get_isSun() {
@@ -22,7 +20,7 @@ class DirLight extends Light {
 	override function emit(ctx:RenderContext) {
 	override function emit(ctx:RenderContext) {
 		pbr.lightColor.load(_color);
 		pbr.lightColor.load(_color);
 		pbr.lightColor.scale3(power * power);
 		pbr.lightColor.scale3(power * power);
-		pbr.lightDir.load(direction);
+		pbr.lightDir.load(absPos.front());
 		pbr.lightDir.scale3(-1);
 		pbr.lightDir.scale3(-1);
 		pbr.lightDir.normalize();
 		pbr.lightDir.normalize();
 		super.emit(ctx);
 		super.emit(ctx);