Commit 0e3ecfdc authored by BRUNEAU Julien's avatar BRUNEAU Julien
Browse files

+ Increase precision of Filters

+ Add a few parameters to the depth filter
+ Fix depth shader: use distance from camera point and not camera viewport plane
parent 0930c53c
......@@ -108,6 +108,7 @@ public class FilterDepth : Filter
{
public float maxDist = 50;
public float minDist = 0;
public float exponent = 1;
public FilterDepth(Camera mainCam, float maxRepresentedDist=50f)
{
......@@ -125,8 +126,9 @@ public class FilterDepth : Filter
public override void initParams()
{
maxDist = ConfigReader.imgDepth.MaxDepth;
minDist = ConfigReader.imgDepth.MinDepth;
maxDist = ConfigReader.imgDepth.maxDepth;
minDist = ConfigReader.imgDepth.minDepth;
exponent = ConfigReader.imgDepth.exponent;
}
public override void OnSceneChange(Renderer r, ref MaterialPropertyBlock mpb)
......@@ -135,6 +137,7 @@ public class FilterDepth : Filter
//var tag = r.gameObject.tag;
mpb.SetFloat("_maxDist", maxDist);
mpb.SetFloat("_minDist", minDist);
mpb.SetFloat("_exponent", exponent);
}
}
......
......@@ -28,7 +28,7 @@
fixed4 _CategoryColor;
fixed4 frag(v2f i) : SV_Target {
float4 frag(v2f i) : SV_Target {
return _CategoryColor;
}
ENDCG
......
......@@ -15,6 +15,7 @@
struct v2f {
float4 pos : SV_POSITION;
float nz : TEXCOORD0;
float4 worldPos : TEXCOORD2;
UNITY_VERTEX_OUTPUT_STEREO
};
......@@ -24,20 +25,23 @@
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.pos = UnityObjectToClipPos(v.vertex);
o.nz = -(UnityObjectToViewPos(v.vertex).z);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
return o;
}
uniform float _maxDist;
uniform float _minDist;
uniform float _exponent;
fixed4 frag(v2f i) : SV_Target {
float depth = i.nz - _minDist;
float4 frag(v2f i) : SV_Target {
float depth = distance(i.worldPos, _WorldSpaceCameraPos) - _minDist;
if (depth < 0)
depth = 0;
float ratio = _maxDist - _minDist;
if (ratio <= 0)
ratio = 1;
depth = depth / ratio;
depth = pow(depth / ratio, _exponent);
return float4(depth, depth, depth, 1);
}
......
......@@ -28,7 +28,7 @@
return o;
}
fixed4 frag(v2f i) : SV_Target {
float4 frag(v2f i) : SV_Target {
float3 c = i.nz * 0.5 + 0.5;
return fixed4(c, 1);
}
......
......@@ -84,7 +84,7 @@
// return float4(rgb, 1);
//}
fixed4 frag(v2f i) : SV_Target
float4 frag(v2f i) : SV_Target
{
float2 motion = tex2D(_CameraMotionVectorsTexture, i.uv).rg;
......
......@@ -28,7 +28,7 @@
fixed4 _ObjectColor;
fixed4 frag(v2f i) : SV_Target {
float4 frag(v2f i) : SV_Target {
return _ObjectColor;
}
ENDCG
......
......@@ -56,22 +56,22 @@ public class FiltersControl : MonoBehaviour
public void init()
{
// Image
saveImage = ConfigReader.imgOriginal.Record;
saveImage = ConfigReader.imgOriginal.record;
// Segmentation
saveIdSegmentation = ConfigReader.imgSegmentation.Record;
saveIdSegmentation = ConfigReader.imgSegmentation.record;
// Categories
saveLayerSegmentation = ConfigReader.imgCategories.Record;
saveLayerSegmentation = ConfigReader.imgCategories.record;
// Depth
saveDepth = ConfigReader.imgDepth.Record;
saveDepth = ConfigReader.imgDepth.record;
// Normals
saveNormals = ConfigReader.imgNormals.Record;
saveNormals = ConfigReader.imgNormals.record;
// Optical Flow
saveOpticalFlow = ConfigReader.imgOpticalFlow.Record;
saveOpticalFlow = ConfigReader.imgOpticalFlow.record;
foreach (Filter f in filters)
{
......@@ -86,10 +86,10 @@ public class FiltersControl : MonoBehaviour
void LateUpdate()
{
#if UNITY_EDITOR
if (DetectPotentialSceneChangeInEditor())
//#if UNITY_EDITOR
// if (DetectPotentialSceneChangeInEditor())
OnSceneChange();
#endif // UNITY_EDITOR
//#endif // UNITY_EDITOR
// @TODO: detect if camera properties actually changed
OnCameraChange();
......@@ -222,15 +222,14 @@ public class FiltersControl : MonoBehaviour
if (!System.IO.Directory.Exists(subPath))
System.IO.Directory.CreateDirectory(subPath);
Save(mainCam, Path.Combine(subPath, filenameWithoutExtension + filenameExtension), width, height, true, false);
Save(mainCam, Path.Combine(subPath, filenameWithoutExtension), width, height, true, false);
}
foreach (var f in filters)
{
// Perform a check to make sure that the capture pass should be saved
if (
(f.name == "Images" && saveImage)
|| (f.name == "Segmentation" && saveIdSegmentation)
(f.name == "Segmentation" && saveIdSegmentation)
|| (f.name == "Categories" && saveLayerSegmentation)
|| (f.name == "Depth" && saveDepth)
|| (f.name == "Normals" && saveNormals)
......@@ -241,7 +240,7 @@ public class FiltersControl : MonoBehaviour
if (!System.IO.Directory.Exists(subPath))
System.IO.Directory.CreateDirectory(subPath);
Save(f.camera, Path.Combine(subPath, filenameWithoutExtension + filenameExtension), width, height, f.supportsAntialiasing, f.needsRescale);
Save(f.camera, Path.Combine(subPath, filenameWithoutExtension), width, height, f.supportsAntialiasing, f.needsRescale);
}
}
}
......@@ -250,15 +249,15 @@ public class FiltersControl : MonoBehaviour
{
var mainCamera = GetComponent<Camera>();
var depth = 24;
var format = RenderTextureFormat.Default;
var readWrite = RenderTextureReadWrite.Default;
var format = RenderTextureFormat.ARGBFloat;
var readWrite = RenderTextureReadWrite.Linear;
var antiAliasing = (supportsAntialiasing) ? Mathf.Max(1, QualitySettings.antiAliasing) : 1;
var finalRT =
RenderTexture.GetTemporary(width, height, depth, format, readWrite, antiAliasing);
var renderRT = (!needsRescale) ? finalRT :
RenderTexture.GetTemporary(mainCamera.pixelWidth, mainCamera.pixelHeight, depth, format, readWrite, antiAliasing);
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
var tex = new Texture2D(width, height, TextureFormat.RGBAFloat, true);
var prevActiveRT = RenderTexture.active;
......@@ -284,6 +283,9 @@ public class FiltersControl : MonoBehaviour
// encode texture into PNG
var bytes = tex.EncodeToPNG();
filename = filename + ".png";
//var bytes = tex.EncodeToEXR(Texture2D.EXRFlags.OutputAsFloat);
//filename = filename + ".exr";
File.WriteAllBytes(filename, bytes);
// restore state and cleanup
......
......@@ -172,13 +172,13 @@ public class LoadEnv : MonoBehaviour
private void InitDeepRecorders()
{
GameObject DeepRecorders = GameObject.FindGameObjectWithTag("DeepRecorders");
if (ConfigReader.bboxeBody.Record)
if (ConfigReader.bboxeBody.record)
{
DeepRecorders.AddComponent<BodyBoundingBoxRecorder>();
DeepRecorders.GetComponent<BodyBoundingBoxRecorder>().Init(ConfigReader.recordingSaveDir);
}
if (ConfigReader.bboxeHead.Record)
if (ConfigReader.bboxeHead.record)
{
DeepRecorders.AddComponent<HeadBoundingBoxRecorder>();
DeepRecorders.GetComponent<HeadBoundingBoxRecorder>().Init(ConfigReader.recordingSaveDir);
......
......@@ -460,51 +460,53 @@ public class ConfigRecording
public class DataImgOriginal
{
[XmlAttribute]
public bool Record = true;
public bool record = true;
}
public class DataImgSegmentation
{
[XmlAttribute]
public bool Record = false;
public bool record = false;
}
public class DataImgCategories
{
[XmlAttribute]
public bool Record = false;
public bool record = false;
}
public class DataImgDepth
{
[XmlAttribute]
public bool Record = false;
public bool record = false;
[XmlAttribute]
public float MinDepth=0;
public float minDepth=0;
[XmlAttribute]
public float MaxDepth=50;
public float maxDepth=50;
[XmlAttribute]
public float exponent = 1;
}
public class DataImgNormals
{
[XmlAttribute]
public bool Record = true;
public bool record = false;
}
public class DataImgOpticalFlow
{
[XmlAttribute]
public bool Record = false;
public bool record = false;
}
public class DataBodyBoundingBoxes
{
[XmlAttribute]
public bool Record = false;
public bool record = false;
}
public class DataHeadBoundingBoxes
{
[XmlAttribute]
public bool Record = false;
public bool record = false;
}
/// <summary>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment