Browse Source

[RENDERER][MRT] Move depth into its own R32F RT. Added Emissive Decals.

clandrin 4 năm trước cách đây
mục cha
commit
ede2aa8eeb

+ 4 - 1
h3d/mat/PbrMaterial.hx

@@ -245,7 +245,10 @@ class PbrMaterial extends Material {
 		case Overlay:
 			mainPass.setPassName("overlay");
 		case Decal:
-			mainPass.setPassName("decal");
+			if (props.emissive != 0)
+				mainPass.setPassName("emissiveDecal");
+			else
+				mainPass.setPassName("decal");
 			var vd = mainPass.getShader(h3d.shader.VolumeDecal);
 			if( vd == null ) {
 				vd = new h3d.shader.VolumeDecal(1,1);

+ 24 - 4
h3d/scene/pbr/Renderer.hx

@@ -72,6 +72,7 @@ class Renderer extends h3d.scene.Renderer {
 		normal : (null:h3d.mat.Texture),
 		pbr : (null:h3d.mat.Texture),
 		other : (null:h3d.mat.Texture),
+		depth : (null:h3d.mat.Texture),
 		hdr : (null:h3d.mat.Texture),
 		ldr : (null:h3d.mat.Texture),
 	};
@@ -88,13 +89,20 @@ class Renderer extends h3d.scene.Renderer {
 		Value("output.color"),
 		Vec4([Value("output.normal",3),ALPHA]),
 		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.occlusion"), ALPHA]),
-		Vec4([Value("output.emissive"),Value("output.depth"),Const(0), ALPHA /* ? */])
+		Vec4([Value("output.emissive"), Const(0), Const(0), ALPHA]),
+		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)]),
 		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.occlusion"), Value("output.pbrStrength")])
 	]);
+	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)]),
+		Vec4([Value("output.metalness"), Value("output.roughness"), Value("output.occlusion"), Value("output.pbrStrength")]),
+		Vec4([Value("output.emissive"), Const(0), Const(0), Value("output.emissiveStrength")])
+	]);
 
 	public function new(?env) {
 		super();
@@ -110,6 +118,7 @@ class Renderer extends h3d.scene.Renderer {
 		allPasses.push(output);
 		allPasses.push(defaultPass);
 		allPasses.push(decalsOutput);
+		allPasses.push(emissiveDecalsOutput);
 		allPasses.push(new h3d.pass.Shadows(null));
 		refreshProps();
 	}
@@ -327,14 +336,15 @@ class Renderer extends h3d.scene.Renderer {
 		textures.albedo = allocTarget("albedo", true, 1.);
 		textures.normal = allocTarget("normal", true, 1., RGBA16F);
 		textures.pbr = allocTarget("pbr", true, 1.);
-		textures.other = allocTarget("other", true, 1., RGBA32F);
+		textures.other = allocTarget("other", true, 1.);
+		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 : textures.other, channel : hxsl.Channel.G });
+		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);
@@ -360,6 +370,7 @@ class Renderer extends h3d.scene.Renderer {
 		pbrProps.albedoTex = textures.albedo;
 		pbrProps.normalTex = textures.normal;
 		pbrProps.pbrTex = textures.pbr;
+		pbrProps.depthTex = textures.depth;
 		pbrProps.otherTex = textures.other;
 		pbrProps.cameraInverseViewProj = ctx.camera.getInverseViewProj();
 		pbrProps.occlusionPower = props.occlusion * props.occlusion;
@@ -441,10 +452,18 @@ class Renderer extends h3d.scene.Renderer {
 		ctx.engine.popTarget();
 	}
 
+	function drawEmissiveDecals( passName : String ) {
+		var passes = get(passName);
+		if( passes.isEmpty() ) return;
+		ctx.engine.pushTargets([textures.albedo,textures.normal,textures.pbr,textures.other]);
+		renderPass(emissiveDecalsOutput, passes);
+		ctx.engine.popTarget();
+	}
+
 	override function render() {
 		beginPbr();
 
-		setTargets([textures.albedo,textures.normal,textures.pbr,textures.other]);
+		setTargets([textures.albedo,textures.normal,textures.pbr,textures.other,textures.depth]);
 		clear(0, 1, 0);
 
 		begin(MainDraw);
@@ -457,6 +476,7 @@ class Renderer extends h3d.scene.Renderer {
 
 		begin(Decals);
 		drawPbrDecals("decal");
+		drawEmissiveDecals("emissiveDecal");
 		end();
 
 		setTarget(textures.hdr);

+ 2 - 1
h3d/shader/pbr/PropsImport.hx

@@ -6,6 +6,7 @@ class PropsImport extends hxsl.Shader {
 		@param var albedoTex : Sampler2D;
 		@param var normalTex : Sampler2D;
 		@param var pbrTex : Sampler2D;
+		@param var depthTex : Sampler2D;
 		@param var otherTex : Sampler2D;
 		@const var isScreen : Bool = true;
 
@@ -37,7 +38,7 @@ class PropsImport extends hxsl.Shader {
 
 			var other = otherTex.get(uv);
 			emissive = other.r;
-			depth = other.g;
+			depth = depthTex.get(uv).r;
 
 			pbrSpecularColor = mix(vec3(0.04),albedo,metalness);
 

+ 5 - 1
h3d/shader/pbr/StrengthValues.hx

@@ -8,26 +8,30 @@ class StrengthValues extends hxsl.Shader {
 			albedoStrength : Float,
 			normalStrength : Float,
 			pbrStrength : Float,
+			emissiveStrength : Float
 		};
 
 		var pixelColor : Vec4;
 		@param var albedoStrength : Float;
 		@param var normalStrength : Float;
 		@param var pbrStrength : Float;
+		@param var emissiveStrength : Float;
 
 		function fragment() {
 			output.albedoStrength = albedoStrength * pixelColor.a;
 			output.normalStrength = normalStrength * pixelColor.a;
 			output.pbrStrength = pbrStrength * pixelColor.a;
+			output.emissiveStrength = emissiveStrength * pixelColor.a;
 		}
 
 	};
 
-	public function new(albedoStrength=1.,normalStrength=1.,pbrStrength=1.) {
+	public function new(albedoStrength=1.,normalStrength=1.,pbrStrength=1., emissiveStrength=1.) {
 		super();
 		this.albedoStrength = albedoStrength;
 		this.normalStrength = normalStrength;
 		this.pbrStrength = pbrStrength;
+		this.emissiveStrength = emissiveStrength;
 	}
 
 }

+ 3 - 0
h3d/shader/pbr/VolumeDecal.hx

@@ -94,6 +94,7 @@ class DecalPBR extends hxsl.Shader {
 			albedoStrength : Float,
 			normalStrength : Float,
 			pbrStrength : Float,
+			emissiveStrength : Float,
 		};
 
 		@const var CENTERED : Bool;
@@ -103,6 +104,7 @@ class DecalPBR extends hxsl.Shader {
 		@param var albedoStrength : Float;
 		@param var normalStrength : Float;
 		@param var pbrStrength : Float;
+		@param var emissiveStrength : Float;
 
 		@global var depthMap : Channel;
 
@@ -192,6 +194,7 @@ class DecalPBR extends hxsl.Shader {
 			output.albedoStrength = albedoSt * alpha * fadeFactor;
 			output.normalStrength = normalSt * alpha * fadeFactor;
 			output.pbrStrength = pbrStrength * alpha * fadeFactor;
+			output.emissiveStrength = emissiveStrength * alpha * fadeFactor;
 		}
 	};