0
$\begingroup$

Hi I want to create a ray generation shader which traces rays inside a box frustum given by an Orthographic projection matrix(XMMatrixOrthographicLH) I use the following ray generation shader code:

struct RTConstants
{

    matrix invproj;
};

struct Simpleraypayload
{
    float3 outcol;
};
RWTexture2D<float4> outtex: register(u0);
RaytracingAccelerationStructure basicas:register(t0);
ConstantBuffer<RTConstants> rtconsts:register(b0);
[shader("raygeneration")]
void rgsmain()
{
Simpleraypayload payload;
payload.outcol=float3(0.0f,0.0f,0.0f);
RayDesc ray;


ray.TMin=0.001f;
ray.TMax=10.0f;
ray.Direction=float3(0.0f,0.0f,-1.0f);
    uint3 rayidx=DispatchRaysIndex();
    uint3 raydims=DispatchRaysDimensions();
    float2 clippointxy=rayidx.xy/float2(raydims.xy);
    clippointxy=(clippointxy*2.0f)-float2(1.0f,1.0f);
    float4 clippointnear=float4(clippointxy,0.0f,1.0f);
    clippointnear=mul(rtconsts.invproj,clippointnear);clippointnear=clippointnear/clippointnear.w;
    float4 clippointfar=float4(clippointxy,1.0f,1.0f);
    clippointfar=mul(rtconsts.invproj,clippointfar);clippointfar=clippointfar/clippointfar.w;
    ray.Origin=clippointnear.xyz;
    ray.Direction=normalize(clippointfar.xyz-clippointnear.xyz);
    TraceRay(basicas,RAY_FLAG_NONE,0xFF,0,0,0,ray,payload);
    //flipping the output.
    uint2 outindex=uint2(rayidx.x,raydims.y-rayidx.y);
    
    outtex[outindex]=float4(payload.outcol,1.0f);
}

here "invproj" is the inverse of the ortho projection matrix for which we are trying to shootrays for.Am I right in using this rgs shader code for tracing all possible rays inside the frustum represented by the ortho matrix whose inverse I am using here?I have tested it for ortho projection only though.

$\endgroup$

1 Answer 1

0
$\begingroup$

Yes the raygen shader used here is correct for shooting rays inside the frustum given by the projection matrix(whose inverse is used here).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.