steaklive / DXR-Sandbox-GI

Simple DirectX 12 toy framework for testing Global Illumination: Reflective Shadow Mapping, Light Propagation Volume, Voxel Cone Tracing, DXR
71 stars 7 forks source link

i have some questions about the project #7

Closed Xiyinyue closed 1 year ago

Xiyinyue commented 1 year ago

Sorry,it's my first time to use github,i don't know what the comment will affect you . but i have some questions about it .In LPVpropagation.hlsl

VS_OUT VSMain(VS_IN input)
{
    VS_OUT output = (VS_OUT) 0;

    if (input.vertex == 0)
        output.screenPos.xy = float2(-1.0, 1.0);
    else if (input.vertex == 1)
        output.screenPos.xy = float2(3.0, 1.0);
    else
        output.screenPos.xy = float2(-1.0, -3.0);

    output.screenPos.zw = float2(0.0, 1.0);
    output.depthIndex = input.depthIndex;

    return output;
}

[maxvertexcount(3)]
void GSMain(triangle VS_OUT input[3], inout TriangleStream<GS_OUT> OutputStream)
{
    for (int i = 0; i < 3; i++)
    {
        GS_OUT output = (GS_OUT)0;
        output.depthIndex = input[i].depthIndex;
        output.screenPos = input[i].screenPos;

        OutputStream.Append(output);
    }
}
PS_OUT PSMain(GS_OUT input)
{
    PS_OUT output = (PS_OUT) 0;

    int4 cellIndex = int4(input.screenPos.xy - 0.5f, input.depthIndex, 0);
    SHContribution resultContribution = GetSHGatheringContribution(cellIndex);

    output.redSH = resultContribution.red;
    output.greenSH = resultContribution.green;
    output.blueSH = resultContribution.blue;

    output.acc_redSH = resultContribution.red;
    output.acc_greenSH = resultContribution.green;
    output.acc_blueSH = resultContribution.blue;

    return output;
}

i don't know why the value of screenPos is [-1,3] and whatever any small counts,and then I open renderdoc,I saw it became [0-32] when i open any pixel's debugging. there is no change for screenPos,the 32 Instance have the same screenpos,how can i identify 323232 volume for only one depthIndex

steaklive commented 1 year ago

@Xiyinyue hello! I will try to explain what is happening here.

1) The "[-1,3]" you mentioned. Basically, it is a trick to render a quad (which is a slice of our propagation volume) only with 3 vertices by drawing a bigger triangle which is then "clipped" to a quad. This is efficient and common in full screen passes (we kinda have a fullscreen pass if we think from the "volume" perspective because its our render target). Here is a more detailed explanation: https://stackoverflow.com/questions/2588875/whats-the-best-way-to-draw-a-fullscreen-quad-in-opengl-3-2

2) I am not sure I am following your "there is no change for screenPos". SV_Position semantic which stores our screenPos in shader has to be in normalized coordinates; the pixel shader then receives screenPos which was automatically prepared/converted to pixel coordinates (thus [0,32] range which is the dimension of our volume).

In RenderDoc if you select a slice in the texture view and then debug a pixel from that slice, you should see proper values in shader debug (screenPos in [0,32], depthIndex = slice).

I hope it answers your questions. If you have more, feel free to ask!