Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal webgpu
#define UNIFIED_RT_GROUP_SIZE_X 64
#define UNIFIED_RT_GROUP_SIZE_Y 1

#include "Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/FetchGeometry.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRay.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRayAndQueryHit.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/Common.hlsl"

#define QRNG_METHOD_SOBOL
#include "Packages/com.unity.render-pipelines.core/Runtime/Sampling/QuasiRandom.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Sampling/Common.hlsl"

Expand All @@ -32,7 +31,7 @@ void RayGenExecute(UnifiedRT::DispatchInfo dispatchInfo)

int probeId = dispatchInfo.globalThreadIndex;

QuasiRandomGenerator rngState;
QrngSobol rngState;
rngState.Init(uint2((uint)probeId, 0), _SampleId);

if (_SampleId==0)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ struct APVRTContext
static IRayTracingShader m_ShaderSO = null;
static IRayTracingShader m_ShaderRL = null;

const string k_PackageLightTransport = "Packages/com.unity.rendering.light-transport";
const string k_PackageLightTransport = "Packages/com.unity.render-pipelines.core";

internal AccelStructAdapter CreateAccelerationStructure()
{
Expand Down Expand Up @@ -713,7 +713,7 @@ public void BindSamplingTextures(CommandBuffer cmd)
m_SamplingResources.Load();
}

SamplingResources.BindSobolBlueNoiseTextures(cmd, m_SamplingResources);
SamplingResources.Bind(cmd, m_SamplingResources);
}

public bool TryGetMeshForAccelerationStructure(Renderer renderer, out Mesh mesh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ static AccelStructAdapter BuildAccelerationStructure()
Array.Fill(matIndices, renderer.component.renderingLayerMask); // repurpose the material id as we don't need it here
var perSubMeshMask = new uint[subMeshCount];
Array.Fill(perSubMeshMask, GetInstanceMask(renderer.component.shadowCastingMode));
accelStruct.AddInstance(renderer.component.GetInstanceID(), renderer.component, perSubMeshMask, matIndices, 1);
var perSubMeshIsOpaque = new bool[subMeshCount];
Array.Fill(perSubMeshIsOpaque, true);
accelStruct.AddInstance(renderer.component.GetInstanceID(), renderer.component, perSubMeshMask, matIndices, perSubMeshIsOpaque, 1);
}

foreach (var terrain in contributors.terrains)
{
uint mask = GetInstanceMask(terrain.component.shadowCastingMode);
uint materialID = terrain.component.renderingLayerMask; // repurpose the material id as we don't need it here
accelStruct.AddInstance(terrain.component.GetInstanceID(), terrain.component, new uint[1] { mask }, new uint[1] { materialID }, 1);
accelStruct.AddInstance(terrain.component.GetInstanceID(), terrain.component, new uint[1] { mask }, new uint[1] { materialID }, new bool[1] { true }, 1);
}

return accelStruct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,16 @@ static AccelStructAdapter BuildAccelerationStructure()
var matIndices = GetMaterialIndices(renderer.component);
var perSubMeshMask = new uint[subMeshCount];
Array.Fill(perSubMeshMask, GetInstanceMask(renderer.component.shadowCastingMode));
var perSubMeshIsOpaque = new bool[subMeshCount];
Array.Fill(perSubMeshIsOpaque, true);

accelStruct.AddInstance(renderer.component.GetInstanceID(), renderer.component, perSubMeshMask, matIndices, 1);
accelStruct.AddInstance(renderer.component.GetInstanceID(), renderer.component, perSubMeshMask, matIndices, perSubMeshIsOpaque, 1);
}

foreach (var terrain in contributors.terrains)
{
uint mask = GetInstanceMask(terrain.component.shadowCastingMode);
accelStruct.AddInstance(terrain.component.GetInstanceID(), terrain.component, new uint[1] { mask }, new uint[1] { 0 }, 1);
accelStruct.AddInstance(terrain.component.GetInstanceID(), terrain.component, new uint[1] { mask }, new uint[1] { 0 }, new bool[1] { true }, 1);
}

return accelStruct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ static AccelStructAdapter BuildAccelerationStructure(int mask)
int subMeshCount = mesh.subMeshCount;
var maskAndMatDummy = new uint[subMeshCount];
System.Array.Fill(maskAndMatDummy, 0xFFFFFFFF);
var isOpaqueDummy = new bool[subMeshCount];
System.Array.Fill(isOpaqueDummy, true);

accelStruct.AddInstance(renderer.component.GetInstanceID(), renderer.component, maskAndMatDummy, maskAndMatDummy, 1);
accelStruct.AddInstance(renderer.component.GetInstanceID(), renderer.component, maskAndMatDummy, maskAndMatDummy, isOpaqueDummy, 1);
}

foreach (var terrain in contributors.terrains)
Expand All @@ -153,7 +155,7 @@ static AccelStructAdapter BuildAccelerationStructure(int mask)
if ((layerMask & mask) == 0)
continue;

accelStruct.AddInstance(terrain.component.GetInstanceID(), terrain.component, new uint[1] { 0xFFFFFFFF }, new uint[1] { 0xFFFFFFFF }, 1);
accelStruct.AddInstance(terrain.component.GetInstanceID(), terrain.component, new uint[1] { 0xFFFFFFFF }, new uint[1] { 0xFFFFFFFF }, new bool[1] { true }, 1);
}

