Tag auch
Ich hab mir mit OpenGL einen Effekt gemacht der eine Art Tron 2.0 effekt sein soll.
Funktioniert auch so weit so gut, nur gehen die FPS in den Keller bei standard PC's.
Ich hab gerade erst mit OpenGl angefangen und bin froh, das ich den hingekriegt hab, nur bei der Optimierung haperts jetzt.
Hier mal der Code:
Wie gesagt, die FPS gehen in den Keller bei 08/15 PC's, bei meinem grossen merk ich nichts, das ist aber auch kein standard PC.
Kann mir helfen beim optimieren?
Danke im voraus
Ich hab mir mit OpenGL einen Effekt gemacht der eine Art Tron 2.0 effekt sein soll.
Funktioniert auch so weit so gut, nur gehen die FPS in den Keller bei standard PC's.
Ich hab gerade erst mit OpenGl angefangen und bin froh, das ich den hingekriegt hab, nur bei der Optimierung haperts jetzt.
Hier mal der Code:
PHP:
void CShader::RenderScreenGlow(void)
{
// check to see if (a) we can render it, and (b) we're meant to render it
if (IEngineStudio.IsHardware() != 1)
return;
if ((int)gEngfuncs.pfnGetCvarFloat("shader_glowblursteps") == 0 || (int)gEngfuncs.pfnGetCvarFloat("shader_glowstrength") == 0)
return;
// enable some OpenGL stuff
glEnable(GL_TEXTURE_RECTANGLE_NV);
glColor3f(1,1,1);
glDisable(GL_DEPTH_TEST);
// STEP 1: Grab the screen and put it into a texture
glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);
glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth, ScreenHeight, 0);
// STEP 2: Set up an orthogonal projection
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 1, 1, 0, 0.1, 100);
// STEP 3: Render the current scene to a new, lower-res texture, darkening non-bright areas of the scene
// by multiplying it with itself a few times.
glViewport(0, 0, ScreenWidth/2, ScreenHeight/2);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
glDisable(GL_BLEND);
glBegin(GL_QUADS);
DrawQuad(ScreenWidth, ScreenHeight);
glEnd();
glEnable(GL_BLEND);
glBegin(GL_QUADS);
for (int i = 0; i < (int)gEngfuncs.pfnGetCvarFloat("shader_glowdarkensteps"); i++)
DrawQuad(ScreenWidth, ScreenHeight);
glEnd();
glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiGlowTex);
glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/2, ScreenHeight/2, 0);
// STEP 4: Blur the now darkened scene in the horizontal direction.
float blurAlpha = 1 / (gEngfuncs.pfnGetCvarFloat("shader_glowblursteps")*2 + 1);
glColor4f(1,1,1,blurAlpha);
glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
glBegin(GL_QUADS);
DrawQuad(ScreenWidth/2, ScreenHeight/2);
glEnd();
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBegin(GL_QUADS);
for (i = 1; i <= (int)gEngfuncs.pfnGetCvarFloat("shader_glowblursteps"); i++) {
DrawQuad(ScreenWidth/2, ScreenHeight/2, -i, 0);
DrawQuad(ScreenWidth/2, ScreenHeight/2, i, 0);
}
glEnd();
glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/2, ScreenHeight/2, 0);
// STEP 5: Blur the horizontally blurred image in the vertical direction.
glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
glBegin(GL_QUADS);
DrawQuad(ScreenWidth/2, ScreenHeight/2);
glEnd();
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBegin(GL_QUADS);
for (i = 1; i <= (int)gEngfuncs.pfnGetCvarFloat("shader_glowblursteps"); i++) {
DrawQuad(ScreenWidth/2, ScreenHeight/2, 0, -i);
DrawQuad(ScreenWidth/2, ScreenHeight/2, 0, i);
}
glEnd();
glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/2, ScreenHeight/2, 0);
// STEP 6: Combine the blur with the original image.
glViewport(0, 0, ScreenWidth, ScreenHeight);
glDisable(GL_BLEND);
glBegin(GL_QUADS);
DrawQuad(ScreenWidth/2, ScreenHeight/2);
glEnd();
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glBegin(GL_QUADS);
for (i = 1; i < (int)gEngfuncs.pfnGetCvarFloat("shader_glowstrength"); i++) {
DrawQuad(ScreenWidth/2, ScreenHeight/2);
}
glEnd();
glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);
glBegin(GL_QUADS);
DrawQuad(ScreenWidth, ScreenHeight);
glEnd();
// STEP 7: Restore the original projection and modelview matrices and disable rectangular textures.
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glDisable(GL_TEXTURE_RECTANGLE_NV);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
}
Wie gesagt, die FPS gehen in den Keller bei 08/15 PC's, bei meinem grossen merk ich nichts, das ist aber auch kein standard PC.
Kann mir helfen beim optimieren?
Danke im voraus