www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on October 12, 2017, 03:02:14 am

Title: Fog Of War Transparency With Software
Post by: AGP on October 12, 2017, 03:02:14 am
I''m writing a strategy game and can't seem to properly paint a transparent PNG on my fog (so that its edges are rounded). The logic for the texture placement is sound and has been tested. But all I get is solid black.

Code: [Select]
if (!TextureManager.getInstance().containsTexture("fog-top")) {
     TextureManager.getInstance().addTexture("fog-top", new Texture("Assets"+File.separator+"fog-top.png", true));
     TextureManager.getInstance().addTexture("fog-left", new Texture("Assets"+File.separator+"fog-left.png", true));
     TextureManager.getInstance().addTexture("fog-right", new Texture("Assets"+File.separator+"fog-right.png", true));
     TextureManager.getInstance().addTexture("fog-bottom", new Texture("Assets"+File.separator+"fog-bottom.png", true));
}
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 12, 2017, 07:46:52 am
Then most likely your objects aren't rendered with transparency enabled or your textures' alpha channel is off.
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 12, 2017, 07:41:14 pm
The textures are right. I set transparency to 0.
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 13, 2017, 10:16:57 am
Can you upload such a texture for me to see?
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 13, 2017, 10:31:19 am
Yup.

https://www.dropbox.com/s/yzwpl76o8zuzy2e/fog-left.png?dl=0 (https://www.dropbox.com/s/yzwpl76o8zuzy2e/fog-left.png?dl=0)
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 13, 2017, 12:00:12 pm
That texture has an alpha channel assigned to it that makes the white part transparent. I would guess that you actually want it the other way around?
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 13, 2017, 10:19:38 pm
No, those are the edges of the fog of war. The fog is black, naturally.
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 14, 2017, 07:34:40 pm
I can't see anything wrong with it nor with the rendering itself in my simple test case. Do you have a screen shot that shows the problem? Just to be sure that we are talking about the same thing here.
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 14, 2017, 09:22:08 pm
No problem.

https://www.dropbox.com/s/l7lqhpehh19f2qe/FogProblem.png?dl=0 (https://www.dropbox.com/s/l7lqhpehh19f2qe/FogProblem.png?dl=0)
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 16, 2017, 11:59:08 am
There quads don't seem to have any transparency applied to it. Alpha channel aside, they should be transparent anyway with a value of 0.
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 16, 2017, 10:21:38 pm
They are set to 0.
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 17, 2017, 10:01:53 am
Doesn't look like it. Do you have a test case?
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 19, 2017, 08:30:59 pm
I wrote a simple test and transparency worked. So then I wrote the following method, and all I get are "End of printOddTransparencies()" prints. So now I'm stumped.

Code: [Select]
     public void printOddTransparencies(World theWorld) {
for (int y = 0; y < planes[0].length; y++)
     for (int x = 0; x < planes.length; x++)
if (theWorld.containsObject(planes[x][y]) && planes[x][y].getTransparency() != 0)
     System.out.println("Odd transparency at ("+x+", "+y+"): "+planes[x][y].getTransparency());
System.out.println("End of printOddTransparencies()");
     }
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 20, 2017, 09:54:39 am
Maybe the texture itself hasn't been loaded properly? Albeit that doesn't explain why it's pitch black, but just to be sure...
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 20, 2017, 07:07:41 pm
I tested both the application logic (by replacing them with solid-color textures) and the same loading line (TextureManager.getInstance().addTexture("fog-left.png", new Texture("Assets"+File.separator+"fog-left.png", true))). Could it be relative to the number of polygons, or the sheer scale of the world? Maybe force-sorting the transparency list would fix it. Because number of polygons and size of the world are the only two different things between my test and the actual game.
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 20, 2017, 09:10:21 pm
I don't think so. As long as it's transparent AND on top of the rest, it should work. What happens if you use a texture in another color? Does it show?
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 20, 2017, 09:42:10 pm
The solid-color ones are semi-transparent (and where they belong).
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 22, 2017, 12:30:56 am
Maybe an issue with the texture coordinates somehow? If you are using a proper texture (not just a single colored one), does that look right?
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 23, 2017, 05:32:54 pm
The planes are created with the Extended Primitives class. So are the ones in my test case.
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 24, 2017, 07:30:01 am
I've no idea what's going on then. And I can't open the video link that you've sent me. All that YouTube does when I try to, is telling me: Oops!?
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 24, 2017, 07:34:53 am
That's weird. The video is no longer up (I just signed in from a different computer and can't see it). I wonder if Google took it down. Try again in a few hours, please. As soon as I wake up I'll check this out.
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 25, 2017, 08:41:02 am
The new video doesn't work either. I'm getting the same opps-page...!?
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 26, 2017, 06:41:52 pm
The latest video works. But it's almost impossible to tell anything based on it IMHO. All I see are black squares...could you make a similar video based on this texture: http://jpct.de/download/tmp/testtexture.png (http://jpct.de/download/tmp/testtexture.png)?
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 27, 2017, 06:07:48 am
I applied it only to the left and:

https://www.dropbox.com/s/zkgx3zkwcuc29r0/FogProblem.jpg?dl=0 (https://www.dropbox.com/s/zkgx3zkwcuc29r0/FogProblem.jpg?dl=0)
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 27, 2017, 06:50:39 am
I got it working by calling recreateTextureCoords(). Is that costly? It seems like it would be.

Oh, and how could I come as close as possible to an orthographic view (in order to reduce the displacement between the fog and the gound)? Field-of-view? And would that be by increasing or decreasing it?
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 27, 2017, 11:21:42 am
It's cheap as long as you don't call it every frame, which you shouldn't have to. To come closer to an orthographic view, you have to move the camera far(er) away and decrease the fov to compensate for that. But especially with the software renderer, you might run into accuracy issues if you are moving away too far.
Title: Re: Fog Of War Transparency With Software
Post by: AGP on October 27, 2017, 07:13:43 pm
Is this too big a scale for a Warcraft level, in your opinion?

Quote
************
World bounds:
X: -1133.6974, 318.40582
Y: -279.86633, 0.25386608
Z: -925.57733, 135.38232
************
Title: Re: Fog Of War Transparency With Software
Post by: EgonOlsen on October 30, 2017, 01:24:41 am
No, it should be fine. You might even want to increase it, if you run into some accuracy problems.