Explorar o código

pbr decals support

ncannasse %!s(int64=7) %!d(string=hai) anos
pai
achega
4df5a7befe
Modificáronse 2 ficheiros con 60 adicións e 5 borrados
  1. 26 5
      h3d/mat/PbrMaterial.hx
  2. 34 0
      h3d/shader/pbr/StrengthValues.hx

+ 26 - 5
h3d/mat/PbrMaterial.hx

@@ -4,6 +4,7 @@ package h3d.mat;
 	var PBR = "PBR";
 	var Albedo = "Albedo";
 	var Overlay = "Overlay";
+	var Decal = "Decal";
 }
 
 @:enum abstract PbrBlend(String) {
@@ -55,6 +56,13 @@ class PbrMaterial extends Material {
 				culling : false,
 				alphaKill : true,
 			};
+		case "decal":
+			props = {
+				mode : Decal,
+				blend : Alpha,
+				shadows : false,
+				culling : true,
+			};
 		default:
 			props = {
 				mode : PBR,
@@ -86,6 +94,19 @@ class PbrMaterial extends Material {
 			mainPass.setPassName("albedo");
 		case Overlay:
 			mainPass.setPassName("overlay");
+		case Decal:
+			mainPass.setPassName("decal");
+			var vd = mainPass.getShader(h3d.shader.VolumeDecal);
+			if( vd == null ) {
+				vd = new h3d.shader.VolumeDecal(1,1);
+				vd.setPriority(-1);
+				mainPass.addShader(vd);
+			}
+			var sv = mainPass.getShader(h3d.shader.pbr.StrengthValues);
+			if( sv == null ) {
+				sv = new h3d.shader.pbr.StrengthValues();
+				mainPass.addShader(sv);
+			}
 		}
 		switch( props.blend ) {
 		case None:
@@ -112,13 +133,13 @@ class PbrMaterial extends Material {
 
 		// get values from specular texture
 		var emit = props.emissive == null ? 0 : props.emissive;
-		var spec = mainPass.getShader(h3d.shader.pbr.PropsTexture);
+		var tex = mainPass.getShader(h3d.shader.pbr.PropsTexture);
 		var def = mainPass.getShader(h3d.shader.pbr.PropsValues);
-		if( spec == null && def == null ) {
+		if( tex == null && def == null ) {
 			def = new h3d.shader.pbr.PropsValues();
 			mainPass.addShader(def);
 		}
-		if( spec != null ) spec.emissive = emit;
+		if( tex != null ) tex.emissive = emit;
 		if( def != null ) def.emissive = emit;
 	}
 
@@ -137,9 +158,9 @@ class PbrMaterial extends Material {
 		if( t != null ) {
 			if( spec == null ) {
 				spec = new h3d.shader.pbr.PropsTexture();
+				spec.emissive = emit;
 				mainPass.addShader(spec);
 			}
-			spec.emissive = emit;
 			spec.texture = t;
 			if( def != null )
 				mainPass.removeShader(def);
@@ -148,9 +169,9 @@ class PbrMaterial extends Material {
 			// default values (if no texture)
 			if( def == null ) {
 				def = new h3d.shader.pbr.PropsValues();
+				def.emissive = emit;
 				mainPass.addShader(def);
 			}
-			def.emissive = emit;
 		}
 		return t;
 	}

+ 34 - 0
h3d/shader/pbr/StrengthValues.hx

@@ -0,0 +1,34 @@
+package h3d.shader.pbr;
+
+class StrengthValues extends hxsl.Shader {
+
+	static var SRC = {
+
+		var output : {
+			albedoStrength : Float,
+			normalStrength : Float,
+			pbrStrength : Float,
+		};
+
+		var pixelColor : Vec4;
+		@param var albedoStrength : Float;
+		@param var normalStrength : Float;
+		@param var pbrStrength : Float;
+
+		function fragment() {
+			output.albedoStrength = albedoStrength * pixelColor.a;
+			output.normalStrength = normalStrength * pixelColor.a;
+			output.pbrStrength = pbrStrength * pixelColor.a;
+		}
+
+	};
+
+	public function new(albedoStrength=1.,normalStrength=1.,pbrStrength=1.) {
+		super();
+		this.albedoStrength = albedoStrength;
+		this.normalStrength = normalStrength;
+		this.pbrStrength = pbrStrength;
+	}
+
+}
+