2

これは私の最後の質問に関連しています。この画像を取得するには:

http://img252.imageshack.us/img252/623/picture8z.png

  1. 白い背景を描きます(color = (1, 1, 1, 1))。

  2. color =とblend関数を使用して左上の2つの正方形をテクスチャにレンダリングしてから、color=(1, 0, 0, .8)とblend関数(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)を使用してテクスチャを描画し(1, 1, 1, 1)ます(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)

  3. 右下の正方形をcolor=(1, 0, 0, .8)とblend関数で描画します(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

私の計算では、テクスチャへのレンダリングの正方形は色を持っている必要があります

.8 * (1, 0, 0, .8) + (1 - .8) * (0, 0, 0, 0) = (.8, 0, 0, .64)

そのため、白い背景にそのテクスチャを描画した後、色を付ける必要があります

(.8, 0, 0, .64) + (1 - .8) * (1, 1, 1, 1) = (1, .2, .2, .84)

右下の正方形は色が付いているはずです

.8 * (1, 0, 0, .8) + (1 - .8) * (1, 1, 1, 1) = (1, .2, .2, .84)

同じように見えるはずです!私の推論は間違っていますか?私の計算は間違っていますか?

いずれにせよ、私の目標は私のシーンの一部をキャッシュすることです。テクスチャにレンダリングしてからそのテクスチャを描画して、シーンをインラインで描画するのと同じようにするにはどうすればよいですか?

4

3 に答える 3

4

If you want to render blended content to a texture and composite that texture to the screen, the simplest way is to use premultiplied alpha everywhere. It’s relatively simple to show that this works for your case: the color of your semi-transparent squares in premultiplied form is (0.8, 0, 0, 0.8), and blending this over (0, 0, 0, 0) with (GL_ONE, GL_ONE_MINUS_SRC_ALPHA) essentially passes your squares’ color through to the texture. Blending (0.8, 0, 0, 0.8) over opaque white with (GL_ONE, GL_ONE_MINUS_SRC_ALPHA) gives you (1.0, 0.2, 0.2, 1.0). Note that the color channels are the same as your third calculation, but the alpha channel is still 1.0, which is what you would expect for an opaque object covered by a blended object.

Tom Forsyth has a good article about premultiplied alpha. The whole thing is worth reading, but see the “Compositing translucent layers” section for an explanation of why the math works out in the general case.

于 2009-08-23T17:04:10.080 に答える
0

おっと、私の計算は間違っています!2行目は

(.8, 0, 0, .64) + (1 - .64) * (1, 1, 1, 1) = (1, .36, .36, .84)

これは確かに私が見ているものと一致しているようです(最後の正方形を色に変更すると(1, .2, .2, .8)、3つの正方形すべてが同じ色で表示されます)。

于 2009-08-23T00:25:39.293 に答える
0

最後の質問について:シーンの一部をテクスチャに置き換えるのは簡単ではありません。良い出発点は、ステファン・イエシュケの博士論文です。

于 2009-08-23T01:51:14.360 に答える