return accelStruct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
#include "Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ShaderVariablesProbeVolumes.cs.hlsl"

#include "Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/FetchGeometry.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRay.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRayAndQueryHit.hlsl"

#define QRNG_METHOD_SOBOL
#define SAMPLE_COUNT 32
#define RAND_SAMPLES_PER_BOUNCE 2
#include "Packages/com.unity.render-pipelines.core/Runtime/Sampling/QuasiRandom.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Sampling/Common.hlsl"

Expand All @@ -27,7 +25,7 @@ void RayGenExecute(UnifiedRT::DispatchInfo dispatchInfo)
ray.tMax = FLT_MAX;
ray.tMin = 0.0f;

QuasiRandomGenerator rngState;
QrngSobol rngState;
rngState.Init(0, SAMPLE_COUNT);

int4 hitCount = 0;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;

namespace UnityEditor.Rendering.UnifiedRayTracing
{
internal class ShaderTemplates
{
[MenuItem("Assets/Create/Shader/Unified Ray Tracing Shader", false, 1)]
internal static void CreateNewUnifiedRayTracingShader()
{
var action = ScriptableObject.CreateInstance<DoCreateUnifiedRayTracingShader>();
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, action, "NewUnifiedRayTracingShader.urtshader", null, null);
}

internal class DoCreateUnifiedRayTracingShader : EndNameEditAction
{
public override void Action(int instanceId, 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/TraceRay.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
}

}
";
}
}


Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using UnityEditor.AssetImporters;
using System.IO;

namespace UnityEditor.Rendering.UnifiedRayTracing
{
[ScriptedImporter(1, "urtshader")]
internal class UnifiedRTShaderImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
string source = File.ReadAllText(ctx.assetPath);

var com = ShaderUtil.CreateComputeShaderAsset(ctx, computeShaderTemplate.Replace("SHADERCODE", source));
var rt = ShaderUtil.CreateRayTracingShaderAsset(ctx,
raytracingShaderTemplate.Replace("SHADERCODE", source));

ctx.AddObjectToAsset("ComputeShader", com);
ctx.AddObjectToAsset("RayTracingShader", rt);
ctx.SetMainObject(com);
}

const string computeShaderTemplate =
"#define UNIFIED_RT_BACKEND_COMPUTE\n" +
"SHADERCODE\n" +
"#include_with_pragmas \"Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/Compute/ComputeRaygenShader.hlsl\"\n";

const string raytracingShaderTemplate =
"#define UNIFIED_RT_BACKEND_HARDWARE\n" +
"SHADERCODE\n" +
"#include_with_pragmas \"Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/Hardware/HardwareRaygenShader.hlsl\"\n";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Unity.Rendering.LightTransport.Editor",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Packages/com.unity.render-pipelines.core/Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@
[assembly: InternalsVisibleTo("Unity.RenderPipelines.Core.Runtime.Tests")]
[assembly: InternalsVisibleTo("Unity.GraphicTests.Performance.RPCore.Runtime")]
[assembly: InternalsVisibleTo("Unity.GraphicTests.Performance.Universal.Runtime")] // access to internal ProfileIds

// Access to SamplingResources for the PathTracing package, to be removed when its content will be moved to RP Core
[assembly: InternalsVisibleTo("Unity.Rendering.PathTracing.Runtime.Tests")]
[assembly: InternalsVisibleTo("Unity.PathTracing.Runtime.Tests")]
[assembly: InternalsVisibleTo("Unity.PathTracing.Editor.Tests")]
[assembly: InternalsVisibleTo("Unity.PathTracing.Runtime")]
[assembly: InternalsVisibleTo("Unity.PathTracing.Editor")]

// Smoke test project visibility
[assembly: InternalsVisibleTo("SRPSmoke.Runtime")]
[assembly: InternalsVisibleTo("SRPSmoke.Runtime.Tests")]
[assembly: InternalsVisibleTo("SRPSmoke.Editor.Tests")]
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor-testable")]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#define _SAMPLING_SAMPLING_COMMON_HLSL_

#ifndef PI
#define PI 3.141592653589f
#define PI 3.14159265358979323846f
#endif

#define FLOAT_ONE_MINUS_EPSILON 0.99999994

// Paper: Building an Orthonormal Basis, Revisited.
// Tom Duff, James Burgess, Per Christensen, Christophe Hery, Andrew Kensler, Max Liani, and Ryusuke Villemin (Pixar).
// https://graphics.pixar.com/library/OrthonormalB/paper.pdf
Expand Down Expand Up @@ -111,7 +113,7 @@ float PowerHeuristic(float f, float b)

float UintToFloat01(uint x)
{
return x * 2.3283064365386963e-10; // (1.f / (1ULL << 32));
return min(x * 2.3283064365386963e-10, FLOAT_ONE_MINUS_EPSILON); // (1.f / (1ULL << 32));
}

int Log2Int(uint v)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,9 @@ uint4 Pcg4d(uint4 v)
return v;
}

uint PixelHash(uint2 pixelCoord, uint seed = 0)
{
return LowBiasHash32((pixelCoord.x & 0xFFFF) | (pixelCoord.y << 16), seed);
}

#endif // _SAMPLING_HASHES_HLSL_

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading