浏览代码

Updating shader to use PackageRequirements

/keypoint_self_occlusion_2020_3
Jon Hogins 3 年前
当前提交
78b4c1fb
共有 2 个文件被更改,包括 78 次插入43 次删除
  1. 80
      com.unity.perception/Editor/GroundTruth/ShaderPreprocessor.cs
  2. 41
      com.unity.perception/Runtime/GroundTruth/Resources/KeypointDepthCheck.shader

80
com.unity.perception/Editor/GroundTruth/ShaderPreprocessor.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Perception.GroundTruth
{
public class ShaderPreprocessor : IPreprocessShaders
{
private string[] shadersToPreprocess = new[]
{
"Perception/KeypointDepthCheck"
};
public int callbackOrder => 0;
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
{
if (!shadersToPreprocess.Contains(shader.name))
return;
var hdrpKeyword = new ShaderKeyword(shader, "HDRP_ENABLED");
#if HDRP_PRESENT || URP_PRESENT
#if HDRP_PRESENT
bool isHdrp = true;
#else
bool isHdrp = false;
#endif
for (var i = data.Count - 1; i >= 0; --i)
{
if (data[i].shaderKeywordSet.IsEnabled(hdrpKeyword) == isHdrp)
continue;
data.RemoveAt(i);
}
#endif
}
}
}
// using System.Collections.Generic;
// using System.Linq;
// using UnityEditor.Build;
// using UnityEditor.Rendering;
// using UnityEngine;
// using UnityEngine.Rendering;
//
// namespace UnityEditor.Perception.GroundTruth
// {
// public class ShaderPreprocessor : IPreprocessShaders
// {
// private string[] shadersToPreprocess = new[]
// {
// "Perception/KeypointDepthCheck"
// };
// public int callbackOrder => 0;
// public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
// {
// if (!shadersToPreprocess.Contains(shader.name))
// return;
//
// var hdrpKeyword = new ShaderKeyword(shader, "HDRP_ENABLED");
// #if HDRP_PRESENT || URP_PRESENT
//
// #if HDRP_PRESENT
// bool isHdrp = true;
// #else
// bool isHdrp = false;
// #endif
// for (var i = data.Count - 1; i >= 0; --i)
// {
// if (data[i].shaderKeywordSet.IsEnabled(hdrpKeyword) == isHdrp)
// continue;
//
// data.RemoveAt(i);
// }
// #endif
// }
// }
// }

41
com.unity.perception/Runtime/GroundTruth/Resources/KeypointDepthCheck.shader


{
Pass
{
PackageRequirements {
"com.unity.render-pipelines.highdefinition"
}
Tags { "LightMode" = "SRP" }
Name "KeypointDepthCheck"

Texture2D _Positions;
Texture2D _KeypointCheckDepth;
#if HDRP_ENABLED
#pragma enable_d3d11_debug_symbols
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl"

uint result = depth >= checkDepth ? 1 : 0;
return float4(result, result, result, 1);
}
#else
ENDHLSL
}
Pass
{
PackageRequirements {
"com.unity.render-pipelines.universal"
}
Tags { "LightMode" = "SRP" }
Name "KeypointDepthCheck"
ZWrite Off
ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
HLSLPROGRAM
#pragma only_renderers d3d11 vulkan metal
#pragma target 4.5
#pragma vertex Vert
#pragma fragment Frag
static const float2 checkOffsets[9] = {
float2( 0, 0),
float2(-1, -1),
float2( 0, -1),
float2( 1, -1),
float2(-1, 0),
float2( 1, 0),
float2(-1, 1),
float2( 0, 1),
float2( 1, 1)};
Texture2D _Positions;
Texture2D _KeypointCheckDepth;
#include "UnityCG.cginc"
//copied from UnityInput.hlsl

uint result = depthVSActual >= depthVSToCheck ? 1 : 0;
return float4(result, result, result, 1);
}
#endif
ENDHLSL
}
}
正在加载...
取消
保存