Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
045ded9
Initial data changes
unity-cchu Mar 24, 2021
0a0cfca
Added a few more fixes for new variables
unity-cchu Mar 24, 2021
af2b96b
First pass rework of the UI
unity-cchu Mar 24, 2021
5461791
Fixed warnings and removed run in editor button
unity-cchu Mar 24, 2021
a32e9d6
Added warning to camera
unity-cchu Mar 25, 2021
6511a50
Fixed some warnings
unity-cchu Mar 25, 2021
da43583
First pass at versioning
unity-cchu Mar 25, 2021
8829251
Removing editor time restriction (in progress)
unity-cchu Mar 25, 2021
91a73b8
Fixed letterbox and pillarbox (they were switched)
unity-cchu Mar 26, 2021
cf806eb
Removed projection and size from orthographic
unity-cchu Mar 26, 2021
05d3c46
Fixed some bugs and changed the warning to info
unity-cchu Mar 26, 2021
fae2615
Added error message if you are using a non 2d renderer with pixel per…
unity-cchu Mar 26, 2021
87b5a75
Update CHANGELOG.md
unity-cchu Mar 27, 2021
8ee6a3c
Merge branch 'master' into 2d/Pixel-Perfect-Improvements
unity-cchu Apr 1, 2021
1c7a11f
Fixed formatting
unity-cchu Apr 5, 2021
6f4490a
Merge branch 'master' into 2d/Pixel-Perfect-Improvements
unity-cchu Apr 8, 2021
a5ebfab
In progress update of docs
unity-cchu Apr 8, 2021
0a7c2e5
Fixed issue with Windowbox and StretchFill
unity-cchu Apr 9, 2021
4b8a974
Fixed bug with letterbox and other modes
unity-cchu Apr 12, 2021
ba18bad
Merge branch 'master' into 2d/Pixel-Perfect-Improvements
unity-cchu Apr 13, 2021
27a1811
Merge branch 'master' into 2d/Pixel-Perfect-Improvements
unity-cchu Apr 13, 2021
6aad3d4
Updated changes needed for new namespace
unity-cchu Apr 13, 2021
53d20b1
Fixed some code that caused a warning when building the player
unity-cchu Apr 15, 2021
c503cde
Fixed formatting
unity-cchu Apr 15, 2021
da6d5bc
Merge branch 'master' into 2d/Pixel-Perfect-Improvements
unity-cchu Apr 16, 2021
1952e2c
Pixel perfect camera updates
unity-cchu Apr 26, 2021
902ffb2
Merge branch 'master' into 2d/Pixel-Perfect-Improvements
unity-cchu Apr 26, 2021
df3cdf8
Merge branch 'master' into 2d/Pixel-Perfect-Improvements
unity-cchu Apr 27, 2021
55eb08c
Fix for bad merge
unity-cchu Apr 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- ClearFlag.Depth does not implicitely clear stencil anymore. ClearFlag.Stencil added.
- The Forward Renderer asset is renamed to the Universal Renderer asset. The Universal Renderer asset contains the property Rendering Path that lets you select the Forward or the Deferred Rendering Path.
- Improved PixelPerfectCamera UI/UX
- Changed Pixel Snapping and Upscale Render Texture in the PixelPerfectCamera to a dropdown.
- Move Assets/Create/Rendering/Universal Render Pipeline/Pipeline Asset (2D Renderer) to Assets/Create/Rendering/URP Asset (with 2D Renderer)
- Move Assets/Create/Rendering/Universal Render Pipeline/2D Renderer to Assets/Create/Rendering/URP 2D Renderer
- Move Assets/Create/Rendering/Universal Render Pipeline/Renderer Feature to Assets/Create/Rendering/URP Renderer Feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ private class Style
public GUIContent y = new GUIContent("Y");
public GUIContent assetsPPU = new GUIContent("Assets Pixels Per Unit", "The amount of pixels that make up one unit of the Scene. Set this value to match the PPU value of Sprites in the Scene.");
public GUIContent refRes = new GUIContent("Reference Resolution", "The original resolution the Assets are designed for.");
public GUIContent upscaleRT = new GUIContent("Upscale Render Texture", "If enabled, the Scene is rendered as close as possible to the Reference Resolution while maintaining the screen aspect ratio, then upscaled to fit the full screen.");
public GUIContent pixelSnapping = new GUIContent("Pixel Snapping", "If enabled, Sprite Renderers are snapped to a grid in world space at render-time. Grid size is based on the Assets Pixels Per Unit value. This does not affect GameObjects' Transform positions.");
public GUIContent gridSnapping = new GUIContent("Grid Snapping", "Sets the snapping behavior for the camera and sprites.");
public GUIContent cropFrame = new GUIContent("Crop Frame", "Crops the viewport to match the Reference Resolution, along the checked axis. Black bars will be added to fit the screen aspect ratio.");
public GUIContent stretchFill = new GUIContent("Stretch Fill", "If enabled, expands the viewport to fit the screen resolution while maintaining the viewport aspect ratio.");
public GUIContent currentPixelRatio = new GUIContent("Current Pixel Ratio", "Ratio of the rendered Sprites compared to their original size.");
public GUIContent runInEditMode = new GUIContent("Run In Edit Mode", "Enable this to preview Camera setting changes in Edit Mode. This will cause constant changes to the Scene while active.");
public const string cameraStackingWarning = "Pixel Perfect Camera won't function properly if stacked with another camera.";
public const string nonRenderer2DError = "Pixel Perfect Camera requires a camera using a 2D Renderer.";

