5

私は(無駄に)OpenGLとNVIDIAのCgシェーダーシステムを使用してMRTをセットアップしようとしていますが、最終的な目標は遅延レンダリングです。単一のターゲットに対してシェーダーとRenderToTextureの両方を正常に機能させることができましたが、オブジェクトを複数のレンダリングターゲットにレンダリングしようとすると、いずれのターゲットにも表示されません。

フレームバッファオブジェクトを次のように設定しています。

// Initialize textures
// (I'll spare you the code since I've  done that without issues)

// Initialize the FBO
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glGenRenderbuffers(1, &depthBuff);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuff);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                          GL_RENDERBUFFER, depthBuff);

// -snip-

// Bind each texture we want to use to the FBO at rtNum
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + rtNum,
                       GL_TEXTURE_2D, tex->getID(), 0);
// Check to make sure we're good to go
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
    throw Exceptions::GLException("Frame buffer object is not complete.",
                                __FUNCTION__);
}

// -snip-

// Call glDrawBuffers with the RTs we want to render to
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
unique_ptr<GLenum[]> arr(new GLenum[num]);
for (size_t c = 0; c < num; ++c)
    arr[c] = GL_COLOR_ATTACHMENT0 + c;
glDrawBuffers(num, arr.get());
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
    throw Exceptions::GLException("Frame buffer object is not complete.",
                                __FUNCTION__);

// -snip-

// Set up the FBO for rendering
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Draw calls here

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glPopAttrib();

私のシェーダー(によって返されるプロファイルを使用してコンパイルされますcgGLGetLatestProfile)は次のとおりです。

struct VertexShaderOutput {
    float4 position : POSITION;
    float3 normal : TEXCOORD0;
    float4 color : COLOR;
};

VertexShaderOutput VS_Main(float4 local : POSITION,
                        float4 normal : NORMAL,
                        float4 color : COLOR,
                        uniform float4x4 modelViewProj,
                        uniform float4x4 modelViewIT)
{
    VertexShaderOutput OUT;
    OUT.position = mul(modelViewProj, local);
    OUT.normal= mul(modelViewIT, normal).xyz;
    OUT.color = color;
    return OUT;
}

struct FragmentShaderOutput {
    float4 unlit : COLOR0;
    float4 normAndDepth : COLOR1;
};

FragmentShaderOutput FS_Main(VertexShaderOutput vsOut)
{
    FragmentShaderOutput OUT;
    OUT.unlit = float4(1.0f, 1.0f, 0.0f, 1.0f);//vsOut.color;
    OUT.normAndDepth.rgb = vsOut.normal;
    // Calculate depth later
    OUT.normAndDepth.a = 1.0f;
    return OUT;
}

なぜこれが失敗するのかについて誰かが何か手がかりを持っていますか?

4

1 に答える 1

2

上記の方法は正しいです。問題は、ハードウェアとCgの組み合わせにあるようです。チップセットが統合された私のラップトップでは、Cgがエラーを返さないにもかかわらず、MRTが失敗し、他の多くのシェーダー関連の問題が発生します。GeForce GTX260を搭載したデスクトップマシンでは、すべてが完全に機能します。

于 2012-05-02T02:51:09.447 に答える