- Home /
Where do I put this shader code? Getting weird error?
I'm trying to test out the DirectX 12 API in a .raytrace shader. Here's the Ray generation and miss shader:
#pragma max_recursion_depth 1
RWTexture2D<float4> Result;
RaytracingAccelerationStructure sceneAccelStruct;
float4x4 _CameraToWorld;
float4x4 _CameraInverseProjection;
float TMin = 0.0f;
float TMax = 1e38f;
struct SimpleRayPayload
{
float3 color;
};
RayDesc CreateRay(float2 uv)
{
RayDesc ray;
ray.Origin = mul(_CameraToWorld, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz;
ray.Direction = normalize(mul(_CameraToWorld, float4(mul(_CameraInverseProjection, float4(uv, 0.0f, 1.0f)).xyz, 0.0f)).xyz);
ray.TMin = TMin;
ray.TMax = TMax;
return ray;
}
[shader("raygeneration")]
void RayGenerationShader()
{
uint2 curPixel = DispatchRaysIndex().xy;
uint2 totalPixels = DispatchRaysDimensions().xy;;
float2 pixelCenter = (curPixel + float2(0.5f, 0.5f)) / totalPixels;
float2 uv = float2(2, -2) * pixelCenter + float2(-1, 1);
RayDesc ray = CreateRay(uv);
SimpleRayPayload payload = { float3(0,0,0) };
TraceRay(sceneAccelStruct, RAY_FLAG_NONE, 0xFF, 0, 1, 0, ray, payload);
Result[curPixel] = float4(payload.color, 1.0f);
}
[shader(“miss”)]
void RayMiss(inout SimpleRayPayload data)
{
data.color = float3(0, 0, 1);
}
[shader(“closesthit”)]
void RayClosestHit(inout SimpleRayPayload data, BuiltinIntersectionAttribs attribs)
{
data.color = float3(1, 0, 0);
}
which i pieced together using the following links:
http://intro-to-dxr.cwyman.org/presentations/IntroDXR_RaytracingShaders.pdf
My project is setup with the HDRP and the Graphics API is set to use DirectX 12 as the first priority option.
Here's the error i see in the editor:
Am I supposed to be putting the miss ./ closest hit shaders somewhere else?
Answer by TheLazyEngineer · Sep 01, 2020 at 04:37 AM
Ok, so this is funny... the error in the image is actually from copy and pasting code. The quotations in the miss shader attribute (line 40) aren't actually quotation marks!!! hahaha wow!
But anyway.. does anyone have a demo project of writing custom raytracing shaders all the way from raygeneration shader to the intersection, anyhit, closesthit, and miss shaders? Would be very helpful!