浏览代码

added mask test object

/semantic_shader_tests
Mohsen Kamalzadeh 3 年前
当前提交
a78ec53e
共有 16 个文件被更改,包括 1034 次插入51 次删除
  1. 4
      TestProjects/PerceptionURP/Assets/Lit.mat
  2. 159
      TestProjects/PerceptionURP/Assets/Scenes/ShaderTests.unity
  3. 14
      TestProjects/PerceptionURP/Assets/testext.png.meta
  4. 1
      TestProjects/PerceptionURP/Packages/manifest.json
  5. 7
      TestProjects/PerceptionURP/Packages/packages-lock.json
  6. 4
      com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/Materials/SegmentationMaterial.mat
  7. 5
      com.unity.perception/Runtime/GroundTruth/Labeling/SemanticSegmentationBehaviour.cs
  8. 22
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs
  9. 20
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs
  10. 19
      com.unity.perception/Runtime/GroundTruth/Resources/InstanceSegmentation.shader
  11. 37
      com.unity.perception/Runtime/GroundTruth/Resources/SemanticSegmentation.shader
  12. 693
      TestProjects/PerceptionURP/Assets/treemask.png
  13. 92
      TestProjects/PerceptionURP/Assets/treemask.png.meta
  14. 8
      com.unity.perception/Runtime/GroundTruth/Exporters.meta
  15. 0
      /TestProjects/PerceptionURP/Assets/Scenes/ShaderTests.unity.meta
  16. 0
      /TestProjects/PerceptionURP/Assets/Scenes/ShaderTests.unity

4
TestProjects/PerceptionURP/Assets/Lit.mat


serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Texture: {fileID: 2800000, guid: 6c6d5e5cce7b447ca891dde4bcf949a2, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Texture: {fileID: 2800000, guid: 6c6d5e5cce7b447ca891dde4bcf949a2, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:

159
TestProjects/PerceptionURP/Assets/Scenes/ShaderTests.unity


m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &374759648
Transform:
m_ObjectHideFlags: 0

- Box
useAutoLabeling: 0
autoLabelingSchemeType:
--- !u!1 &1762131272
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1762131273}
- component: {fileID: 1762131277}
- component: {fileID: 1762131276}
- component: {fileID: 1762131275}
- component: {fileID: 1762131274}
- component: {fileID: 1762131278}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1762131273
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1762131272}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1833536665}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1762131274
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1762131272}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d362ce101173546a9b2047a832293571, type: 3}
m_Name:
m_EditorClassIdentifier:
useSegmentationMask: 1
segmentationMask: {fileID: 2800000, guid: 474275722ca6a4570bf9773fed7b079d, type: 3}
useMainTextureAsSegmask: 0
--- !u!65 &1762131275
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1762131272}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1762131276
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1762131272}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 75f5a99ef313c4df4abda96a22a5974f, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1762131277
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1762131272}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &1762131278
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1762131272}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8b33f0bc2b78db642a758f07826d0dd0, type: 3}
m_Name:
m_EditorClassIdentifier:
labels:
- Cube
useAutoLabeling: 0
autoLabelingSchemeType:
--- !u!1 &1800622449
GameObject:
m_ObjectHideFlags: 0

- {fileID: 1735358618}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1833536664
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1833536665}
m_Layer: 0
m_Name: Test6_CustomSegmentationMasksOpaqueOnly
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1833536665
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1833536664}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 75.8, y: 115.26736, z: -221.1}
m_LocalScale: {x: 10, y: 10, z: 10}
m_Children:
- {fileID: 1762131273}
m_Father: {fileID: 0}
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1956127314
GameObject:

14
TestProjects/PerceptionURP/Assets/testext.png.meta


textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
aniso: 0
mipBias: -100
wrapU: -1
wrapV: -1

platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1

1
TestProjects/PerceptionURP/Packages/manifest.json


"com.unity.package-validation-suite": "0.9.1-preview",
"com.unity.perception": "file:../../../com.unity.perception",
"com.unity.render-pipelines.universal": "7.3.1",
"com.unity.scripting.python": "4.0.0-exp.5",
"com.unity.simulation.capture": "0.0.10-preview.16",
"com.unity.simulation.core": "0.0.10-preview.21",
"com.unity.test-framework": "1.1.19",

7
TestProjects/PerceptionURP/Packages/packages-lock.json


"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.scripting.python": {
"version": "4.0.0-exp.5",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.shadergraph": {
"version": "7.3.1",
"depth": 1,

4
com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/Materials/SegmentationMaterial.mat


m_Offset: {x: 0, y: 0}
m_Floats:
- _AlphaClip: 1
- _BackTransparency: 0
- _BackTransparency: 0.08
- _Blend: 2
- _BlendOp: 0
- _BumpScale: 1

- _QueueOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _SegmentTransparency: 0.8
- _SegmentTransparency: 1
- _Shininess: 0
- _Smoothness: 0.5
- _SmoothnessSource: 0

5
com.unity.perception/Runtime/GroundTruth/Labeling/SemanticSegmentationBehaviour.cs


public class SemanticSegmentationBehaviour : MonoBehaviour
{
public bool enableTransparency = false;
public float opacityThreshold = 1;
//public bool enableTransparency = false;
//public float opacityThreshold = 1;
public bool useMainTextureAsSegmask = false;
}

22
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs


mpb.SetVector(k_SegmentationIdProperty, (Color)color);
Texture mainTex = null;
var maintex = renderer.material.GetTexture("_MainTex");
if (maintex)
mpb.SetTexture("_MainTex", renderer.material.GetTexture("_MainTex"));
mainTex = renderer.material.GetTexture("_MainTex");
// if (maintex)
// mpb.SetTexture("_MainTex", renderer.material.GetTexture("_MainTex"));
}
var segBeh = renderer? renderer.gameObject.GetComponent<SemanticSegmentationBehaviour>() : null;

{
mpb.SetFloat("_TextureIsSegmentationMask", 1);
if (segBeh.useSegmentationMask)
if (segBeh.useMainTextureAsSegmask)
if (mainTex == null)
Debug.LogError("No texture found on object");
else
mpb.SetTexture("_MainTex", mainTex);
}
else
}
mpb.SetFloat("_TransparencyThreshold", segBeh.opacityThreshold);
//mpb.SetFloat("_TransparencyThreshold", segBeh.opacityThreshold);
}
#if PERCEPTION_DEBUG

20
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs


// Set the labeling ID so that it can be accessed in ClassSemanticSegmentationPass.shader
mpb.SetVector(k_LabelingId, found ? entry.color : Color.black);
Texture mainTex = null;
var maintex = renderer.material.GetTexture("_MainTex");
if (maintex)
mpb.SetTexture("_MainTex", renderer.material.GetTexture("_MainTex"));
mainTex = renderer.material.GetTexture("_MainTex");
// if (maintex)
// mpb.SetTexture("_MainTex", renderer.material.GetTexture("_MainTex"));
}
mpb.SetColor("_BaseColor", renderer.material.color);
}

if (segBeh.useSegmentationMask)
{
mpb.SetFloat("_TextureIsSegmentationMask", 1);
if (segBeh.useSegmentationMask)
if (segBeh.useMainTextureAsSegmask)
mpb.SetTexture("_MainTex", segBeh.segmentationMask);
if (mainTex == null)
Debug.LogError("No texture found on object");
else
mpb.SetTexture("_MainTex", mainTex);
else
mpb.SetTexture("_MainTex", segBeh.segmentationMask);
mpb.SetFloat("_TransparencyThreshold", segBeh.opacityThreshold);
//mpb.SetFloat("_TransparencyThreshold", segBeh.opacityThreshold);
}
}

19
com.unity.perception/Runtime/GroundTruth/Resources/InstanceSegmentation.shader


