xna - Pix,有几个问题我不明白

标签 xna shader hlsl

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

HLSL and Pix number of questions

我认为两个和三个都适契约(Contract)一个问题,因为其中一个的解决方案可能有助于解决另一个问题。我正在尝试调试着色器,但似乎遇到了问题。首先,当我运行分析模式时,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 进行实时调试吗?我想知道这种方法是否会揭示更多信息。

干杯,

最佳答案

看起来大部分着色器代码都已被优化(未编译,因为它不相关)。

最后,最重要的是 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 < 1从一开始就是 false(i 的起始值为 1)。

希望有帮助!

<小时/>

为了回答你的第二个问题,我相信要实时调试着色器,你需要使用像 Nvidia 的 FX Composer 这样的东西。和 Shader Debugger 。然而,它们在游戏之外运行,因此结果并不总是有用。

关于xna - Pix,有几个问题我不明白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14774438/

相关文章:

c# - XNA : How to use double value within Draw() method instead of float to get precise rotation?

c# - Monogame 中 base.Update 和 base.Draw 的功能?

opengl-es - 从 OpenGL ES 2.0 着色器返回值

c++ - OpenGL/GLSL - 统一 block 数据值不正确

c# - 将 C 翻译成 C# 和 HLSL : will this be possible?

opengl - GLSL 中的 HLSL cbuffer 等效项

xna - 如何在 xna 中设置窗口/屏幕尺寸?

opengl - 什么是 OpenGL 中的着色器,我们需要它们做什么?

c++ - Direct3D 11 CreatePixelShader (E_INVLIDARGS)

c# - 在表单中打开文件,未处理 ThreadStateException