God rays tweaks.

This commit is contained in:
Andrei Drexler 2011-03-16 00:18:12 +00:00
parent 7b882ae08f
commit 50e46c30f2

View file

@ -134,13 +134,19 @@ static void RB_DrawScaledQuad(float x, float y, float w, float h, float xcenter,
static void RB_RadialBlur(int passes, float stretch, float x, float y, float w, float h, float xcenter, float ycenter, float alpha) static void RB_RadialBlur(int passes, float stretch, float x, float y, float w, float h, float xcenter, float ycenter, float alpha)
{ {
const float inc = 1.f / (passes + 1.f); const float inc = 1.f / passes;
const float mul = powf(stretch, inc); const float mul = powf(stretch, inc);
float scale; float scale;
alpha *= inc; alpha *= inc;
RB_Color4f(alpha, alpha, alpha, 1.f); RB_Color4f(alpha, alpha, alpha, 1.f);
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
RB_DrawQuad(x, y, w, h, 0.f, 0.f, 1.f, 1.f);
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
--passes;
scale = mul; scale = mul;
while (passes > 0) while (passes > 0)
{ {
@ -168,7 +174,6 @@ static void RB_GodRays(void)
float x, y, w, h, w2, h2; float x, y, w, h, w2, h2;
matrix_t mvp; matrix_t mvp;
vec4_t pos, hpos; vec4_t pos, hpos;
float mul;
if (!backEnd.hasSunFlare) if (!backEnd.hasSunFlare)
return; return;
@ -201,51 +206,69 @@ static void RB_GodRays(void)
w2 = w * 0.5f; w2 = w * 0.5f;
h2 = h * 0.5f; h2 = h * 0.5f;
// downsample full-screen buffer to first quarter buffer // initialize quarter buffers
R_FBO_Bind(tr.fbo.quarter[0]); {
float mul = 1.f;
RB_SetGL2D_Level(1);
RB_SetGL2D_Level(1);
R_FBO_BindColorBuffer(tr.fbo.full[1], 0);
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO ); GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
RB_Color4f(1.f, 1.f, 1.f, 1.f);
mul = 0.75f;
RB_Color4f(mul, mul, mul, 1.f);
RB_DrawQuad(x, y, w2, h2, 0.f, 0.f, 1.f, 1.f);
// copy to second quarter buffer
R_FBO_Bind(tr.fbo.quarter[1]);
R_FBO_BindColorBuffer(tr.fbo.quarter[0], 0);
mul = 0.25f; // first, downsample the main framebuffers
RB_Color4f(mul, mul, mul, 1.f); R_FBO_Bind(tr.fbo.quarter[0]);
R_FBO_BindColorBuffer(tr.fbo.full[0], 0);
RB_DrawScaledQuad(x, y, w2, h2, pos[0], pos[1], 1.f); RB_DrawQuad(x, y, w2, h2, 0.f, 0.f, 1.f, 1.f);
// several additive passes
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
RB_RadialBlur(3, 4.f/3.f, x, y, w2, h2, pos[0], pos[1], 1.f);
// switch back to the first buffer and do some more passes R_FBO_Bind(tr.fbo.quarter[1]);
R_FBO_Bind(tr.fbo.quarter[0]); R_FBO_BindColorBuffer(tr.fbo.full[1], 0);
R_FBO_BindColorBuffer(tr.fbo.quarter[1], 0); RB_DrawQuad(x, y, w2, h2, 0.f, 0.f, 1.f, 1.f);
mul = 1.f/6.f; R_FBO_Bind(tr.fbo.quarter[0]);
RB_Color4f(mul, mul, mul, 1.f/5.f); R_FBO_BindColorBuffer(tr.fbo.quarter[1], 0);
RB_DrawScaledQuad(x, y, w2, h2, pos[0], pos[1], 1.f);
RB_RadialBlur(5, 5.f, x, y, w2, h2, pos[0], pos[1], 1.f); // then blend over the flare buffer using multiply2x
if (1)
{
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_SRC_COLOR );
mul = 1.f;
RB_Color4f(mul, mul, mul, 1.f);
RB_DrawQuad(x, y, w2, h2, 0.f, 0.f, 1.f, 1.f);
}
RB_Color4f(1.f, 1.f, 1.f, 1.f); // or additively
if (0)
{
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
mul = 0.25f;
RB_Color4f(mul, mul, mul, 1.f);
RB_DrawQuad(x, y, w2, h2, 0.f, 0.f, 1.f, 1.f);
}
}
// radial blur passes, ping-ponging between the two quarter-size buffers
{
const float stretch_add = 2.f/3.f;
float stretch = 1.f + stretch_add;
int i;
for (i=0; i<2; ++i)
{
R_FBO_Bind(tr.fbo.quarter[(~i) & 1]);
R_FBO_BindColorBuffer(tr.fbo.quarter[i&1], 0);
RB_RadialBlur(5, stretch, x, y, w2, h2, pos[0], pos[1], 1.f);
stretch += stretch_add;
}
}
// add back on top of the main buffer // add result back on top of the main buffer
R_FBO_Bind(tr.fbo.full[0]); {
R_FBO_BindColorBuffer(R_FBO_Bind(tr.fbo.full[0]), 0);
RB_SetGL2D_Level(0); RB_SetGL2D_Level(0);
R_FBO_BindColorBuffer(tr.fbo.quarter[0], 0); GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
RB_Color4f(1.f, 1.f, 1.f, 1.f);
RB_DrawQuad(x, y, w, h, 0.f, 0.f, 1.f, 1.f); RB_DrawQuad(x, y, w, h, 0.f, 0.f, 1.f, 1.f);
}
} }
void RB_FBO_Set2D(void) void RB_FBO_Set2D(void)