【问题标题】:Pix, A couple of issues I'm not understandingPix,我不明白的几个问题
【发布时间】:2013-02-08 14:11:51
【问题描述】:

我被要求拆分我在这里提出的问题:

HLSL and Pix number of questions

我认为两个和三个都适合同一个问题,因为其中一个的解决方案可能有助于解决另一个问题。我正在尝试调试着色器,但似乎遇到了问题。首先,当我运行分析模式时,Pix 似乎跳过了大量代码。这是分析 F12 捕获和关闭 D3DX 分析的实验。我在使用 XNA 时必须将其关闭。有问题的着色器代码如下:

float4 PixelShaderFunction(float2 OriginalUV : TEXCOORD0) : COLOR0
{   

    // Get the depth buffer value at this pixel.  
    float4 color = float4 (0, 0,0,0);
    float4 finalColor = float4(0,0,0,0);

    float zOverW = tex2D(mySampler, OriginalUV);  
    // H is the viewport position at this pixel in the range -1 to 1.  
    float4 H = float4(OriginalUV.x * 2 - 1, (1 - OriginalUV.y) * 2 - 1,  
    zOverW, 1);  
    // Transform by the view-projection inverse.  
    float4 D = mul(H, xViewProjectionInverseMatrix);  
    // Divide by w to get the world position.  
    float4 worldPos = D / D.w;  

    // Current viewport position  
    float4 currentPos = H;  
    // Use the world position, and transform by the previous view-  
    // projection matrix.  
    float4 previousPos = mul(worldPos, xPreviousViewProjectionMatrix);  
    // Convert to nonhomogeneous points [-1,1] by dividing by w.  
    previousPos /= previousPos.w;  
    // Use this frame's position and last frame's to compute the pixel  
       // velocity.  
    float2 velocity = (currentPos - previousPos)/2.f;  

    // Get the initial color at this pixel.  
    color = tex2D(sceneSampler, OriginalUV);  
    OriginalUV += velocity;  
    for(int i = 1; i < 1; ++i, OriginalUV += velocity)  
    {  
        // Sample the color buffer along the velocity vector.  
        float4 currentColor = tex2D(sceneSampler, OriginalUV);  
        // Add the current color to our color sum.  
        color += currentColor;  
    } 
    // Average all of the samples to get the final blur color.  
    finalColor = color / xNumSamples;  


    return finalColor;
}

使用捕获的帧并在调试像素时,我只能看到两行工作。它们是 color = tex2D(sceneSampler, OriginalUV) 和 finalColor = color / xNumSamples。其余的 Pix 只是跳过或不做。

我还可以使用 Pix 进行实时调试吗?我想知道这种方法是否会揭示更多信息。

干杯,

【问题讨论】:

    标签: xna shader hlsl


    【解决方案1】:

    看起来大部分着色器代码正在被优化(未编译,因为它无关紧要)。

    最后,finalColor 的返回值才是最重要的,它由colorxNumSamples 设置。

    // Average all of the samples to get the final blur color.  
    finalColor = color / xNumSamples; 
    

    我不确定xNumSamples 的设置位置,但您可以看到,与color 相关的唯一行是color = tex2D(sceneSampler, OriginalUV);(因此不会被删除)。

    之前的每一行都无关紧要,因为它将被该行覆盖。

    唯一的一点是for循环:

    for(int i = 1; i < 1; ++i, OriginalUV += velocity)  
    

    但这永远不会执行,因为i &lt; 1 从一开始就是假的(我被分配了一个起始值 1)。

    希望有帮助!


    要回答您的第二个问题,我认为要实时调试着色器,您需要使用 Nvidia 的 FX ComposerShader Debugger 之类的东西。但是,它们在您的游戏之外运行,因此结果并不总是有用的。

    【讨论】:

    • 好的,我认为 for 循环线是我在摆弄东西,所以我忘记了将值切换回来。我基本上是在尝试实现此处找到的运动模糊效果:http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html 我已尝试尽可能多地复制此方法,但我担心编译器是否正在对其进行优化,这种方法是不可能的。
    • 修复循环后不应该删除上面的行;它在循环中使用该数据。修复循环后您还有问题吗?
    • 啊,好吧,你是对的,我现在似乎得到了某种效果,所以可能可以从那里解决。干杯
    猜你喜欢
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 2020-06-20
    • 2012-03-18
    相关资源
    最近更新 更多