sleal-unity
4 年前
当前提交
3715567c
共有 48 个文件被更改,包括 432 次插入 和 159 次删除
-
73com.unity.perception/Runtime/GroundTruth/GroundTruthRendererFeature.cs
-
4com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs
-
5com.unity.perception/Runtime/GroundTruth/LabeledObjectsManager.cs
-
25com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs
-
24com.unity.perception/Runtime/GroundTruth/PerceptionCamera_InstanceSegmentation.cs
-
2com.unity.perception/Runtime/GroundTruth/PerceptionUpdater.cs
-
11com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs
-
12com.unity.perception/Runtime/GroundTruth/RenderedObjectInfo.cs
-
2com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs
-
29com.unity.perception/Runtime/GroundTruth/SimulationState.cs
-
4com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
-
18com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
-
2com.unity.perception/package.json
-
4com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs
-
5com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs
-
2com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs.meta
-
2com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs.meta
-
3com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses.meta
-
11com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs.meta
-
191com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/LensDistortionCrossPipelinePass.cs
-
3com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/LensDistortionCrossPipelinePass.cs.meta
-
3com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses.meta
-
3com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/GroundTruthPass.cs.meta
-
48com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/LensDistortionPass.cs
-
3com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses.meta
-
31com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/InstanceSegmentationUrpPass.cs
-
3com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/InstanceSegmentationUrpPass.cs.meta
-
31com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/LensDistortionUrpPass.cs
-
3com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/LensDistortionUrpPass.cs.meta
-
31com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/SemanticSegmentationUrpPass.cs
-
3com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/SemanticSegmentationUrpPass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses.meta
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/GroundTruthCrossPipelinePass.cs
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/LensDistortionPass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/GroundTruthCrossPipelinePass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/GroundTruthPass.cs
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: ab58b1700a9642998cb3a5971f6543d1 |
|||
timeCreated: 1615157471 |
|
|||
fileFormatVersion: 2 |
|||
guid: 799b5ba08ee3e6d479c2aac3a89507f0 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine.Rendering; |
|||
#if HDRP_PRESENT
|
|||
using UnityEngine.Rendering.HighDefinition; |
|||
#elif URP_PRESENT
|
|||
using UnityEngine.Rendering.Universal; |
|||
#endif
|
|||
|
|||
#if HDRP_PRESENT || URP_PRESENT
|
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
/// <summary>
|
|||
/// Custom Pass which will apply a lens distortion (per the respective volume override in URP or HDRP, or
|
|||
/// through a custom override directly through the pass) to an incoming mask / texture. The purpose of this
|
|||
/// is to allow the same lens distortion being applied to the RGB image in the perception camera to be applied
|
|||
/// to the respective ground truths generated.
|
|||
/// </summary>
|
|||
class LensDistortionCrossPipelinePass : GroundTruthCrossPipelinePass |
|||
{ |
|||
const string k_ShaderName = "Perception/LensDistortion"; |
|||
|
|||
// NOTICE: Serialize the shader so that the shader asset is included in player builds when the SemanticSegmentationPass is used.
|
|||
// Currently commented out and shaders moved to Resources folder due to serialization crashes when it is enabled.
|
|||
// See https://fogbugz.unity3d.com/f/cases/1187378/
|
|||
// [SerializeField]
|
|||
Shader m_LensDistortionShader; |
|||
Material m_LensDistortionMaterial; |
|||
|
|||
bool m_Initialized; |
|||
|
|||
static readonly int k_DistortionParams1Id = Shader.PropertyToID("_Distortion_Params1"); |
|||
static readonly int k_DistortionParams2Id = Shader.PropertyToID("_Distortion_Params2"); |
|||
|
|||
LensDistortion m_LensDistortion; |
|||
internal float? lensDistortionOverride = null; // Largely for testing, but could be useful otherwise
|
|||
|
|||
RenderTexture m_TargetTexture; |
|||
RenderTexture m_DistortedTexture; |
|||
|
|||
public LensDistortionCrossPipelinePass(Camera targetCamera, RenderTexture targetTexture) |
|||
: base(targetCamera) |
|||
{ |
|||
m_TargetTexture = targetTexture; |
|||
} |
|||
|
|||
public override void Setup() |
|||
{ |
|||
base.Setup(); |
|||
m_LensDistortionShader = Shader.Find(k_ShaderName); |
|||
|
|||
var shaderVariantCollection = new ShaderVariantCollection(); |
|||
|
|||
if (shaderVariantCollection != null) |
|||
shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_LensDistortionShader, PassType.ScriptableRenderPipeline)); |
|||
|
|||
m_LensDistortionMaterial = new Material(m_LensDistortionShader); |
|||
|
|||
if (shaderVariantCollection != null) |
|||
shaderVariantCollection.WarmUp(); |
|||
|
|||
// Set up a new texture
|
|||
if (m_DistortedTexture == null || m_DistortedTexture.width != Screen.width || m_DistortedTexture.height != Screen.height) |
|||
{ |
|||
if (m_DistortedTexture != null) |
|||
m_DistortedTexture.Release(); |
|||
|
|||
m_DistortedTexture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); |
|||
m_DistortedTexture.enableRandomWrite = true; |
|||
m_DistortedTexture.filterMode = FilterMode.Point; |
|||
m_DistortedTexture.Create(); |
|||
} |
|||
|
|||
// Grab the lens distortion
|
|||
#if HDRP_PRESENT
|
|||
// Grab the Lens Distortion from Perception Camera stack
|
|||
var hdCamera = HDCamera.GetOrCreate(targetCamera); |
|||
var stack = hdCamera.volumeStack; |
|||
m_LensDistortion = stack.GetComponent<LensDistortion>(); |
|||
#elif URP_PRESENT
|
|||
var stack = VolumeManager.instance.stack; |
|||
m_LensDistortion = stack.GetComponent<LensDistortion>(); |
|||
#endif
|
|||
m_Initialized = true; |
|||
} |
|||
|
|||
protected override void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult) |
|||
{ |
|||
if (m_Initialized == false) |
|||
return; |
|||
|
|||
if (SetLensDistortionShaderParameters() == false) |
|||
return; |
|||
|
|||
// Blit mayhem
|
|||
cmd.Blit(m_TargetTexture, m_DistortedTexture, m_LensDistortionMaterial); |
|||
cmd.Blit(m_DistortedTexture, m_TargetTexture); |
|||
|
|||
renderContext.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
} |
|||
|
|||
public bool SetLensDistortionShaderParameters() |
|||
{ |
|||
if (m_Initialized == false) |
|||
return false; |
|||
|
|||
// This code is lifted from the SetupLensDistortion() function in
|
|||
// https://github.com/Unity-Technologies/Graphics/blob/257b08bba6c11de0f894e42e811124247a522d3c/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPass.cs
|
|||
// This is in UnityEngine.Rendering.Universal.Internal.PostProcessPass::SetupLensDistortion so it's
|
|||
// unclear how to re-use this code
|
|||
|
|||
var intensity = 0.5f; |
|||
var scale = 1.0f; |
|||
var center = new Vector2(0.0f, 0.0f); |
|||
var mult = new Vector2(1.0f, 1.0f); |
|||
|
|||
#if HDRP_PRESENT
|
|||
if(m_LensDistortion == null) |
|||
return false; |
|||
#elif URP_PRESENT
|
|||
if (targetCamera == null) |
|||
return false; |
|||
|
|||
var additionalCameraData = targetCamera.GetUniversalAdditionalCameraData(); |
|||
if (additionalCameraData.renderPostProcessing == false && lensDistortionOverride.HasValue == false) |
|||
return false; |
|||
|
|||
if (m_LensDistortion.active == false) |
|||
return false; |
|||
|
|||
#else
|
|||
return false; |
|||
#endif
|
|||
|
|||
if (lensDistortionOverride.HasValue) |
|||
{ |
|||
intensity = lensDistortionOverride.Value; |
|||
} |
|||
else if (m_LensDistortion != null) |
|||
{ |
|||
// This is a bit finicky for URP - since Lens Distortion comes off the VolumeManager stack as active
|
|||
// even if post processing is not enabled. An intensity of 0.0f is untenable, so the below checks
|
|||
// ensures post processing hasn't been enabled but Lens Distortion actually overriden
|
|||
if (m_LensDistortion.intensity.value != 0.0f) |
|||
{ |
|||
intensity = m_LensDistortion.intensity.value; |
|||
center = m_LensDistortion.center.value * 2f - Vector2.one; |
|||
mult.x = Mathf.Max(m_LensDistortion.xMultiplier.value, 1e-4f); |
|||
mult.y = Mathf.Max(m_LensDistortion.yMultiplier.value, 1e-4f); |
|||
scale = 1.0f / m_LensDistortion.scale.value; |
|||
} |
|||
else |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
var amount = 1.6f * Mathf.Max(Mathf.Abs(intensity * 100.0f), 1.0f); |
|||
var theta = Mathf.Deg2Rad * Mathf.Min(160f, amount); |
|||
var sigma = 2.0f * Mathf.Tan(theta * 0.5f); |
|||
|
|||
var p1 = new Vector4( |
|||
center.x, |
|||
center.y, |
|||
mult.x, |
|||
mult.y |
|||
); |
|||
|
|||
var p2 = new Vector4( |
|||
intensity >= 0f ? theta : 1f / theta, |
|||
sigma, |
|||
scale, |
|||
intensity * 100.0f |
|||
); |
|||
|
|||
// Set Shader Constants
|
|||
m_LensDistortionMaterial.SetVector(k_DistortionParams1Id, p1); |
|||
m_LensDistortionMaterial.SetVector(k_DistortionParams2Id, p2); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
public override void SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId) |
|||
{ |
|||
SetLensDistortionShaderParameters(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif // ! HDRP_PRESENT || URP_PRESENT
|
|
|||
fileFormatVersion: 2 |
|||
guid: 91d542be380c442186b86e0816a0c0fb |
|||
timeCreated: 1615157478 |
|
|||
fileFormatVersion: 2 |
|||
guid: 3e921ed47cbb4b4daee97efd288b537e |
|||
timeCreated: 1615157360 |
|
|||
fileFormatVersion: 2 |
|||
guid: fce7b38cf56d40358e555bb2403b23d0 |
|||
timeCreated: 1615157376 |
|
|||
#if HDRP_PRESENT
|
|||
using System; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.HighDefinition; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
/// <summary>
|
|||
/// Custom Pass which renders labeled images where each object with a Labeling component is drawn with the value
|
|||
/// specified by the given LabelingConfiguration.
|
|||
/// </summary>
|
|||
public class LensDistortionPass : CustomPass |
|||
{ |
|||
public RenderTexture targetTexture; |
|||
public Camera targetCamera; |
|||
|
|||
internal LensDistortionCrossPipelinePass lensDistortionCrossPipelinePass; |
|||
|
|||
public LensDistortionPass(Camera targetCamera, RenderTexture targetTexture) |
|||
{ |
|||
this.targetTexture = targetTexture; |
|||
this.targetCamera = targetCamera; |
|||
EnsureInit(); |
|||
} |
|||
|
|||
public void EnsureInit() |
|||
{ |
|||
if (lensDistortionCrossPipelinePass == null) |
|||
{ |
|||
lensDistortionCrossPipelinePass = new LensDistortionCrossPipelinePass(targetCamera, targetTexture); |
|||
lensDistortionCrossPipelinePass.EnsureActivated(); |
|||
} |
|||
} |
|||
|
|||
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) |
|||
{ |
|||
EnsureInit(); |
|||
lensDistortionCrossPipelinePass.Setup(); |
|||
} |
|||
|
|||
protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult) |
|||
{ |
|||
CoreUtils.SetRenderTarget(cmd, targetTexture); |
|||
lensDistortionCrossPipelinePass.Execute(renderContext, cmd, hdCamera.camera, cullingResult); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: 4cd6f632a845433cbbfc06263002654a |
|||
timeCreated: 1615157347 |
|
|||
#if URP_PRESENT
|
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
class InstanceSegmentationUrpPass : ScriptableRenderPass |
|||
{ |
|||
InstanceSegmentationCrossPipelinePass m_InstanceSegmentationPass; |
|||
|
|||
public InstanceSegmentationUrpPass(Camera camera, RenderTexture targetTexture) |
|||
{ |
|||
m_InstanceSegmentationPass = new InstanceSegmentationCrossPipelinePass(camera); |
|||
ConfigureTarget(targetTexture, targetTexture.depthBuffer); |
|||
m_InstanceSegmentationPass.Setup(); |
|||
} |
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
var commandBuffer = CommandBufferPool.Get(nameof(InstanceSegmentationUrpPass)); |
|||
m_InstanceSegmentationPass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults); |
|||
CommandBufferPool.Release(commandBuffer); |
|||
} |
|||
|
|||
public void Cleanup() |
|||
{ |
|||
m_InstanceSegmentationPass.Cleanup(); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: f8f08e25f7cb4355aa70060081bc4200 |
|||
timeCreated: 1615156976 |
|
|||
#if URP_PRESENT
|
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
class LensDistortionUrpPass : ScriptableRenderPass |
|||
{ |
|||
public LensDistortionCrossPipelinePass lensDistortionCrossPipelinePass; |
|||
|
|||
public LensDistortionUrpPass(Camera camera, RenderTexture targetTexture) |
|||
{ |
|||
lensDistortionCrossPipelinePass = new LensDistortionCrossPipelinePass(camera, targetTexture); |
|||
ConfigureTarget(targetTexture, targetTexture.depthBuffer); |
|||
lensDistortionCrossPipelinePass.Setup(); |
|||
} |
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
var commandBuffer = CommandBufferPool.Get(nameof(SemanticSegmentationUrpPass)); |
|||
lensDistortionCrossPipelinePass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults); |
|||
CommandBufferPool.Release(commandBuffer); |
|||
} |
|||
|
|||
public void Cleanup() |
|||
{ |
|||
lensDistortionCrossPipelinePass.Cleanup(); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: db2ddd6b833f412bb68447d5f85eff4d |
|||
timeCreated: 1615157082 |
|
|||
#if URP_PRESENT
|
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
class SemanticSegmentationUrpPass : ScriptableRenderPass |
|||
{ |
|||
public SemanticSegmentationCrossPipelinePass m_SemanticSegmentationCrossPipelinePass; |
|||
|
|||
public SemanticSegmentationUrpPass(Camera camera, RenderTexture targetTexture, SemanticSegmentationLabelConfig labelConfig) |
|||
{ |
|||
m_SemanticSegmentationCrossPipelinePass = new SemanticSegmentationCrossPipelinePass(camera, labelConfig); |
|||
ConfigureTarget(targetTexture, targetTexture.depthBuffer); |
|||
m_SemanticSegmentationCrossPipelinePass.Setup(); |
|||
} |
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
var commandBuffer = CommandBufferPool.Get(nameof(SemanticSegmentationUrpPass)); |
|||
m_SemanticSegmentationCrossPipelinePass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults); |
|||
CommandBufferPool.Release(commandBuffer); |
|||
} |
|||
|
|||
public void Cleanup() |
|||
{ |
|||
m_SemanticSegmentationCrossPipelinePass.Cleanup(); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: a16b614c904345fa8666f31f18a703af |
|||
timeCreated: 1615157147 |
撰写
预览
正在加载...
取消
保存
Reference in new issue