[aquaria] Patch to fix water surface rendering glitch
Andrew Church
achurch+aquaria at achurch.org
Mon Aug 2 18:11:45 EDT 2010
Quick fix for a bug reported on the Aquaria support forum
(http://www.bit-blot.com/forum/index.php?topic=778.0); it turns out the
calculations for frame buffer texture coordinates got thrown off if the
frame buffer height was not 1024 pixels. I'll admit I haven't studied
the algorithm enough to know exactly where all the magic numbers come
from (: but I've checked that the texture coordinates from the new code
match those from the old code to 6 decimal places at 800x600 and 1024x768.
--Andrew Church
achurch at achurch.org
http://achurch.org/
------------------------------------------------------------------------
# HG changeset patch
# User achurch
# Date 1280739646 -32400
# Branch water-surface-hi-res-glitch-fix
# Node ID 2d74c5dbf92dd986520cbd0211bf764100607663
# Parent f08314f4174e071225534ab2922d22ff56cdf01b
Fix a rendering glitch on the water surface at high resolutions.
This patch fixes a rendering glitch reported on the Bit Blot forums
(http://www.bit-blot.com/forum/index.php?topic=778.0), in which the
water surface reflection was not properly rendered when the height of
the game window exceeded 1024 pixels. (The glitch could also be seen
with a height of 512 pixels or less, such as at 640x480.)
diff -r f08314f4174e -r 2d74c5dbf92d Aquaria/WaterSurfaceRender.cpp
--- a/Aquaria/WaterSurfaceRender.cpp Sat Jul 10 15:04:54 2010 +0900
+++ b/Aquaria/WaterSurfaceRender.cpp Mon Aug 02 18:00:46 2010 +0900
@@ -201,18 +201,16 @@
if (dsq->useFrameBuffer && dsq->frameBuffer.isInited())
{
- int scrh=0;
- scrh = 768;
- float factor = core->frameBuffer.getHeight()/float(scrh);
+ const float reflectSize = 97;
+ const float reflectPos = (dsq->game->waterLevel.x - core->cameraPos.y)
+ + (dsq->game->waterLevel.x - core->screenCenter.y) / 3;
+ const float reflectOffset = -0.03f;
+ const float coordDiv = 768;
+ const float v0 = 1 + reflectOffset - (reflectPos * core->globalScale.x) / coordDiv;
+ const float v1 = v0 + (reflectSize * core->globalScale.x) / coordDiv;
- float diff = (dsq->game->waterLevel.x - core->screenCenter.y)*factor + (core->screenCenter.y-core->cameraPos.y);
-
- float tehSz = 97;
- float psy1 = (tehSz/100.0)-(diff/float(scrh*core->invGlobalScale));
- float bit = (tehSz/float(scrh*core->invGlobalScale));
-
- upperLeftTextureCoordinates.y = (psy1*core->frameBuffer.getHeightP());
- lowerRightTextureCoordinates.y = (psy1*core->frameBuffer.getHeightP() + bit*core->frameBuffer.getHeightP());
+ upperLeftTextureCoordinates.y = v0 * core->frameBuffer.getHeightP();
+ lowerRightTextureCoordinates.y = v1 * core->frameBuffer.getHeightP();
upperLeftTextureCoordinates.x = 0;
lowerRightTextureCoordinates.x = core->frameBuffer.getWidthP();
More information about the aquaria
mailing list