Преглед изворни кода

Revert pbr renderer not having depth texture. Some passes currently write depth (buffer) while sampling depth (texture). For compatibility, would require drawing them twice, not worth the overhead.

clementlandrin пре 2 година
родитељ
комит
e00db8e9af
1 измењених фајлова са 11 додато и 41 уклоњено
  1. 11 41
      h3d/scene/pbr/Renderer.hx

+ 11 - 41
h3d/scene/pbr/Renderer.hx

@@ -83,9 +83,7 @@ class Renderer extends h3d.scene.Renderer {
 		#if !MRT_low
 		#if !MRT_low
 		other : (null:h3d.mat.Texture),
 		other : (null:h3d.mat.Texture),
 		#end
 		#end
-		#if js
 		depth : (null:h3d.mat.Texture),
 		depth : (null:h3d.mat.Texture),
-		#end
 		hdr : (null:h3d.mat.Texture),
 		hdr : (null:h3d.mat.Texture),
 		ldr : (null:h3d.mat.Texture),
 		ldr : (null:h3d.mat.Texture),
 	};
 	};
@@ -103,13 +101,11 @@ class Renderer extends h3d.scene.Renderer {
 		Vec4([Value("output.normal",3),ALPHA]),
 		Vec4([Value("output.normal",3),ALPHA]),
 		#if !MRT_low
 		#if !MRT_low
 		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.occlusion"), ALPHA]),
 		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.occlusion"), ALPHA]),
-		Vec4([Value("output.emissive"), Value("output.custom1"), Value("output.custom2"), ALPHA])
+		Vec4([Value("output.emissive"), Value("output.custom1"), Value("output.custom2"), ALPHA]),
 		#else
 		#else
-		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.emissive"), ALPHA])
-		#end
-		#if js
-		,Vec4([Value("output.depth"),Const(0), Const(0), ALPHA /* ? */])
+		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.emissive"), ALPHA]),
 		#end
 		#end
+		Vec4([Value("output.depth"),Const(0), Const(0), ALPHA /* ? */])
 	]);
 	]);
 	var decalsOutput = new h3d.pass.Output("decals",[
 	var decalsOutput = new h3d.pass.Output("decals",[
 		Vec4([Swiz(Value("output.color"),[X,Y,Z]), Value("output.albedoStrength",1)]),
 		Vec4([Swiz(Value("output.color"),[X,Y,Z]), Value("output.albedoStrength",1)]),
@@ -131,10 +127,8 @@ class Renderer extends h3d.scene.Renderer {
 		#end
 		#end
 	]);
 	]);
 	var colorDepthOutput = new h3d.pass.Output("colorDepth",[
 	var colorDepthOutput = new h3d.pass.Output("colorDepth",[
-		Value("output.color")
-		#if js
-		,Vec4([Value("output.depth"),Const(0),Const(0),h3d.scene.pbr.Renderer.ALPHA])
-		#end
+		Value("output.color"),
+		Vec4([Value("output.depth"),Const(0),Const(0),h3d.scene.pbr.Renderer.ALPHA])
 	]);
 	]);
 
 
 	public function new(?env) {
 	public function new(?env) {
@@ -311,7 +305,7 @@ class Renderer extends h3d.scene.Renderer {
 
 
 		// Probe Rendering & Blending
 		// Probe Rendering & Blending
 		var probeOutput = allocTarget("probeOutput", true, 1.0, #if MRT_low RGB10A2 #else RGBA16F #end);
 		var probeOutput = allocTarget("probeOutput", true, 1.0, #if MRT_low RGB10A2 #else RGBA16F #end);
-		ctx.engine.pushTarget(probeOutput, ReadOnly);
+		ctx.engine.pushTarget(probeOutput);
 		clear(0);
 		clear(0);
 
 
 		// Default Env & SkyBox
 		// Default Env & SkyBox
@@ -399,19 +393,13 @@ class Renderer extends h3d.scene.Renderer {
 		#if !MRT_low
 		#if !MRT_low
 		textures.other = allocTarget("other", true, 1.);
 		textures.other = allocTarget("other", true, 1.);
 		#end
 		#end
-		#if js
 		textures.depth = allocTarget("depth", true, 1., R32F);
 		textures.depth = allocTarget("depth", true, 1., R32F);
-		#end
 		textures.hdr = allocTarget("hdrOutput", true, 1, #if MRT_low RGB10A2 #else RGBA16F #end);
 		textures.hdr = allocTarget("hdrOutput", true, 1, #if MRT_low RGB10A2 #else RGBA16F #end);
 		textures.ldr = allocTarget("ldrOutput");
 		textures.ldr = allocTarget("ldrOutput");
 	}
 	}
 
 
 	public function getPbrDepth() {
 	public function getPbrDepth() {
-		#if js
 		return textures.depth;
 		return textures.depth;
-		#else
-		return textures.albedo.depthBuffer;
-		#end
 	}
 	}
 
 
 	function initGlobals() {
 	function initGlobals() {
@@ -528,7 +516,7 @@ class Renderer extends h3d.scene.Renderer {
 	function drawPbrDecals( passName : String ) {
 	function drawPbrDecals( passName : String ) {
 		var passes = get(passName);
 		var passes = get(passName);
 		if( passes.isEmpty() ) return;
 		if( passes.isEmpty() ) return;
-		ctx.engine.pushTargets([textures.albedo,textures.normal,textures.pbr], ReadOnly);
+		ctx.engine.pushTargets([textures.albedo,textures.normal,textures.pbr]);
 		renderPass(decalsOutput, passes);
 		renderPass(decalsOutput, passes);
 		ctx.engine.popTarget();
 		ctx.engine.popTarget();
 	}
 	}
@@ -536,32 +524,26 @@ class Renderer extends h3d.scene.Renderer {
 	function drawEmissiveDecals( passName : String ) {
 	function drawEmissiveDecals( passName : String ) {
 		var passes = get(passName);
 		var passes = get(passName);
 		if( passes.isEmpty() ) return;
 		if( passes.isEmpty() ) return;
-		ctx.engine.pushTargets([textures.albedo,textures.normal,textures.pbr#if !MRT_low ,textures.other #end], ReadOnly);
+		ctx.engine.pushTargets([textures.albedo,textures.normal,textures.pbr#if !MRT_low ,textures.other #end]);
 		renderPass(emissiveDecalsOutput, passes);
 		renderPass(emissiveDecalsOutput, passes);
 		ctx.engine.popTarget();
 		ctx.engine.popTarget();
 	}
 	}
 
 
 	function getPbrRenderTargets( depth : Bool ) {
 	function getPbrRenderTargets( depth : Bool ) {
-		#if js
 		if ( depth )
 		if ( depth )
-			return [textures.albedo, textures.normal, textures.pbr #if !MRT_low , textures.other #end #if js , getPbrDepth() #end];
-		#end
+			return [textures.albedo, textures.normal, textures.pbr #if !MRT_low , textures.other #end, getPbrDepth()];
 		return [textures.albedo, textures.normal, textures.pbr #if !MRT_low , textures.other #end];
 		return [textures.albedo, textures.normal, textures.pbr #if !MRT_low , textures.other #end];
 	}
 	}
 
 
 	override function render() {
 	override function render() {
 		beginPbr();
 		beginPbr();
-		#if js
 		setTarget(textures.depth);
 		setTarget(textures.depth);
 		ctx.engine.clearF(new h3d.Vector(1));
 		ctx.engine.clearF(new h3d.Vector(1));
-		#end
 
 
 		setTargets(getPbrRenderTargets(false));
 		setTargets(getPbrRenderTargets(false));
 		clear(0, 1, 0);
 		clear(0, 1, 0);
 
 
-		#if js
 		setTargets(getPbrRenderTargets(true));
 		setTargets(getPbrRenderTargets(true));
-		#end
 
 
 		begin(MainDraw);
 		begin(MainDraw);
 		renderPass(output, get("terrain"));
 		renderPass(output, get("terrain"));
@@ -576,18 +558,14 @@ class Renderer extends h3d.scene.Renderer {
 		drawEmissiveDecals("emissiveDecal");
 		drawEmissiveDecals("emissiveDecal");
 		end();
 		end();
 
 
-		setTarget(textures.hdr, ReadOnly);
+		setTarget(textures.hdr);
 		clear(0);
 		clear(0);
 		lighting();
 		lighting();
 
 
-		setTarget(textures.hdr);
 		begin(Forward);
 		begin(Forward);
-		setTarget(textures.hdr);
 		var ls = hxd.impl.Api.downcast(getLightSystem(), h3d.scene.pbr.LightSystem);
 		var ls = hxd.impl.Api.downcast(getLightSystem(), h3d.scene.pbr.LightSystem);
 		ls.forwardMode = true;
 		ls.forwardMode = true;
-		#if js
 		setTargets([textures.hdr, getPbrDepth()]);
 		setTargets([textures.hdr, getPbrDepth()]);
-		#end
 		renderPass(colorDepthOutput, get("forward"));
 		renderPass(colorDepthOutput, get("forward"));
 		setTarget(textures.hdr);
 		setTarget(textures.hdr);
 		renderPass(defaultPass, get("forwardAlpha"), backToFront);
 		renderPass(defaultPass, get("forwardAlpha"), backToFront);
@@ -602,27 +580,19 @@ class Renderer extends h3d.scene.Renderer {
 			return;
 			return;
 		}
 		}
 
 
-		setTarget(textures.hdr, ReadOnly);
 		begin(BeforeTonemapping);
 		begin(BeforeTonemapping);
-		setTarget(textures.hdr, ReadOnly);
 		draw("beforeTonemappingDecal");
 		draw("beforeTonemappingDecal");
-		setTarget(textures.hdr);
 		draw("beforeTonemapping");
 		draw("beforeTonemapping");
-		setTarget(textures.hdr, ReadOnly);
 		end();
 		end();
 
 
-		setTarget(textures.ldr, ReadOnly);
+		setTarget(textures.ldr);
 		tonemap.render();
 		tonemap.render();
 
 
 		begin(AfterTonemapping);
 		begin(AfterTonemapping);
-		setTarget(textures.ldr, ReadOnly);
 		draw("afterTonemappingDecal");
 		draw("afterTonemappingDecal");
-		setTarget(textures.ldr);
 		draw("afterTonemapping");
 		draw("afterTonemapping");
-		setTarget(textures.ldr, ReadOnly);
 		end();
 		end();
 
 
-		setTarget(textures.ldr);
 		begin(Overlay);
 		begin(Overlay);
 		draw("overlay");
 		draw("overlay");
 		end();
 		end();