Просмотр исходного кода

Environment hdrMax + preview diffuse/specular

Nicolas Cannasse 4 лет назад
Родитель
Сommit
0a463928ff
2 измененных файлов с 30 добавлено и 39 удалено
  1. 30 25
      hrt/prefab/l3d/Environment.hx
  2. 0 14
      hrt/prefab/vlm/LightProbe.hx

+ 30 - 25
hrt/prefab/l3d/Environment.hx

@@ -9,8 +9,7 @@ class Environment extends Object3D {
 	var env : h3d.scene.pbr.Environment;
 
 	public var power : Float = 1.0;
-	public var threshold : Float = 1.0;
-	public var scale : Float = 1.0;
+	public var hdrMax : Float = 10.0;
 	public var rotation : Float = 0.0;
 	public var sampleBits : Int = 12;
 	public var diffSize : Int = 64;
@@ -25,8 +24,7 @@ class Environment extends Object3D {
 	override function load( obj : Dynamic ) {
 		super.load(obj);
 	 	power = obj.power != null ? obj.power : 1.0;
-		threshold = obj.threshold != null ? obj.threshold : 1.0;
-		scale = obj.scale != null ? obj.scale : 1.0;
+		hdrMax = obj.hdrMax != null ? obj.hdrMax : 10.0;
 		rotation = obj.rotation != null ? obj.rotation : 0.0;
 		sampleBits = obj.sampleBits != null ? obj.sampleBits : 12;
 		diffSize = obj.diffSize != null ? obj.diffSize : 64;
@@ -39,28 +37,22 @@ class Environment extends Object3D {
 	override function save() {
 		var obj : Dynamic = super.save();
 		obj.power = power;
-		obj.threshold = threshold;
-		obj.scale = scale;
 		obj.rotation = rotation;
 		obj.sampleBits = sampleBits;
 		obj.diffSize = diffSize;
 		obj.specSize = specSize;
 		obj.ignoredSpecLevels = ignoredSpecLevels;
 		obj.sourceMapPath = sourceMapPath;
+		obj.hdrMax = hdrMax;
 		if( configName != null ) obj.configName = configName;
 		return obj;
 	}
 
 	function loadFromBinary() {
-		var path = new haxe.io.Path(sourceMapPath);
 		try {
 			env.dispose();
-			if( configName != null )
-				path.file += "-" + configName;
-			path.ext = "envd.dds";
-			env.diffuse = hxd.res.Loader.currentInstance.load(path.toString()).toImage().toTexture();
-			path.ext = "envs.dds";
-			env.specular = hxd.res.Loader.currentInstance.load(path.toString()).toImage().toTexture();
+			env.diffuse = hxd.res.Loader.currentInstance.load(getBinaryPath(true)).toImage().toTexture();
+			env.specular = hxd.res.Loader.currentInstance.load(getBinaryPath(false)).toImage().toTexture();
 			env.specular.mipMap = Linear;
 			env.specLevels = env.getMipLevels() - ignoredSpecLevels;
 			return true;
@@ -69,19 +61,22 @@ class Environment extends Object3D {
 		}
 	}
 
+	function getBinaryPath( diffuse : Bool ) {
+		var path = new haxe.io.Path(sourceMapPath);
+		if( configName != null )
+			path.file += "-" + configName;
+		path.ext = diffuse ? "envd.dds" : "envs.dds";
+		return path.toString();
+	}
+
 	function saveToBinary() {
 		#if (hl || hxnodejs)
 		var fs = cast(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
 		if( fs == null ) return;
-		var path = new haxe.io.Path(fs.baseDir+sourceMapPath);
-		if( configName != null )
-			path.file += "-" + configName;
 		var diffuse = hxd.Pixels.toDDS([for( i in 0...6 ) env.diffuse.capturePixels(i)],true);
-		path.ext = "envd.dds";
-		sys.io.File.saveBytes(path.toString(), diffuse);
+		sys.io.File.saveBytes(fs.baseDir + getBinaryPath(true), diffuse);
 		var specular = hxd.Pixels.toDDS([for( i in 0...6 ) for( mip in 0...env.getMipLevels() ) env.specular.capturePixels(i,mip)],true);
-		path.ext = "envs.dds";
-		sys.io.File.saveBytes(path.toString(), specular);
+		sys.io.File.saveBytes(fs.baseDir + getBinaryPath(false), specular);
 		#end
 	}
 
@@ -127,8 +122,7 @@ class Environment extends Object3D {
 		env.diffSize = diffSize;
 		env.sampleBits = sampleBits;
 		env.ignoredSpecLevels = ignoredSpecLevels;
-		env.threshold = threshold;
-		env.scale = scale;
+		env.hdrMax = hdrMax;
 
 		env.rot = rotation;
 		env.power = power;
@@ -170,7 +164,7 @@ class Environment extends Object3D {
 				<dl>
 					<dt>SkyBox</dt><dd><input type="texturepath" field="sourceMapPath"/></dd>
 					<dt>Rotation</dt><dd><input type="range" min="0" max="360" field="rotation"/></dd>
-					<dt>Power</dt><dd><input type="range" min="0" max="10" field="power"/></dd>
+					<dt>Power</dt><dd><input type="range" min="0" max="2" field="power"/></dd>
 				</dl>
 			</div>
 			<div class="group closed" name="Generation">
@@ -179,10 +173,13 @@ class Environment extends Object3D {
 					<dt>Specular</dt><dd><input type="range" min="1" max="2048" step="1" field="specSize"/></dd>
 					<dt>Sample Count</dt><dd><input type="range" min="1" max="12" step="1" field="sampleBits"/></dd>
 					<dt>Ignored Spec Levels</dt><dd><input type="range" min="0" max="3" step="1" field="ignoredSpecLevels"/></dd>
-					<dt>HDR Threshold</dt><dd><input type="range" min="0" max="1" step="0.1" field="threshold"/></dd>
-					<dt>HDR Scale</dt><dd><input type="range" min="0" max="10" field="scale"/></dd>
+					<dt>HDR Max</dt><dd><input type="range" min="0" max="100" field="hdrMax"/></dd>
 					<dt>Config Name</dt><dd><input type="text" field="configName"/></dd>
 					<dt>&nbsp;</dt><dd><input type="button" class="compute" value="Compute"/></dd>
+					<dt>View</dt><dd>
+						<input type="button" style="width:90px" class="showDif" value="Diffuse"/>
+						<input type="button" style="width:90px" class="showSpec" value="Specular"/>
+					</dd>
 				</dl>
 			</div>
 		');
@@ -196,6 +193,14 @@ class Environment extends Object3D {
 			ctx.onChange(this,"force");
 		});
 
+		props.find(".showDif").click(function(_) {
+			ctx.ide.openFile(getBinaryPath(true));
+		});
+
+		props.find(".showSpec").click(function(_) {
+			ctx.ide.openFile(getBinaryPath(false));
+		});
+
 		ctx.properties.add(props, this, function(pname) {
 			ctx.onChange(this, pname);
 		});

+ 0 - 14
hrt/prefab/vlm/LightProbe.hx

@@ -182,8 +182,6 @@ class LightProbe extends Object3D {
 
 	// Texture Mode
 	public var texturePath : String = null;
-	public var threshold : Float = 1.0;
-	public var scale : Float = 1.0;
 	public var rotation : Float = 0.0;
 
 	// Capture Mode
@@ -234,8 +232,6 @@ class LightProbe extends Object3D {
 		if( obj.fadeDist != null ) fadeDist = obj.fadeDist;
 		if( obj.fadeMode != null ) fadeMode = obj.fadeMode;
 		if( obj.power != null ) power = obj.power;
-		if( obj.threshold != null ) threshold = obj.threshold;
-		if( obj.scale != null ) scale = obj.scale;
 		if( obj.rotation != null ) rotation = obj.rotation;
 		if( obj.sampleBits != null ) sampleBits = obj.sampleBits;
 		if( obj.diffSize != null ) diffSize = obj.diffSize;
@@ -254,8 +250,6 @@ class LightProbe extends Object3D {
 		o.fadeDist = fadeDist;
 		o.fadeMode = fadeMode;
 		o.power = power;
-		o.threshold = threshold;
-		o.scale = scale;
 		o.rotation = rotation;
 		o.sampleBits = sampleBits;
 		o.diffSize = diffSize;
@@ -330,8 +324,6 @@ class LightProbe extends Object3D {
 				}
 				if( lpo.env != null ) {
 					lpo.env.power = power;
-					lpo.env.threshold = threshold;
-					lpo.env.scale = scale;
 					lpo.env.rot = hxd.Math.degToRad(rotation);
 					lpo.env.sampleBits = sampleBits;
 					lpo.env.ignoredSpecLevels = ignoredSpecLevels;
@@ -466,8 +458,6 @@ class LightProbe extends Object3D {
 		bytes.setInt32(curPos, env.diffSize); 			curPos += 4;
 		bytes.setInt32(curPos, env.specSize); 			curPos += 4;
 		bytes.setInt32(curPos, env.ignoredSpecLevels); 	curPos += 4;
-		bytes.setDouble(curPos, env.threshold); 		curPos += 8;
-		bytes.setDouble(curPos, env.scale);			 	curPos += 8;
 
 		for( p in diffusePixels ) {
 			bytes.blit(curPos, p.bytes, 0, p.bytes.length);
@@ -490,8 +480,6 @@ class LightProbe extends Object3D {
 		env.diffSize = bytes.getInt32(curPos); 			curPos += 4;
 		env.specSize = bytes.getInt32(curPos); 			curPos += 4;
 		env.ignoredSpecLevels = bytes.getInt32(curPos); curPos += 4;
-		env.threshold = bytes.getDouble(curPos); 		curPos += 8;
-		env.scale = bytes.getDouble(curPos); 			curPos += 8;
 
 		env.createTextures();
 
@@ -680,8 +668,6 @@ class LightProbe extends Object3D {
 					diffSize = lpo.env.diffSize;
 					specSize = lpo.env.specSize;
 					ignoredSpecLevels = lpo.env.ignoredSpecLevels;
-					threshold = lpo.env.threshold;
-					scale = lpo.env.scale;
 
 					// Save the import
 					ctx.rootContext.shared.savePrefabDat("probe", "bake", this.name, b);