This commit is contained in:
jasonm-unity 2017-01-31 12:14:21 -05:00
Родитель d389b024c5
Коммит 458bf32eea
10 изменённых файлов: 420 добавлений и 159 удалений

21
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,21 @@
release/
debug/
dependencies/
ProjectSettings/
.build/
*.dblite
excons.cache
*.csproj
*.sln
*.sdf
*.meta
*.opendb
*.vcxproj.user
.vs/
Library/
Temp/
_tmp/
_out/
ipch/

Двоичный файл не отображается.

Просмотреть файл

@ -1,5 +1,6 @@
using System;
using System.ComponentModel.Design;
using System.Linq.Expressions;
using Unity.Vfx.Cameras.Model;
using UnityEngine;
using UnityEditor;
@ -13,6 +14,8 @@ namespace Unity.Vfx.Cameras.Editor
public bool m_ShowCamera = true;
public bool m_showLens = true;
public bool m_showBody = true;
public bool m_showStereo = true;
public bool m_showOctane = false;
public override void OnInspectorGUI()
{
@ -21,153 +24,266 @@ namespace Unity.Vfx.Cameras.Editor
physCamera.Update();
// Start --------------------------------------------------------
var camObj = serializedObject.targetObject as PhysicalCamera;
var property = this.serializedObject.FindProperty(GetName(() => camObj.m_Mode));
AddEnumPopup(property, "Mode", "Determines is the Physical Camera controls the attached camera or reads from it.", typeof(PhysicalCameraMode));
var property = this.serializedObject.FindProperty("m_Mode");
AddEnumPopup(property, "Mode", typeof(PhysicalCameraMode));
property = this.serializedObject.FindProperty("m_AssociatedCameraObj");
property = this.serializedObject.FindProperty( GetName( ()=>camObj.m_AssociatedCameraObj) );
EditorGUILayout.PropertyField(property);
// models
var camModel = this.serializedObject.FindProperty("m_cameraModel");
var camModel = this.serializedObject.FindProperty("m_Model");
var lensModel = camModel.FindPropertyRelative("m_Lens");
var bodyModel = camModel.FindPropertyRelative("m_Body");
var bodyStereo = camModel.FindPropertyRelative("m_Stereo");
m_ShowCamera = EditorGUILayout.Foldout(m_ShowCamera, "Camera");
if (m_ShowCamera)
OnInspectorGuiCamera(camModel, lensModel);
DrawCameraModel(camModel, lensModel);
m_showLens = EditorGUILayout.Foldout(m_showLens, "Camera Lens");
m_showLens = EditorGUILayout.Foldout(m_showLens, "Lens");
if (m_showLens)
OnInspectorGuiLens(lensModel);
DrawLensModel(lensModel);
m_showBody = EditorGUILayout.Foldout(m_showBody, "Camera body");
m_showBody = EditorGUILayout.Foldout(m_showBody, "Body");
if (m_showBody)
OnInspectorGuiBody(bodyModel);
DrawBodyModel(bodyModel);
m_showStereo = EditorGUILayout.Foldout(m_showStereo, "Stereoscopic");
if (m_showStereo)
DrawStereoModel(bodyStereo);
// Done -------------------------------------------------------------
physCamera.ApplyModifiedProperties();
EditorGUI.EndChangeCheck();
}
private void OnInspectorGuiCamera(SerializedProperty camModel, SerializedProperty lensModel)
private void DrawCameraModel(SerializedProperty camModel, SerializedProperty lensModel)
{
var camObj = serializedObject.targetObject as PhysicalCamera;
var camModelObj = camObj.Model;
SerializedProperty property;
property = camModel.FindPropertyRelative("m_ProjectionMode");
AddEnumPopup(property, "Projection", typeof(EProjectionMode));
property = camModel.FindPropertyRelative("m_NearClippingPlane");
AddFloatProperty(property, "Near clipping plane", (oldv, newv) =>
// Projection / stereo
{
if (newv < 0f) return 0f;
else return newv;
});
var projProp = camModel.FindPropertyRelative(GetName(() => camModelObj.m_ProjectionMode));
var stereoProp = camModel.FindPropertyRelative(GetName(() => camModelObj.m_StereoScopic));
property = camModel.FindPropertyRelative("m_FarClippingPlane");
AddFloatProperty(property, "Far clipping plane", (oldv, newv) => {
if (newv < 0f) return 0f;
else return newv;
});
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, projProp);
EditorGUI.BeginProperty(ourRect, GUIContent.none, stereoProp);
property = camModel.FindPropertyRelative("m_AutoFocus");
AddBoolProperty(property, "Autofocus");
int value = (stereoProp.boolValue ? 1 : 0) * 2 + projProp.intValue;
string[] enumNamesList = new []
{
EProjectionMode.Perspective.ToString(),
EProjectionMode.Ortographic.ToString(),
"Stereo " + EProjectionMode.Perspective.ToString(),
"Stereo " + EProjectionMode.Ortographic.ToString(),
};
var newValue = EditorGUILayout.Popup("Projection", value, enumNamesList);
if (newValue != value)
{
projProp.intValue = newValue & 1;
stereoProp.boolValue = (newValue >> 1) != 0;
}
EditorGUI.EndProperty();
EditorGUI.EndProperty();
EditorGUILayout.EndHorizontal();
property = camModel.FindPropertyRelative("m_Exposure");
AddFloatProperty(property, "Exposure(?)");
}
// Fake property
if(camObj.m_cameraModel.m_ProjectionMode < EProjectionMode.Ortographic )
// Fake property: FOV
{
EditorGUILayout.BeginHorizontal();
var orgValue = camObj.m_cameraModel.HorzAFOV;
var newValue = EditorGUILayout.FloatField("Horizontal AFOV (deg)", orgValue);
GUIContent gc;
if (camObj.Model.m_ProjectionMode < EProjectionMode.Ortographic)
gc = new GUIContent("Vertical FOV", "Vertical angular field of view of the camera.");
else
gc = new GUIContent("Vertical FOV", "Vertical field of view of the camera.");
var orgValue = camObj.Model.VerticalFOV;
var newValue = EditorGUILayout.FloatField(gc, orgValue);
newValue = camObj.Model.Rules.ClampVerticalFOV(newValue);
if (orgValue != newValue)
{
if (newValue < 0.00001f) newValue = 0.00001f;
if (newValue > 180f) newValue = 180f;
camObj.m_cameraModel.HorzAFOV = newValue;
var lens = camModelObj.Lens;
var flenProp = lensModel.FindPropertyRelative(GetName(() => lens.m_FocalLength));
camObj.Model.VerticalFOV = newValue;
flenProp.floatValue = lens.m_FocalLength;
}
EditorGUILayout.EndHorizontal();
}
var property = camModel.FindPropertyRelative(GetName(() => camModelObj.m_NearClippingPlane ));
AddFloatProperty(property, "Near clipping plane", "Distance, from camera sensor, to the Near clipping plane.", (oldv, newv) =>
{
if (newv < 0.01f) newv = 0.01f;
var far = camModel.FindPropertyRelative(GetName(() => camModelObj.m_FarClippingPlane));
if (far.floatValue - 0.01f < newv)
far.floatValue = newv + 0.01f;
return newv;
});
property = camModel.FindPropertyRelative( GetName(() => camModelObj.m_FarClippingPlane) );
AddFloatProperty(property, "Far clipping plane", "Distance, from camera sensor, to the Far clipping plane.", (oldv, newv) => {
if (newv < camModelObj.m_NearClippingPlane +0.01f) return camModelObj.m_NearClippingPlane + 0.01f;
else return newv;
});
property = camModel.FindPropertyRelative(GetName(() => camModelObj.m_AutoFocus));
AddBoolProperty(property, "Autofocus", "Does the camera auto focus? [For future use]");
GUI.enabled = camObj.Model.Body.m_HDR;
property = camModel.FindPropertyRelative(GetName(() => camModelObj.m_Exposure));
AddFloatSlider( property, "Exposure", "Used for tonal mapping of HDR images. [For future use]", null, 1f, -10f, 10f);
GUI.enabled = true;
}
private void OnInspectorGuiBody(SerializedProperty bodyModel)
private void DrawBodyModel(SerializedProperty bodyModel)
{
var camObj = serializedObject.targetObject as PhysicalCamera;
var bodyModelObj = camObj.Model.Body;
var property = bodyModel.FindPropertyRelative("m_SensorWidth");
AddFloatSlider(property, "Sensor width (mm)", null, 1000f, 0.001f, 0.1f);
var property = bodyModel.FindPropertyRelative( GetName(()=> bodyModelObj.m_SensorWidth));
AddFloatProperty(property, "Sensor width", "Width, in millimeters, of the camera sensor.", (o, n) => n < 0.001f ? 0.001f : n > 0.1f ? 0.1f : n, 1000f);
property = bodyModel.FindPropertyRelative("m_SensorHeight");
AddFloatSlider(property, "Sensor height (mm)", null, 1000f, 0.001f, 0.1f);
property = bodyModel.FindPropertyRelative(GetName(() => bodyModelObj.m_SensorHeight));
AddFloatProperty(property, "Sensor height", "Height, in millimeters, of the camera sensor.", (o, n) => n < 0.001f ? 0.001f : n > 0.1f ? 0.1f : n, 1000f);
// Fake property
// Fake property: Aspect Ratio
{
EditorGUILayout.BeginHorizontal();
var orgValue = camObj.m_cameraModel.m_Body.AspectRatio;
var newValue = EditorGUILayout.Slider("Aspect ratio (w/h)", orgValue, 0.1f, 20f);
var orgValue = camObj.Model.Body.AspectRatio;
var newValue = EditorGUILayout.FloatField(new GUIContent("Aspect ratio", "Aspect ratio of sensor: width over height"), orgValue);
if (newValue < camObj.Model.Rules.MaxAspectRatio(camObj.Model))
newValue = camObj.Model.Rules.MaxAspectRatio(camObj.Model);
if (newValue > 20f)
newValue = 20f;
if (orgValue != newValue)
camObj.m_cameraModel.m_Body.AspectRatio = newValue;
camObj.Model.Body.AspectRatio = newValue;
EditorGUILayout.EndHorizontal();
}
property = bodyModel.FindPropertyRelative("m_ShutterSpeed");
AddFloatSlider(property, "Shutter speed (sec.)", null, 1f, 1/100000f, 5*60f);
property = bodyModel.FindPropertyRelative(GetName(() => bodyModelObj.m_ShutterAngle));
AddIntSlider(property, "Shutter angle", "For motion blur, dictates the angle of the shutters opening.", null, 15, 360);
property = bodyModel.FindPropertyRelative("m_ISO");
AddIntSlider(property, "ISO", null, 25, 32000);
property = bodyModel.FindPropertyRelative(GetName(() => bodyModelObj.m_ISO));
AddIntProperty(property, "ISO", "A measure of the sensitivity of the image sensor. [For future use]", (o, n) => n < 25 ? 25 : n > 25600 ? 25600 : n);
property = bodyModel.FindPropertyRelative("m_HDR");
AddBoolProperty(property, "HDR");
property = bodyModel.FindPropertyRelative(GetName(() => bodyModelObj.m_HDR));
AddBoolProperty(property, "HDR", "Toggles extended dynamic range of generated images.");
property = bodyModel.FindPropertyRelative("m_LensShiftX");
AddFloatSlider(property, "Lens Shift X", null, 1f, -1f, 1f);
property = bodyModel.FindPropertyRelative(GetName(() => bodyModelObj.m_LensShiftX));
AddFloatSlider(property, "Lens Shift X", "[For future use]", null, 1f, -1f, 1f);
property = bodyModel.FindPropertyRelative("m_LensShiftY");
AddFloatSlider(property, "Lens Shift Y", null, 1f, -1f, 1f);
property = bodyModel.FindPropertyRelative(GetName(() => bodyModelObj.m_LensShiftY));
AddFloatSlider(property, "Lens Shift Y", "[For future use]", null, 1f, -1f, 1f);
if (camObj.m_cameraModel.m_ProjectionMode < EProjectionMode.Ortographic)
GUI.enabled = camObj.Model.m_ProjectionMode < EProjectionMode.Ortographic;
{
property = bodyModel.FindPropertyRelative("m_PerspectiveCorrection");
AddFloatSlider(property, "Perspective Correction", null, 1f, -1f, 1f);
property = bodyModel.FindPropertyRelative(GetName(() => bodyModelObj.m_PerspectiveCorrection));
AddFloatSlider(property, "Perspective Correction", "[For future use]", null, 1f, -1f, 1f);
}
GUI.enabled = true;
}
private void OnInspectorGuiLens(SerializedProperty lensModel)
private void DrawLensModel(SerializedProperty lensModel)
{
var property = lensModel.FindPropertyRelative("m_FocalLength");
AddFloatSlider(property, "Focal length", null, 1000f, 1/1000f, 2f);
var camObj = serializedObject.targetObject as PhysicalCamera;
var lensModelObj = camObj.Model.Lens;
property = lensModel.FindPropertyRelative("m_FocalDepth");
AddFloatSlider(property, "Focal depth(?)", null, 1, 0f, float.MaxValue);
GUI.enabled = camObj.Model.m_ProjectionMode == EProjectionMode.Perspective;
property = lensModel.FindPropertyRelative("m_FStop");
AddFloatSlider(property, "F-Stop", null, 1f, 0.25f, 128f);
var property = lensModel.FindPropertyRelative( GetName(()=> lensModelObj.m_FocalLength));
AddFloatProperty(property, "Focal length", "Focal length of the lens in millimeters.", (o, n) =>
{
if (n < 0.001f) n = 0.001f;
return n;
}, 1000f);
property = lensModel.FindPropertyRelative("m_Aperture");
AddFloatSlider(property, "Aperture(?)", null, 1f, -1f, 1f);
GUI.enabled = true;
property = lensModel.FindPropertyRelative("m_ApertureAspectRatio");
AddFloatSlider(property, "Aperture aspect ratio(?)", null, 1f, -1f, 1f);
property = lensModel.FindPropertyRelative(GetName(() => lensModelObj.m_FStop));
AddFloatSlider(property, "F-Stop", "Ratio of the lens's focal length to the diameter of the lens's entrance pupil. [For future use]", null, 1f, 0.7f, 64f);
property = lensModel.FindPropertyRelative("m_ApertureEdge");
AddFloatSlider(property, "Aperture edge(?)", null, 1f, -1f, 1f);
DrawOctaneModel(lensModel);
}
property = lensModel.FindPropertyRelative("m_Distortion");
AddFloatSlider(property, "Distortion (?)", null, 1f, -1f, 1f);
private void DrawOctaneModel(SerializedProperty lensModel)
{
var camObj = serializedObject.targetObject as PhysicalCamera;
var lensModelObj = camObj.Model.Lens;
EditorGUI.indentLevel++;
// Octane
m_showOctane = EditorGUILayout.Foldout(m_showOctane, "Octane parameters");
if (!m_showOctane)
{
EditorGUI.indentLevel--;
return;
}
var property = lensModel.FindPropertyRelative(GetName(() => lensModelObj.m_FocalDepth));
AddFloatProperty(property, "Focal depth", "See Octane documentation.");
property = lensModel.FindPropertyRelative(GetName(() => lensModelObj.m_Aperture));
AddFloatProperty(property, "Aperture", "See Octane documentation.");
property = lensModel.FindPropertyRelative(GetName(() => lensModelObj.m_ApertureAspectRatio));
AddFloatProperty(property, "Aperture aspect ratio", "See Octane documentation.");
property = lensModel.FindPropertyRelative(GetName(() => lensModelObj.m_ApertureEdge));
AddFloatProperty(property, "Aperture edge", "See Octane documentation.");
property = lensModel.FindPropertyRelative(GetName(() => lensModelObj.m_Distortion));
AddFloatProperty(property, "Distortion", "See Octane documentation.");
EditorGUI.indentLevel--;
}
public static string GetName(Expression<Func<object>> exp)
{
MemberExpression body = exp.Body as MemberExpression;
if (body == null)
{
var ubody = (UnaryExpression)exp.Body;
body = ubody.Operand as MemberExpression;
}
return body.Member.Name;
}
private void DrawStereoModel(SerializedProperty stereoModel)
{
var camObj = serializedObject.targetObject as PhysicalCamera;
var stereoModelObj = camObj.Model.Stereo;
GUI.enabled = camObj.Model.m_StereoScopic;
var property = stereoModel.FindPropertyRelative( GetName(()=> stereoModelObj.m_Mode));
AddEnumPopup(property, "Mode", "", typeof(EStereoscopicMode));
property = stereoModel.FindPropertyRelative(GetName(() => stereoModelObj.m_EyeDistance));
AddFloatSlider(property, "Eye Distance", "Distance seperating the eyes. [For future use]", null, 1, 0f, float.MaxValue);
property = stereoModel.FindPropertyRelative(GetName(() => stereoModelObj.m_SwapEyes));
AddBoolProperty(property, "Swap eyes", "[For future use]");
property = stereoModel.FindPropertyRelative(GetName(() => stereoModelObj.m_LeftFilter));
EditorGUILayout.PropertyField(property);
property = stereoModel.FindPropertyRelative(GetName(() => stereoModelObj.m_RightFilter));
EditorGUILayout.PropertyField(property);
GUI.enabled = true;
}
private delegate T OnValueChangedDelegate<T>(T oldValue, T newValue);
void AddEnumPopup(SerializedProperty porperty, string text, Type typeOfEnum, OnValueChangedDelegate<int> onChange =null)
void AddEnumPopup(SerializedProperty porperty, string text, string tooltip, Type typeOfEnum, OnValueChangedDelegate<int> onChange =null)
{
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, porperty);
@ -182,28 +298,13 @@ namespace Unity.Vfx.Cameras.Editor
EditorGUILayout.EndHorizontal();
}
void AddIntProperty(SerializedProperty porperty, string text, OnValueChangedDelegate<int> onChange = null)
{
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, porperty);
var orgValue = porperty.intValue;
var newValue = EditorGUILayout.IntField(text, orgValue);
if (onChange != null && orgValue != newValue)
newValue = onChange(orgValue, newValue);
porperty.intValue = newValue;
EditorGUI.EndProperty();
EditorGUILayout.EndHorizontal();
}
void AddFloatProperty(SerializedProperty porperty, string text, OnValueChangedDelegate<float> onChange = null, float factor = 1f)
void AddFloatProperty(SerializedProperty porperty, string text, string tooltip, OnValueChangedDelegate<float> onChange = null, float factor = 1f)
{
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, porperty);
var orgValue = porperty.floatValue * factor;
var newValue = EditorGUILayout.FloatField(text, orgValue) / factor;
var newValue = EditorGUILayout.FloatField(new GUIContent(text, tooltip), orgValue) / factor;
if (onChange != null && orgValue != newValue)
newValue = onChange(orgValue, newValue);
porperty.floatValue = newValue;
@ -212,28 +313,13 @@ namespace Unity.Vfx.Cameras.Editor
EditorGUILayout.EndHorizontal();
}
void AddFloatSlider(SerializedProperty porperty, string text, OnValueChangedDelegate<float> onChange = null, float factor = 1f, float min = 0, float max = float.MaxValue)
{
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, porperty);
var orgValue = porperty.floatValue * factor;
var newValue = EditorGUILayout.Slider(text, orgValue, min * factor, max * factor) / factor;
if (onChange != null && orgValue != newValue)
newValue = onChange(orgValue, newValue);
porperty.floatValue = newValue;
EditorGUI.EndProperty();
EditorGUILayout.EndHorizontal();
}
void AddIntSlider(SerializedProperty porperty, string text, OnValueChangedDelegate<int> onChange = null, int min = 0, int max = int.MaxValue)
void AddIntProperty(SerializedProperty porperty, string text, string tooltip, OnValueChangedDelegate<int> onChange = null)
{
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, porperty);
var orgValue = porperty.intValue;
var newValue = EditorGUILayout.IntSlider(text, orgValue, min, max);
var newValue = EditorGUILayout.IntField(new GUIContent(text, tooltip), orgValue);
if (onChange != null && orgValue != newValue)
newValue = onChange(orgValue, newValue);
porperty.intValue = newValue;
@ -242,14 +328,43 @@ namespace Unity.Vfx.Cameras.Editor
EditorGUILayout.EndHorizontal();
}
void AddFloatSlider(SerializedProperty porperty, string text, string tooltip, OnValueChangedDelegate<float> onChange = null, float factor = 1f, float min = 0, float max = float.MaxValue)
{
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, porperty);
void AddBoolProperty(SerializedProperty porperty, string text, OnValueChangedDelegate<bool> onChange = null)
var orgValue = porperty.floatValue * factor;
var newValue = EditorGUILayout.Slider(new GUIContent(text, tooltip), orgValue, min * factor, max * factor) / factor;
if (onChange != null && orgValue != newValue)
newValue = onChange(orgValue, newValue);
porperty.floatValue = newValue;
EditorGUI.EndProperty();
EditorGUILayout.EndHorizontal();
}
void AddIntSlider(SerializedProperty porperty, string text, string tooltip, OnValueChangedDelegate<int> onChange = null, int min = 0, int max = int.MaxValue)
{
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, porperty);
var orgValue = porperty.intValue;
var newValue = EditorGUILayout.IntSlider(new GUIContent(text, tooltip), orgValue, min, max);
if (onChange != null && orgValue != newValue)
newValue = onChange(orgValue, newValue);
porperty.intValue = newValue;
EditorGUI.EndProperty();
EditorGUILayout.EndHorizontal();
}
void AddBoolProperty(SerializedProperty porperty, string text, string tooltip, OnValueChangedDelegate<bool> onChange = null)
{
Rect ourRect = EditorGUILayout.BeginHorizontal();
EditorGUI.BeginProperty(ourRect, GUIContent.none, porperty);
var orgValue = porperty.boolValue;
var newValue = EditorGUILayout.Toggle(text, orgValue);
var newValue = EditorGUILayout.Toggle(new GUIContent(text, tooltip), orgValue);
if (onChange != null && orgValue != newValue)
newValue = onChange(orgValue, newValue);
porperty.boolValue = newValue;

Просмотреть файл

@ -11,19 +11,32 @@ namespace Unity.Vfx.Cameras.Model
/// </summary>
public class MathematicalModel
{
public virtual void ForceAFOV(float afov, ref PhysicalCameraModel camera)
#region Limits
public virtual float MaxVFOV { get { return 179f; } }
public virtual float MinVFOV { get { return 1f; } }
public virtual float MaxAspectRatio(PhysicalCameraModel camera)
{
camera.m_Lens.m_FocalLength = camera.m_Body.m_SensorWidth/ToRad(afov);
return camera.Body.m_SensorWidth/(ToRad(MaxVFOV)*camera.Lens.m_FocalLength);
}
public virtual void ComputeDependants(ref PhysicalCameraModel camera)
#endregion
public float ClampVerticalFOV( float fov )
{
return fov < MinVFOV ? MinVFOV : fov > MaxVFOV ? MaxVFOV : fov;
}
public float ComputerHAFOV(ref PhysicalCameraModel camera )
public virtual void ApplyVerticalFOV(float afov, PhysicalCameraModel camera)
{
return ToDeg(camera.m_Body.m_SensorWidth/ camera.m_Lens.m_FocalLength);
camera.Lens.m_FocalLength = camera.Body.m_SensorHeight/ToRad(afov);
}
public float VerticalFOV(PhysicalCameraModel camera )
{
return ToDeg(camera.Body.m_SensorHeight/ camera.Lens.m_FocalLength);
}
private float ToRad(float rads)
@ -36,6 +49,8 @@ namespace Unity.Vfx.Cameras.Model
return (float)(degrees * 180 / Math.PI);
}
}
}