public GUIStyle centeredLabel;

Expand All @@ -39,11 +39,8 @@ public Style()
private SerializedProperty m_AssetsPPU;
private SerializedProperty m_RefResX;
private SerializedProperty m_RefResY;
private SerializedProperty m_UpscaleRT;
private SerializedProperty m_PixelSnapping;
private SerializedProperty m_CropFrameY;
private SerializedProperty m_CropFrameX;
private SerializedProperty m_StretchFill;
private SerializedProperty m_CropFrame;
private SerializedProperty m_GridSnapping;

private Vector2 m_GameViewSize = Vector2.zero;
private GUIContent m_CurrentPixelRatioValue;
Expand All @@ -58,6 +55,22 @@ private void LazyInit()
m_CurrentPixelRatioValue = new GUIContent();
}

bool UsingRenderer2D()
{
PixelPerfectCamera obj = target as PixelPerfectCamera;
UniversalAdditionalCameraData cameraData = null;
obj?.TryGetComponent(out cameraData);

if (cameraData != null)
{
Renderer2D renderer2D = cameraData.scriptableRenderer as Renderer2D;
if (renderer2D != null)
return true;
}

return false;
}

void CheckForCameraStacking()
{
m_CameraStacking = false;
Expand All @@ -83,11 +96,8 @@ public void OnEnable()
m_AssetsPPU = serializedObject.FindProperty("m_AssetsPPU");
m_RefResX = serializedObject.FindProperty("m_RefResolutionX");
m_RefResY = serializedObject.FindProperty("m_RefResolutionY");
m_UpscaleRT = serializedObject.FindProperty("m_UpscaleRT");
m_PixelSnapping = serializedObject.FindProperty("m_PixelSnapping");
m_CropFrameY = serializedObject.FindProperty("m_CropFrameY");
m_CropFrameX = serializedObject.FindProperty("m_CropFrameX");
m_StretchFill = serializedObject.FindProperty("m_StretchFill");
m_CropFrame = serializedObject.FindProperty("m_CropFrame");
m_GridSnapping = serializedObject.FindProperty("m_GridSnapping");
}

public override bool RequiresConstantRepaint()
Expand All @@ -111,6 +121,12 @@ public override void OnInspectorGUI()
{
LazyInit();

if (!UsingRenderer2D())
{
EditorGUILayout.HelpBox(Style.nonRenderer2DError, MessageType.Error);
return;
}

float originalLabelWidth = EditorGUIUtility.labelWidth;

serializedObject.Update();
Expand Down Expand Up @@ -143,56 +159,16 @@ public override void OnInspectorGUI()
}
EditorGUILayout.EndHorizontal();

EditorGUILayout.PropertyField(m_UpscaleRT, m_Style.upscaleRT);
if (!m_UpscaleRT.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_PixelSnapping, m_Style.pixelSnapping);
EditorGUI.indentLevel--;
}
EditorGUILayout.PropertyField(m_CropFrame, m_Style.cropFrame);
EditorGUILayout.PropertyField(m_GridSnapping, m_Style.gridSnapping);

EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.PrefixLabel(m_Style.cropFrame);

EditorGUIUtility.labelWidth = k_SingleLetterLabelWidth * (EditorGUI.indentLevel + 1);
EditorGUILayout.PropertyField(m_CropFrameX, m_Style.x, GUILayout.MaxWidth(40.0f));
EditorGUILayout.PropertyField(m_CropFrameY, m_Style.y);
EditorGUIUtility.labelWidth = originalLabelWidth;
}
EditorGUILayout.EndHorizontal();

if (m_CropFrameY.boolValue && m_CropFrameX.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_StretchFill, m_Style.stretchFill);
EditorGUI.indentLevel--;
}

