1

つまり、実際のゲームアートを FBO の 1 つのカラーバッファーにレンダリングし、対応する法線を FBO の別のカラーバッファーにレンダリングします。

(基本的には、複数のレンダー ターゲットを使用して、これこれを作成したいと考えています。)

私の問題は、何もレンダリングされていないか、正しくレンダリングされていないかのように、最終出力が空白であることです。


私のシェーダー (頂点とフラグメント)

画面に有効にして(FBOではなく)いくつかのスプライトを完全に正常にレンダリングすると、レンダリングされるため、これはうまくいくと確信しています。

#version 150

in vec4 a_position;
in vec4 a_color;
in vec2 a_texCoord0;

uniform mat4 u_projTrans;

out vec4 v_color;
out vec2 v_texCoords;

void main()
{
   v_color = a_color;
   v_color.a = v_color.a * (255.0/254.0);
   v_texCoords = a_texCoord0;
   gl_Position =  u_projTrans * a_position;
}



#version 150

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif

in LOWP vec4 v_color;
in vec2 v_texCoords;

uniform sampler2D u_texture;
uniform sampler2D u_normal;

out vec4 fragColor;

void main()
{
    gl_FragData[0] = v_color * texture(u_texture, v_texCoords);
    gl_FragData[1] = texture(u_normal, v_texCoords);
}

次のコードはレンダリング ループにあります。

基本的な考え方は、FBO の 2 つのカラー バッファーを glDrawBuffers でバインドすることです。次に、ゲーム アートと通常のゲーム アートの 2 つのテクスチャ ユニットをバインドします。上記のシェーダーは、これを受け取り、ゲーム アートを 1 つのカラー バッファーに出力し、対応する通常アートを別のカラー バッファーに出力することになっています。

// Position the camera.
_cameraRef.position.set(_stage.getWidth() * 0.5f, _stage.getHeight() * 0.5f, 0);

// Update the camera, SpriteBatch, and map renderer.
_cameraRef.update();
_spriteBatch.setProjectionMatrix(_cameraRef.combined);
_mapRenderer.setView(_cameraRef);       

// Bind the color texture units of the FBO (multiple-render-targets).
Gdx.gl30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _gBufferFBOHandle);
IntBuffer intBuffer = BufferUtils.newIntBuffer(2);
intBuffer.put(GL30.GL_COLOR_ATTACHMENT0);
intBuffer.put(GL30.GL_COLOR_ATTACHMENT1);
Gdx.gl30.glDrawBuffers(2, intBuffer);

// Draw!
Gdx.gl30.glClearColor(0, 0, 0, 1);
Gdx.gl30.glClear(GL30.GL_COLOR_BUFFER_BIT);

_spriteBatch.setShader(_shaderGBuffer);
_spriteBatch.begin();

_tilesAtlasNormal.bind(1); // Using multiple texture units to draw art and normals at same time to the two color buffers of the FBO.
_tilesAtlas.bind(0);
_mapRenderer.renderTileLayer(_mapLayerBackground);

_spriteBatch.end();
_spriteBatch.setShader(null);

// Bind the default FBO.
Gdx.gl30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

// Draw the contents of the FBO onto the screen to see what it looks like.
Gdx.gl30.glClearColor(0, 0, 0, 1);
Gdx.gl30.glClear(GL30.GL_COLOR_BUFFER_BIT);

_spriteBatch.begin();
_spriteBatch.draw(_gBufferTexture1, 0.0f, 0.0f);  // <-- This texture is blank? It's the texture that was just rendered to above.
_spriteBatch.end();

私が言ったように、最終出力は空白です。glCheckFramebufferStatus で確認したので、作成した FBO は有効であると確信しています。

そのFBOからカラーテクスチャを取得して画面に描画すると、空白になります。どこが間違っているのかわかりません。

任意の入力に感謝します。

4

2 に答える 2

0

intbuffer を巻き戻すことを忘れないでください:

IntBuffer intBuffer = BufferUtils.newIntBuffer(2);
intBuffer.put(GL30.GL_COLOR_ATTACHMENT0);
intBuffer.put(GL30.GL_COLOR_ATTACHMENT1);

intBuffer.rewind();
于 2016-09-09T00:57:51.327 に答える