Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire effect shows bottom edges of grid #615

Open
ghost opened this issue Dec 9, 2018 · 6 comments
Open

Fire effect shows bottom edges of grid #615

ghost opened this issue Dec 9, 2018 · 6 comments
Labels
Simulation oddity that shouldn't happen

Comments

@ghost
Copy link

ghost commented Dec 9, 2018

Seems reproducible with any gas, but BOYL works very well.

Fill a large area with gas, make sure "fire display" is active, and you'll note vertical and horizontal lines running along the bottom and right sides of the 4x4 pressure/wall grid (i.e. one above and to the left of what the grid display shows).

@ghost
Copy link
Author

ghost commented Jan 3, 2019

Similar, very faint effect in blob display, best seen with CO2 and HYGN.

@jacob1
Copy link
Member

jacob1 commented Jan 3, 2019

Blob display just blobifies whatever is in normal displays. Anyway I see the bug, I haven't looked into it at all though due to lack of time.

@ghost
Copy link
Author

ghost commented Jan 4, 2019

Ah didn't realise blob display had fire effect. It is indeed exclusive to fire.

@LBPHacker LBPHacker added the Simulation oddity that shouldn't happen label Jan 31, 2020
@LBPHacker
Copy link
Member

LBPHacker commented Feb 1, 2020

This is a result of at least an easy-to-fix bug (the two inner loops should run up to and including CELL, i.e. use <=) and a not-so-easy-to-fix, likely intentionally applied approximation (dividing by 255 is probably slower than shifting to the right by 8). Fixing the first one yields a less noticeable ghost grid, while fixing both renders the phenomenon invisible to the naked eye (mine, anyway), though still detectable upon closer inspection via image editing software.

So, what about this?

diff --git a/src/graphics/RasterDrawMethods.inl b/src/graphics/RasterDrawMethods.inl
index 4d7b0be4..861b5a0b 100644
--- a/src/graphics/RasterDrawMethods.inl
+++ b/src/graphics/RasterDrawMethods.inl
@@ -134,10 +134,11 @@ void PIXELMETHODS_CLASS::addpixel(int x, int y, int r, int g, int b, int a)
        pixel t;
        if (x<0 || y<0 || x>=VIDXRES || y>=VIDYRES)
                return;
+       a += 1;
        t = vid[y*(VIDXRES)+x];
-       r = (a*r + 255*PIXR(t)) >> 8;
-       g = (a*g + 255*PIXG(t)) >> 8;
-       b = (a*b + 255*PIXB(t)) >> 8;
+       r = (a*r + 256*PIXR(t)) >> 8;
+       g = (a*g + 256*PIXG(t)) >> 8;
+       b = (a*b + 256*PIXB(t)) >> 8;
        if (r>255)
                r = 255;
        if (g>255)
diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp
index 1b79994c..516a52e3 100644
--- a/src/graphics/Renderer.cpp
+++ b/src/graphics/Renderer.cpp
@@ -1119,8 +1119,8 @@ void Renderer::prepare_alpha(int size, float intensity)
        memset(temp, 0, sizeof(temp));
        for (x=0; x<CELL; x++)
                for (y=0; y<CELL; y++)
-                       for (i=-CELL; i<CELL; i++)
-                               for (j=-CELL; j<CELL; j++)
+                       for (i=-CELL; i<=CELL; i++)
+                               for (j=-CELL; j<=CELL; j++)
                                        temp[y+CELL+j][x+CELL+i] += expf(-0.1f*(i*i+j*j));
        for (x=0; x<CELL*3; x++)
                for (y=0; y<CELL*3; y++)

EDIT: Nvm the ghost grid is still visible, I blame the >> 8 approximations.

@moonheart08
Copy link
Contributor

moonheart08 commented Feb 3, 2020

Would it be possible to just get rid of the approximation and see what performance hit it entails? (Probably very little. It'd take longer to get a value from L3 cache than to do a division.)

@LBPHacker
Copy link
Member

I think my approach for getting around the problematic approximation (see above) is nice, I just didn't feel like hunting all of them down. Maybe later, or maybe someone else will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Simulation oddity that shouldn't happen
Projects
None yet
Development

No branches or pull requests

3 participants