Przeglądaj źródła

Allow setting dirlight directions in constructor

trethaller 7 lat temu
rodzic
commit
e9745a7a92

+ 7 - 1
h3d/scene/DirLight.hx

@@ -4,10 +4,12 @@ class DirLight extends Light {
 
 	var dshader : h3d.shader.DirLight;
 
-	public function new(?parent) {
+	public function new(?dir: h3d.Vector, ?parent) {
 		dshader = new h3d.shader.DirLight();
 		super(dshader, parent);
 		priority = 100;
+		if(dir != null)
+			setDirection(dir.x, dir.y, dir.z);
 	}
 
 	override function get_color() {
@@ -26,6 +28,10 @@ class DirLight extends Light {
 		return dshader.enableSpecular = b;
 	}
 
+	override function getShadowDirection() : h3d.Vector {
+		return getDirection();	
+	}
+
 	override function emit(ctx) {
 		dshader.direction.load(absPos.front());
 		dshader.direction.normalize();

+ 4 - 0
h3d/scene/Light.hx

@@ -39,6 +39,10 @@ class Light extends Object {
 	}
 
 	function getShadowDirection() : h3d.Vector {
+		return null;	
+	}
+
+	public function getDirection() : h3d.Vector {
 		return absPos.front();
 	}
 

+ 7 - 1
h3d/scene/pbr/DirLight.hx

@@ -4,9 +4,11 @@ class DirLight extends Light {
 
 	var pbr : h3d.shader.pbr.Light.DirLight;
 
-	public function new(?parent) {
+	public function new(?dir: h3d.Vector, ?parent) {
 		pbr = new h3d.shader.pbr.Light.DirLight();
 		super(pbr,parent);
+		if(dir != null)
+			setDirection(dir.x, dir.y, dir.z);
 	}
 
 	override function get_isSun() {
@@ -17,6 +19,10 @@ class DirLight extends Light {
 		return pbr.isSun = b;
 	}
 
+	override function getShadowDirection() : h3d.Vector {
+		return getDirection();	
+	}
+
 	override function emit(ctx:RenderContext) {
 		pbr.lightColor.load(_color);
 		pbr.lightColor.scale3(power * power);

+ 4 - 1
hxd/inspect/SceneProps.hx

@@ -249,7 +249,10 @@ class SceneProps {
 		props.push(PBool("enableSpecular", function() return l.enableSpecular, function(b) l.enableSpecular = b));
 		var dl = Std.instance(l, h3d.scene.DirLight);
 		if( dl != null )
-			props.push(PFloats("direction", function() return [dl.direction.x, dl.direction.y, dl.direction.z], function(fl) dl.direction.set(fl[0], fl[1], fl[2])));
+			props.push(PFloats("direction", function() {
+				var dir = dl.getDirection();
+				return [dl.x, dl.y, dl.z];
+			}, function(fl) dl.setDirection(fl[0], fl[1], fl[2])));
 		var pl = Std.instance(l, h3d.scene.PointLight);
 		if( pl != null )
 			props.push(PFloats("params", function() return [pl.params.x, pl.params.y, pl.params.z], function(fl) pl.params.set(fl[0], fl[1], fl[2], fl[3])));