{
_MainTex ("Texture", 2D) = "white" {}
_BaseColor("Color", Color) = (1,1,1,1)
_EnableTransparency ("Enable Transparency", Range(0,1)) = 1
_TransparencyThreshold ("Transparency Threshold", Range(0,1)) = 1
//_EnableTransparency ("Enable Transparency", Range(0,1)) = 1
//_TransparencyThreshold ("Transparency Threshold", Range(0,1)) = 1
_TextureIsSegmentationMask ("Use Texture as Segmentation Mask", Range(0,1)) = 0
[PerObjectData] _SegmentationId("Segmentation ID", vector) = (0,0,0,1)
}

sampler2D _MainTex;
fixed4 _BaseColor;
float4 _MainTex_ST;
float _TransparencyThreshold;
//float _TransparencyThreshold;
float _EnableTransparency;
//float _EnableTransparency;
struct appdata
{

return outColor;
}
float opacity = 1 * _BaseColor.a;
if (opacity < _TransparencyThreshold)
outColor.a = 0;
else
outColor.a = 1;
// float opacity = 1 * _BaseColor.a;
// if (opacity < _TransparencyThreshold)
// outColor.a = 0;
// else
// outColor.a = 1;
return outColor;
}
ENDCG

37
com.unity.perception/Runtime/GroundTruth/Resources/SemanticSegmentation.shader


{
_MainTex ("Texture", 2D) = "white" {}
_BaseColor("Color", Color) = (1,1,1,1)
_EnableTransparency ("Enable Transparency", Range(0,1)) = 1
_TransparencyThreshold ("Transparency Threshold", Range(0,1)) = 1
// _EnableTransparency ("Enable Transparency", Range(0,1)) = 1
// _TransparencyThreshold ("Transparency Threshold", Range(0,1)) = 1
_TextureIsSegmentationMask ("Use Texture as Segmentation Mask", Range(0,1)) = 0
[PerObjectData] LabelingId("Labeling Id", Vector) = (0,0,0,1)
}

SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
Tags { "RenderType"="Opaque" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
LOD 100

sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _BaseColor;
float _TransparencyThreshold;
//float _TransparencyThreshold;
//float _EnableTransparency;
struct in_vert
{

fixed4 semanticSegmentationFragmentStage (vertexToFragment vertScreenSpace) : SV_Target
{
fixed4 col = tex2D(_MainTex, vertScreenSpace.uv);
//LabelingId = _BaseColor;
// if (_TextureIsSegmentationMask == 1)
// {
// if (col.r == 0 && col.g == 0 && col.b == 0)
// outColor = fixed4(0,0,0,1);
//
// return outColor;
// }
if (_TextureIsSegmentationMask == 1)
{
if (col.r == 0 && col.g == 0 && col.b == 0)
outColor = fixed4(0,0,0,1);
return outColor;
}
//float opacity = col.a * _BaseColor.a;
float opacity = 2;
if (opacity < _TransparencyThreshold)
outColor.a = 0;
else
outColor.a = 1;
// //float opacity = col.a * _BaseColor.a;
// float opacity = 2;
// if (opacity < _TransparencyThreshold)
// outColor.a = 0;
// else
// outColor.a = 1;
return outColor;
}

693
TestProjects/PerceptionURP/Assets/treemask.png

之前 之后
宽度: 1024  |  高度: 1024  |  大小: 184 KiB

92
TestProjects/PerceptionURP/Assets/treemask.png.meta


fileFormatVersion: 2
guid: 474275722ca6a4570bf9773fed7b079d
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

8
com.unity.perception/Runtime/GroundTruth/Exporters.meta


fileFormatVersion: 2
guid: f8c42755c58494382a2a1001b293d4f9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

/TestProjects/PerceptionURP/Assets/Scenes/TransparencyTests.unity.meta → /TestProjects/PerceptionURP/Assets/Scenes/ShaderTests.unity.meta

/TestProjects/PerceptionURP/Assets/Scenes/TransparencyTests.unity → /TestProjects/PerceptionURP/Assets/Scenes/ShaderTests.unity

正在加载...
取消
保存