serializedObject.ApplyModifiedProperties();

PixelPerfectCamera obj = target as PixelPerfectCamera;

if (obj != null)
{
EditorGUI.BeginDisabledGroup(EditorApplication.isPlaying || !obj.isActiveAndEnabled);
EditorGUI.BeginChangeCheck();

bool runInEditMode = EditorGUILayout.Toggle(obj.runInEditMode, GUI.skin.button, GUILayout.Width(110.0f));
GUI.Label(GUILayoutUtility.GetLastRect(), m_Style.runInEditMode, m_Style.centeredLabel);

if (EditorGUI.EndChangeCheck())
{
obj.runInEditMode = runInEditMode;

if (runInEditMode)
obj.GetComponent<Camera>().Render();
else
obj.OnDisable();
}

EditorGUI.EndDisabledGroup();

if (obj.isActiveAndEnabled && (EditorApplication.isPlaying || obj.runInEditMode))
{
if (Event.current.type == EventType.Layout)
Expand Down Expand Up @@ -222,17 +198,17 @@ void OnSceneGUI()
float verticalOrthoSize;
float horizontalOrthoSize;

if (obj.cropFrameY && obj.cropFrameX)
if (obj.cropFrame == PixelPerfectCamera.CropFrame.StretchFill || obj.cropFrame == PixelPerfectCamera.CropFrame.Windowbox)
{
verticalOrthoSize = obj.refResolutionY * 0.5f / obj.assetsPPU;
horizontalOrthoSize = verticalOrthoSize * ((float)obj.refResolutionX / obj.refResolutionY);
}
else if (obj.cropFrameY)
else if (obj.cropFrame == PixelPerfectCamera.CropFrame.Letterbox)
{
verticalOrthoSize = obj.refResolutionY * 0.5f / obj.assetsPPU;
horizontalOrthoSize = verticalOrthoSize * ((float)gameViewWidth / (zoom * obj.refResolutionY));
}
else if (obj.cropFrameX)
else if (obj.cropFrame == PixelPerfectCamera.CropFrame.Pillarbox)
{
horizontalOrthoSize = obj.refResolutionX * 0.5f / obj.assetsPPU;
verticalOrthoSize = horizontalOrthoSize / (zoom * obj.refResolutionX / (float)gameViewHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,15 @@ void DrawCommonSettings()
m_CommonCameraSettingsFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_CommonCameraSettingsFoldout.value, Styles.projectionSettingsText);
if (m_CommonCameraSettingsFoldout.value)
{
settings.DrawProjection();
UnityEngine.Experimental.Rendering.Universal.PixelPerfectCamera pixelPerfectCamera;
camera.TryGetComponent<UnityEngine.Experimental.Rendering.Universal.PixelPerfectCamera>(out pixelPerfectCamera);
bool pixelPerfectEnabled = pixelPerfectCamera != null && pixelPerfectCamera.enabled;

if (pixelPerfectEnabled)
EditorGUILayout.HelpBox(Styles.pixelPerfectInfo, MessageType.Info);
else
settings.DrawProjection();

settings.DrawClippingPlanes();
EditorGUILayout.Space();
EditorGUILayout.Space();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class Styles
public static readonly string noRendererError = "There are no valid Renderers available on the Universal Render Pipeline asset.";
public static readonly string disabledPostprocessing = "Post Processing is currently disabled on the current Universal Render Pipeline renderer.";

public static readonly string pixelPerfectInfo = "Projection and Size have been hidden because the Pixel Perfect Camera is in use.";

public static GUIContent[] cameraBackgroundType =
{
EditorGUIUtility.TrTextContent("Skybox"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ namespace UnityEngine.Experimental.Rendering.Universal
internal class PixelPerfectBackgroundPass : ScriptableRenderPass
{
private static readonly ProfilingSampler m_ProfilingScope = new ProfilingSampler("Pixel Perfect Background Pass");
private bool m_SavedIsOrthographic;
private float m_SavedOrthographicSize;

public PixelPerfectBackgroundPass(RenderPassEvent evt)
{
renderPassEvent = evt;
}

public void Setup(bool savedIsOrthographic, float savedOrthographicSize)
{
m_SavedIsOrthographic = savedIsOrthographic;
m_SavedOrthographicSize = savedOrthographicSize;
}

public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cmd = CommandBufferPool.Get();
Expand All @@ -30,8 +38,12 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
Color.black);
}


context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

renderingData.cameraData.camera.orthographic = m_SavedIsOrthographic;
renderingData.cameraData.camera.orthographicSize = m_SavedOrthographicSize;
}
}
}
Loading