Ver Fonte

renamed h3d.pass.LightSystem to h3d.scene.LightSystem, changed shadowLight to use getShadowDirection()

ncannasse há 7 anos atrás
pai
commit
e3a89b4486

+ 1 - 1
h3d/mat/MaterialSetup.hx

@@ -31,7 +31,7 @@ class MaterialSetup {
 	}
 
 	public function createLightSystem() {
-		return new h3d.pass.LightSystem();
+		return new h3d.scene.LightSystem();
 	}
 
 	public function initModelMaterial( material : Material ) {

+ 3 - 2
h3d/pass/ShadowMap.hx

@@ -125,10 +125,11 @@ class ShadowMap extends Default {
 		texture.depthBuffer = depth;
 		var ct = ctx.camera.target;
 		var slight = ctx.lightSystem.shadowLight;
-		if( slight == null )
+		var ldir = slight == null ? null : @:privateAccess slight.getShadowDirection();
+		if( ldir == null )
 			lightCamera.target.set(0, 0, -1);
 		else {
-			lightCamera.target.set(slight.direction.x, slight.direction.y, slight.direction.z);
+			lightCamera.target.set(ldir.x, ldir.y, ldir.z);
 			lightCamera.target.normalize();
 		}
 		lightCamera.target.x += ct.x;

+ 4 - 0
h3d/scene/DirLight.hx

@@ -28,6 +28,10 @@ class DirLight extends Light {
 		return dshader.enableSpecular = b;
 	}
 
+	override function getShadowDirection() {
+		return direction;
+	}
+
 	override function emit(ctx) {
 		dshader.direction.set(direction.x, direction.y, direction.z);
 		dshader.direction.normalize();

+ 6 - 2
h3d/scene/Light.hx

@@ -4,9 +4,9 @@ class Light extends Object {
 
 	var shader : hxsl.Shader;
 	var objectDistance : Float; // used internaly
-	@:s var cullingDistance : Float = 1e10;
-	@:noCompletion public var next : Light;
+	@:noCompletion public var next : Light; // used internaly (public to allow sorting)
 
+	@:s var cullingDistance : Float = 1e10;
 	@:s public var priority : Int = 0;
 	public var color(get, set) : h3d.Vector;
 	public var enableSpecular(get, set) : Bool;
@@ -38,6 +38,10 @@ class Light extends Object {
 		ctx.emitLight(this);
 	}
 
+	function getShadowDirection() : h3d.Vector {
+		return null;
+	}
+
 	#if hxbit
 	override function customSerialize(ctx:hxbit.Serializer) {
 		super.customSerialize(ctx);

+ 6 - 6
h3d/pass/LightSystem.hx → h3d/scene/LightSystem.hx

@@ -1,4 +1,4 @@
-package h3d.pass;
+package h3d.scene;
 
 @:access(h3d.scene.Light)
 @:access(h3d.scene.Object.absPos)
@@ -10,7 +10,7 @@ class LightSystem {
 	var ambientShader : hxsl.Shader;
 	var lightCount : Int;
 	var ctx : h3d.scene.RenderContext;
-	public var shadowLight : h3d.scene.DirLight;
+	public var shadowLight : h3d.scene.Light;
 	public var ambientLight : h3d.Vector;
 	public var perPixelLighting : Bool = true;
 
@@ -37,7 +37,7 @@ class LightSystem {
 	public function initLights( ctx : h3d.scene.RenderContext ) {
 		lightCount = 0;
 		this.ctx = ctx;
-		var l = ctx.lights, prev = null;
+		var l = ctx.lights, prev : h3d.scene.Light = null;
 		var frustum = new h3d.col.Frustum(ctx.camera.m);
 		var s = new h3d.col.Sphere();
 		while( l != null ) {
@@ -65,9 +65,9 @@ class LightSystem {
 		if( shadowLight == null || shadowLight.parent == null ) {
 			var l = ctx.lights;
 			while( l != null ) {
-				var dl = Std.instance(l, h3d.scene.DirLight);
-				if( dl != null ) {
-					shadowLight = dl;
+				var dir = @:privateAccess l.getShadowDirection();
+				if( dir != null ) {
+					shadowLight = l;
 					break;
 				}
 				l = l.next;

+ 2 - 1
h3d/scene/RenderContext.hx

@@ -15,9 +15,10 @@ class RenderContext extends h3d.impl.RenderContext {
 	public var camera : h3d.Camera;
 	public var scene : Scene;
 	public var drawPass : ObjectPass;
+	public var pbrLightPass : h3d.mat.Pass;
 
 	var sharedGlobals : Array<SharedGlobal>;
-	public var lightSystem : h3d.pass.LightSystem;
+	public var lightSystem : h3d.scene.LightSystem;
 	public var uploadParams : Void -> Void;
 	public var extraShaders : hxsl.ShaderList;
 	public var visibleFlag : Bool;

+ 4 - 1
h3d/scene/Renderer.hx

@@ -60,7 +60,7 @@ class Renderer {
 		return l;
 	}
 
-	function getLightSystem() : h3d.pass.LightSystem {
+	function getLightSystem() : h3d.scene.LightSystem {
 		return ctx.scene.lightSystem;
 	}
 
@@ -143,6 +143,9 @@ class Renderer {
 		throw "Not implemented";
 	}
 
+	public function start() {
+	}
+
 	public function process( passes : Array<PassObjects> ) {
 		hasSetTarget = false;
 		for( p in allPasses )

+ 2 - 1
h3d/scene/Scene.hx

@@ -3,7 +3,7 @@ package h3d.scene;
 class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.InteractiveScene {
 
 	public var camera : h3d.Camera;
-	public var lightSystem : h3d.pass.LightSystem;
+	public var lightSystem : LightSystem;
 	public var renderer(default,set) : Renderer;
 	var ctx : RenderContext;
 	var interactives : Array<Interactive>;
@@ -327,6 +327,7 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		ctx.engine = engine;
 		ctx.scene = this;
 		ctx.start();
+		renderer.start();
 
 		syncRec(ctx);
 		emitRec(ctx);