Ver Fonte

MRT low using RGBA8 instead of RGBA32F

clementlandrin há 2 anos atrás
pai
commit
7d32b0071b
2 ficheiros alterados com 36 adições e 37 exclusões
  1. 22 32
      h3d/scene/pbr/Renderer.hx
  2. 14 5
      h3d/shader/pbr/PropsImport.hx

+ 22 - 32
h3d/scene/pbr/Renderer.hx

@@ -73,10 +73,10 @@ class Renderer extends h3d.scene.Renderer {
 		albedo : (null:h3d.mat.Texture),
 		normal : (null:h3d.mat.Texture),
 		pbr : (null:h3d.mat.Texture),
-		other : (null:h3d.mat.Texture),
 		#if !MRT_low
-		depth : (null:h3d.mat.Texture),
+		other : (null:h3d.mat.Texture),
 		#end
+		depth : (null:h3d.mat.Texture),
 		hdr : (null:h3d.mat.Texture),
 		ldr : (null:h3d.mat.Texture),
 	};
@@ -92,34 +92,36 @@ class Renderer extends h3d.scene.Renderer {
 	var output = new h3d.pass.Output("default",[
 		Value("output.color"),
 		Vec4([Value("output.normal",3),ALPHA]),
-		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.occlusion"), ALPHA]),
 		#if !MRT_low
+		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.depth"), Const(0), Const(0), ALPHA])
 		#else
-		Vec4([Value("output.emissive"),Value("output.depth"),Const(0), ALPHA /* ? */])
+		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.emissive"), ALPHA]),
 		#end
+		Vec4([Value("output.depth"),Const(0), Const(0), ALPHA /* ? */])
 	]);
 	var decalsOutput = new h3d.pass.Output("decals",[
 		Vec4([Swiz(Value("output.color"),[X,Y,Z]), Value("output.albedoStrength",1)]),
 		Vec4([Value("output.normal",3), Value("output.normalStrength",1)]),
+		#if !MRT_low
 		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.occlusion"), Value("output.pbrStrength")])
+		#else
+		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.emissive"), Value("output.pbrStrength")])
+		#end
 	]);
-	#if !MRT_low
 	var emissiveDecalsOutput = new h3d.pass.Output("emissiveDecal",[
 		Vec4([Swiz(Value("output.color"),[X,Y,Z]), Value("output.albedoStrength",1)]),
 		Vec4([Value("output.normal",3), Value("output.normalStrength",1)]),
+		#if !MRT_low
 		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.occlusion"), Value("output.pbrStrength")]),
 		Vec4([Value("output.emissive"), Value("output.custom1"), Value("output.custom2"), Value("output.emissiveStrength")])
+		#else
+		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.emissive"), Value("output.pbrStrength")])
+		#end
 	]);
-	#end
 	var colorDepthOutput = new h3d.pass.Output("colorDepth",[
 		Value("output.color"),
-		#if !MRT_low
 		Vec4([Value("output.depth"),Const(0),Const(0),h3d.scene.pbr.Renderer.ALPHA])
-		#else
-		Vec4([Const(0),Value("output.depth"),Const(0), Const(0)])
-		#end
 	]);
 
 	public function new(?env) {
@@ -137,9 +139,7 @@ class Renderer extends h3d.scene.Renderer {
 		allPasses.push(defaultPass);
 		allPasses.push(decalsOutput);
 		allPasses.push(colorDepthOutput);
-		#if !MRT_low
 		allPasses.push(emissiveDecalsOutput);
-		#end
 		allPasses.push(new h3d.pass.Shadows(null));
 		refreshProps();
 	}
@@ -166,7 +166,7 @@ class Renderer extends h3d.scene.Renderer {
 			return defaultPass;
 		case "default", "alpha", "additive":
 			return output;
-		case "decal" #if MRT_low, "emissiveDecal" #end:
+		case "decal" #if MRT_low , "emissiveDecal" #end:
 			return decalsOutput;
 		}
 		return super.getPassByName(name);
@@ -393,17 +393,15 @@ class Renderer extends h3d.scene.Renderer {
 		textures.pbr = allocTarget("pbr", true, 1.);
 		#if !MRT_low
 		textures.other = allocTarget("other", true, 1.);
-		textures.depth = allocTarget("depth", true, 1., R32F);
-		#else
-		textures.other = allocTarget("other", true, 1., RGBA32F);
 		#end
+		textures.depth = allocTarget("depth", true, 1., R32F);
 		textures.hdr = allocTarget("hdrOutput", true, 1, RGBA16F);
 		textures.ldr = allocTarget("ldrOutput");
 	}
 
 	function initGlobals() {
 		ctx.setGlobal("albedoMap", { texture : textures.albedo, channel : hxsl.Channel.R });
-		ctx.setGlobal("depthMap", { texture : #if !MRT_low textures.depth #else textures.other #end, channel : #if !MRT_low hxsl.Channel.R #else hxsl.Channel.G #end });
+		ctx.setGlobal("depthMap", { texture : textures.depth, channel : hxsl.Channel.R });
 		ctx.setGlobal("normalMap", { texture : textures.normal, channel : hxsl.Channel.R });
 		ctx.setGlobal("occlusionMap", { texture : textures.pbr, channel : hxsl.Channel.B });
 		ctx.setGlobal("hdrMap", textures.hdr);
@@ -428,10 +426,10 @@ class Renderer extends h3d.scene.Renderer {
 		pbrProps.albedoTex = textures.albedo;
 		pbrProps.normalTex = textures.normal;
 		pbrProps.pbrTex = textures.pbr;
-		#if !MRT_low
 		pbrProps.depthTex = textures.depth;
-		#end
+		#if !MRT_low
 		pbrProps.otherTex = textures.other;
+		#end
 		pbrProps.cameraInverseViewProj = ctx.camera.getInverseViewProj();
 		pbrProps.occlusionPower = props.occlusion * props.occlusion;
 
@@ -513,30 +511,22 @@ class Renderer extends h3d.scene.Renderer {
 	}
 
 	function drawEmissiveDecals( passName : String ) {
-		#if !MRT_low
 		var passes = get(passName);
 		if( passes.isEmpty() ) return;
-		ctx.engine.pushTargets([textures.albedo,textures.normal,textures.pbr,textures.other]);
+		ctx.engine.pushTargets([textures.albedo,textures.normal,textures.pbr#if !MRT_low ,textures.other #end]);
 		renderPass(emissiveDecalsOutput, passes);
 		ctx.engine.popTarget();
-		#else
-		drawPbrDecals(passName);
-		#end
 	}
 
 	override function render() {
 		beginPbr();
-		#if !MRT_low
 		setTarget(textures.depth);
 		ctx.engine.clearF(new h3d.Vector(1));
-		#end
 
-		setTargets([textures.albedo,textures.normal,textures.pbr,textures.other]);
+		setTargets([textures.albedo,textures.normal,textures.pbr#if !MRT_low ,textures.other #end]);
 		clear(0, 1, 0);
 
-		#if !MRT_low
-		setTargets([textures.albedo,textures.normal,textures.pbr,textures.other,textures.depth]);
-		#end
+		setTargets([textures.albedo,textures.normal,textures.pbr#if !MRT_low ,textures.other #end,textures.depth]);
 
 		begin(MainDraw);
 		renderPass(output, get("terrain"));
@@ -558,7 +548,7 @@ class Renderer extends h3d.scene.Renderer {
 		begin(Forward);
 		var ls = hxd.impl.Api.downcast(getLightSystem(), h3d.scene.pbr.LightSystem);
 		ls.forwardMode = true;
-		setTargets([textures.hdr, #if !MRT_low textures.depth #else textures.other #end]);
+		setTargets([textures.hdr, textures.depth]);
 		renderPass(colorDepthOutput, get("forward"));
 		setTarget(textures.hdr);
 		renderPass(defaultPass, get("forwardAlpha"), backToFront);

+ 14 - 5
h3d/shader/pbr/PropsImport.hx

@@ -6,10 +6,10 @@ class PropsImport extends hxsl.Shader {
 		@param var albedoTex : Sampler2D;
 		@param var normalTex : Sampler2D;
 		@param var pbrTex : Sampler2D;
-		#if !MRT_low
 		@param var depthTex : Sampler2D;
-		#end
+		#if !MRT_low
 		@param var otherTex : Sampler2D;
+		#end
 		@const var isScreen : Bool = true;
 
 		@param var cameraInverseViewProj : Mat4;
@@ -38,13 +38,22 @@ class PropsImport extends hxsl.Shader {
 			var pbr = pbrTex.get(uv);
 			metalness = pbr.r;
 			roughness = pbr.g;
+			#if !MRT_low
 			occlusion = mix(1, pbr.b, occlusionPower);
 
 			var other = otherTex.get(uv);
 			emissive = other.r;
-			custom1 = #if !MRT_low other.g #else 0.0 #end;
-			custom2 = #if !MRT_low other.b #else 0.0 #end;
-			depth = #if !MRT_low depthTex.get(uv).r #else other.g #end;
+			custom1 = other.g;
+			custom2 = other.b;
+			#else
+			occlusion = 1.0;
+
+			emissive = pbr.b;
+			custom1 = 0.0;
+			custom2 = 0.0;
+			#end
+			
+			depth = depthTex.get(uv).r;
 
 			pbrSpecularColor = mix(vec3(0.04),albedo,metalness);