Просмотреть файл

@ -4,34 +4,45 @@ namespace Unity.Vfx.Cameras.Model
{
[System.Serializable]
public struct PhysicalCameraBodyModel
public class PhysicalCameraBodyModel
{
public float m_SensorWidth;
public float m_SensorHeight;
public float m_LensShiftX;
public float m_LensShiftY;
public float m_PerspectiveCorrection;
public float m_ShutterSpeed;
public int m_ShutterAngle;
public int m_ISO;
public bool m_HDR;
public PhysicalCameraBodyModel()
{
SetupDefaultValues();
}
public void SetupDefaultValues()
{
m_SensorWidth = 35/1000f;
m_SensorHeight = 26/1000f;
m_SensorWidth = 36/1000f;
m_SensorHeight = 24/1000f;
m_LensShiftX = 0f;
m_LensShiftY = 0f;
m_PerspectiveCorrection = 0;
m_ShutterSpeed = 250;
m_ISO = 200;
m_ShutterAngle = 180;
m_ISO = 800;
m_HDR = false;
}
public bool IsValid()
{
return m_SensorWidth > 0 && m_SensorHeight > 0 && m_ShutterSpeed > 0 && m_ISO > 0;
return m_SensorWidth > 0 && m_SensorHeight > 0 && m_ShutterAngle > 0 && m_ISO > 0;
}
public float AspectRatio

Просмотреть файл

@ -4,11 +4,11 @@ namespace Unity.Vfx.Cameras.Model
{
[System.Serializable]
public struct PhysicalCameraLensModel
public class PhysicalCameraLensModel
{
public float m_FocalLength;
public float m_FStop;
public float m_Aperture; // no idea what this is
public float m_Aperture;
public float m_ApertureAspectRatio;
public float m_ApertureEdge;
public float m_Distortion;
@ -16,7 +16,7 @@ namespace Unity.Vfx.Cameras.Model
public void SetupDefaultValues()
{
m_FocalLength = 50/1000f;
m_FocalLength = 24/1000f;
m_FStop = 2.8f;
m_ApertureAspectRatio = 1f;
m_ApertureEdge = 1f;
@ -27,5 +27,10 @@ namespace Unity.Vfx.Cameras.Model
{
return m_FStop > 0 && m_FocalLength > 0;
}
public PhysicalCameraLensModel()
{
SetupDefaultValues();
}
}
}

Просмотреть файл

@ -1,55 +1,69 @@
using System;
using UnityEngine;
namespace Unity.Vfx.Cameras.Model
{
public enum EProjectionMode
{
Perspective,
Stereoscopic,
Ortographic,
Orthographic_Stereo
}
[System.Serializable]
public struct PhysicalCameraModel
public class PhysicalCameraModel
{
public MathematicalModel m_MathModel;
private MathematicalModel m_Rules;
public EProjectionMode m_ProjectionMode;
public bool m_StereoScopic;
public float m_NearClippingPlane;
public float m_FarClippingPlane;
public bool m_AutoFocus;
public float m_Exposure; // tone mapping / hdr
public float m_Exposure;
public PhysicalCameraBodyModel m_Body;
public PhysicalCameraLensModel m_Lens;
public StereoPhysicalCameraModel m_Stereo;
[SerializeField] private PhysicalCameraBodyModel m_Body;
[SerializeField] private PhysicalCameraLensModel m_Lens;
[SerializeField] private StereoPhysicalCameraModel m_Stereo;
public float HorzAFOV
public PhysicalCameraBodyModel Body {
get { return m_Body ?? (m_Body = new PhysicalCameraBodyModel()); }
}
public PhysicalCameraLensModel Lens
{
get { return m_MathModel.ComputerHAFOV( ref this ); }
get { return m_Lens ?? (m_Lens = new PhysicalCameraLensModel()); }
}
public StereoPhysicalCameraModel Stereo
{
get { return m_Stereo?? (m_Stereo = new StereoPhysicalCameraModel()); }
}
public MathematicalModel Rules
{
get { return m_Rules ?? (m_Rules = new MathematicalModel()); }
}
public float VerticalFOV
{
get { return Rules.VerticalFOV( this ); }
set
{
m_MathModel.ForceAFOV(value, ref this);
Rules.ApplyVerticalFOV(value, this);
}
}
public void SetupDefaultValues()
public void SetDefaultValues()
{
m_MathModel = new MathematicalModel();
m_ProjectionMode = EProjectionMode.Perspective;
m_NearClippingPlane = 0.0f;
m_FarClippingPlane = float.MaxValue;
m_StereoScopic = false;
m_NearClippingPlane = 0.03f;
m_FarClippingPlane = 1000f;
m_AutoFocus = false;
m_Exposure = 1.0f;
m_Exposure = 0.0f;
m_Body.SetupDefaultValues();
m_Lens.SetupDefaultValues();
m_MathModel.ComputeDependants(ref this);
Body.SetupDefaultValues();
Lens.SetupDefaultValues();
Stereo.SetupDefaultValues();
}
public bool IsValid()
@ -57,5 +71,9 @@ namespace Unity.Vfx.Cameras.Model
return m_Body.IsValid() && m_Lens.IsValid();
}
public PhysicalCameraModel()
{
SetDefaultValues();
}
}
}

Просмотреть файл

@ -3,14 +3,33 @@ using UnityEngine;
namespace Unity.Vfx.Cameras.Model
{
[System.Serializable]
public struct StereoPhysicalCameraModel
public enum EStereoscopicMode
{
public int m_StereoMode;
Offaxis,
}
[System.Serializable]
public class StereoPhysicalCameraModel
{
public EStereoscopicMode m_Mode;
public float m_EyeDistance;
public bool m_SwapEyes;
[Tooltip("Color tint used as filter for left eye. [For future use]")]
public Color m_LeftFilter;
[Tooltip("Color tint used as filter for right eye. [For future use]")]
public Color m_RightFilter;
public StereoPhysicalCameraModel()
{
SetupDefaultValues();
}
public void SetupDefaultValues()
{
}
}
}

Просмотреть файл

@ -7,21 +7,78 @@ namespace Unity.Vfx.Cameras
public enum PhysicalCameraMode
{
Active,
Passive
Controller,
Slave
}
[ExecuteInEditMode]
public class PhysicalCamera : MonoBehaviour
{
public PhysicalCameraMode m_Mode;
public PhysicalCameraModel m_cameraModel;
[SerializeField] private PhysicalCameraModel m_Model;
public PhysicalCameraModel Model
{
get
{
return m_Model ?? (m_Model = new PhysicalCameraModel());
}
}
[Tooltip("The render camera component that is linked to this physical camera model.")]
public Camera m_AssociatedCameraObj;
public PhysicalCamera()
private void Update()
{
m_cameraModel.SetupDefaultValues();
if (m_AssociatedCameraObj == null)
{
var camera = transform.GetComponentInParent<Camera>();
if (camera != null)
m_AssociatedCameraObj = camera;
else
return;
}
if (m_Mode == PhysicalCameraMode.Controller)
{
if (m_AssociatedCameraObj.orthographic != (Model.m_ProjectionMode == EProjectionMode.Ortographic))
m_AssociatedCameraObj.orthographic = Model.m_ProjectionMode == EProjectionMode.Ortographic;
if (m_AssociatedCameraObj.fieldOfView != Model.VerticalFOV)
m_AssociatedCameraObj.fieldOfView = Model.VerticalFOV;
if (m_AssociatedCameraObj.nearClipPlane != Model.m_NearClippingPlane)
m_AssociatedCameraObj.nearClipPlane = Model.m_NearClippingPlane;
if (m_AssociatedCameraObj.farClipPlane != Model.m_FarClippingPlane)
m_AssociatedCameraObj.farClipPlane = Model.m_FarClippingPlane;
if (m_AssociatedCameraObj.hdr != Model.Body.m_HDR)
m_AssociatedCameraObj.hdr = Model.Body.m_HDR;
}
else
{
if (m_AssociatedCameraObj.orthographic != (Model.m_ProjectionMode == EProjectionMode.Ortographic))
{
Model.m_ProjectionMode = m_AssociatedCameraObj.orthographic
? EProjectionMode.Ortographic
: EProjectionMode.Perspective;
}
if (m_AssociatedCameraObj.fieldOfView != Model.VerticalFOV)
Model.VerticalFOV = m_AssociatedCameraObj.fieldOfView;
if (m_AssociatedCameraObj.nearClipPlane != Model.m_NearClippingPlane)
Model.m_NearClippingPlane = m_AssociatedCameraObj.nearClipPlane;
if (m_AssociatedCameraObj.farClipPlane != Model.m_FarClippingPlane)
Model.m_FarClippingPlane = m_AssociatedCameraObj.farClipPlane;
if (m_AssociatedCameraObj.hdr != Model.Body.m_HDR)
Model.Body.m_HDR = m_AssociatedCameraObj.hdr;
}
}
}
}

Двоичные данные
Project/Assets/testScene.unity Normal file

Двоичный файл не отображается.