-
Notifications
You must be signed in to change notification settings - Fork 869
Expand file tree
/
Copy pathCreateUnifiedRTShaderMenuItem.cs
More file actions
58 lines (47 loc) · 1.91 KB
/
CreateUnifiedRTShaderMenuItem.cs
File metadata and controls
58 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
namespace UnityEditor.Rendering.UnifiedRayTracing
{
internal class ShaderTemplates
{
internal static readonly Texture2D shaderIcon = EditorGUIUtility.IconContent("d_TextAsset Icon").image as Texture2D;
[MenuItem("Assets/Create/Shader/Unified Ray Tracing Shader", false, 1)]
internal static void CreateNewUnifiedRayTracingShader()
{
var action = ScriptableObject.CreateInstance<DoCreateUnifiedRayTracingShader>();
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(EntityId.None, action, "NewUnifiedRayTracingShader.urtshader", shaderIcon, null);
}
internal class DoCreateUnifiedRayTracingShader : AssetCreationEndAction
{
public override void Action(EntityId entityId, string pathName, string resourceFile)
{
string fullPath = Path.GetFullPath(pathName);
File.WriteAllText(fullPath, shaderContent);
AssetDatabase.ImportAsset(pathName);
var shader = AssetDatabase.LoadAssetAtPath(pathName, typeof(Object));
ProjectWindowUtil.ShowCreatedAsset(shader);
}
}
const string shaderContent =
@"#include ""Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRayAndQueryHit.hlsl""
UNIFIED_RT_DECLARE_ACCEL_STRUCT(_AccelStruct);
void RayGenExecute(UnifiedRT::DispatchInfo dispatchInfo)
{
// Example code:
UnifiedRT::Ray ray;
ray.origin = 0;
ray.direction = float3(0, 0, 1);
ray.tMin = 0;
ray.tMax = 1000.0f;
UnifiedRT::RayTracingAccelStruct accelStruct = UNIFIED_RT_GET_ACCEL_STRUCT(_AccelStruct);
UnifiedRT::Hit hitResult = UnifiedRT::TraceRayClosestHit(dispatchInfo, accelStruct, 0xFFFFFFFF, ray, 0);
if (hitResult.IsValid())
{
// Handle found intersection
}
}
";
}
}