浏览代码

Merge pull request #1333 from Unity-Technologies/Fix-camera-preview

Misc fix on camera preview and regular preview with planar reflection
/main
GitHub 7 年前
当前提交
522f0a34
共有 8 个文件被更改,包括 28 次插入23 次删除
  1. 2
      ScriptableRenderPipeline/HDRenderPipeline/CHANGELOG.md
  2. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs
  3. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.Handlers.cs
  4. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.cs
  5. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  6. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs
  7. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/FrameSettings.cs
  8. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyManager.cs

2
ScriptableRenderPipeline/HDRenderPipeline/CHANGELOG.md


- Fix the bug preventing decals from coexisting with density volumes
- Fix issue with alpha tested geometry using planar/triplanar mapping not render correctly or flickering (due to being wrongly alpha tested in depth prepass)
- Fix meta pass with triplanar (was not handling correctly the normal)
- Fix preview when a planar reflection is present
- Fix Camera preview, it is now a Preview cameraType (was a SceneView)
## [2018.1.0f2]

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs


public Color backgroundColorHDR = new Color(0.025f, 0.07f, 0.19f, 0.0f);
public bool clearDepth = true;
public RenderingPath renderingPath;
public RenderingPath renderingPath;
public LayerMask volumeLayerMask = -1;
public LayerMask volumeLayerMask = -1;
// Physical parameters
public float aperture = 8f;

// we create a runtime copy (m_ActiveFrameSettings that is used, and any parametrization is done on serialized frameSettings)
[SerializeField]
[FormerlySerializedAs("serializedFrameSettings")]
FrameSettings m_FrameSettings = new FrameSettings(); // Serialize frameSettings
FrameSettings m_FrameSettings = new FrameSettings(); // Serialize frameSettings
// Not serialized, visible only in the debug windows
FrameSettings m_FrameSettingsRuntime = new FrameSettings();

// Use for debug windows
// When camera name change we need to update the name in DebugWindows.
// This is the purpose of this class
bool m_IsDebugRegistered = false;
string m_CameraRegisterName;
bool m_IsDebugRegistered = false;
string m_CameraRegisterName;
// When we are a preview, there is no way inside Unity to make a disctinctoin between camera preview and material preview.
// This property allow to say that we are an editor camera preview when the type is preview.
public bool isEditorCameraPreview { get; set; }
// This is the function use outside to access FrameSettings. It return the current state of FrameSettings for the camera
// taking into account the customization via the debug menu

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.Handlers.cs


EditorUtility.CopySerialized(cameraData, m_PreviewAdditionalCameraData);
var layer = c.GetComponent<PostProcessLayer>() ?? ComponentSingleton<PostProcessLayer>.instance;
EditorUtility.CopySerialized(layer, m_PreviewPostProcessLayer);
m_PreviewCamera.cameraType = CameraType.SceneView; // This is required else if we use Preview the image is flipped... (Unity...)
// We need to call UpdateDirtyFrameSettings to update the dirty flags that was set in the CopySerialized call
m_PreviewAdditionalCameraData.UpdateDirtyFrameSettings(true, cameraData.GetFrameSettings());
// And then to copy the runtime frame settings
// So this includes the runtime frame settings properly
cameraData.GetFrameSettings().CopyTo(m_PreviewAdditionalCameraData.GetFrameSettings());
m_PreviewHDCamera.Update(m_PreviewAdditionalCameraData.GetFrameSettings(), m_PreviewPostProcessLayer, null);
var previewTexture = GetPreviewTextureWithSize((int)previewSize.x, (int)previewSize.y);
m_PreviewCamera.targetTexture = previewTexture;

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.cs


Camera m_PreviewCamera;
HDAdditionalCameraData m_PreviewAdditionalCameraData;
PostProcessLayer m_PreviewPostProcessLayer;
HDCamera m_PreviewHDCamera;
void OnEnable()
{

m_PreviewCamera.enabled = false;
m_PreviewCamera.cameraType = CameraType.Preview; // Must be init before adding HDAdditionalCameraData
m_PreviewAdditionalCameraData = m_PreviewCamera.gameObject.AddComponent<HDAdditionalCameraData>();
// Say that we are a camera editor preview and not just a regular preview
m_PreviewAdditionalCameraData.isEditorCameraPreview = true;
m_PreviewHDCamera = new HDCamera(m_PreviewCamera);
m_PreviewHDCamera.Update(m_PreviewAdditionalCameraData.GetFrameSettings(), m_PreviewPostProcessLayer, null);
}
void OnDisable()

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


continue;
}
if (camera.cameraType != CameraType.Reflection
// Don't render reflection in Preview, it prevent them to display
if (camera.cameraType != CameraType.Reflection && camera.cameraType != CameraType.Preview
// Planar probes rendering is not currently supported for orthographic camera
// Avoid rendering to prevent error log spamming
&& !camera.orthographic)

(hdCamera.clearColorMode == HDAdditionalCameraData.ClearColorMode.Sky && !m_SkyManager.IsVisualSkyValid()) ||
// Special handling for Preview we force to clear with background color (i.e black)
// Note that the sky use in this case is the last one setup. If there is no scene or game, there is no sky use as reflection in the preview
hdCamera.camera.cameraType == CameraType.Preview
HDUtils.IsRegularPreviewCamera(hdCamera.camera)
)
{
Color clearColor = hdCamera.backgroundColorHDR;

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs


Vector2 mousePixelCoord = MousePositionDebug.instance.GetMouseClickPosition(camera.screenSize.y);
return new Vector4(mousePixelCoord.x, mousePixelCoord.y, camera.viewportScale.x * mousePixelCoord.x / camera.screenSize.x, camera.viewportScale.y * mousePixelCoord.y / camera.screenSize.y);
}
// This function check if camera is a CameraPreview, then check if this preview is a regular preview (i.e not a preview from the camera editor)
public static bool IsRegularPreviewCamera(Camera camera)
{
var additionalCameraData = camera.GetComponent<HDAdditionalCameraData>();
return camera.cameraType == CameraType.Preview && ((additionalCameraData == null) || (additionalCameraData && !additionalCameraData.isEditorCameraPreview));
}
}
}

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/FrameSettings.cs


aggregate.ConfigureMSAADependentSettings();
aggregate.ConfigureStereoDependentSettings();
if (camera.cameraType == CameraType.Preview)
// Disable various option for the preview except if we are a Camera Editor preview
if (HDUtils.IsRegularPreviewCamera(camera))
// remove undesired feature in preview
aggregate.enableShadow = false;
aggregate.enableContactShadows = false;
aggregate.enableSSR = false;

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyManager.cs


}
}
public void UpdateCurrentSkySettings(HDCamera camera)
public void UpdateCurrentSkySettings(HDCamera hdCamera)
if (camera.camera.cameraType == CameraType.Preview)
if (HDUtils.IsRegularPreviewCamera(hdCamera.camera))
{
m_VisualSky.skySettings = GetDefaultPreviewSkyInstance();
}

// Update needs to happen before testing if the component is active other internal data structure are not properly updated yet.
VolumeManager.instance.Update(m_LightingOverrideVolumeStack, camera.camera.transform, m_LightingOverrideLayerMask);
VolumeManager.instance.Update(m_LightingOverrideVolumeStack, hdCamera.camera.transform, m_LightingOverrideLayerMask);
if(VolumeManager.instance.IsComponentActiveInMask<VisualEnvironment>(m_LightingOverrideLayerMask))
{
SkySettings newSkyOverride = GetSkySetting(m_LightingOverrideVolumeStack);

正在加载...
取消
保存