Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Strange transparency behaviour  (Read 2024 times)
0 Members and 1 Guest are viewing this topic.
Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Posted 2005-08-23 11:39:31 »

I am rendering terrain and putting some grass on it. Grass is gif texture with alpha channel on quad. What I get is strange - from one side of grass1,  since it is transparent  I can see other grass2 and terrain through it, but when I move to the other side of grass2, I can't see grass1 but I still can see terrain through it!  Huh Something with depth_function or blend_function or... ??

On screenshot below notice how grass 2 is cut of on the edges...


Offline vrm

Junior Member




where I should sign ?


« Reply #1 - Posted 2005-08-23 11:56:52 »

your polygons are 2 sided ?
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #2 - Posted 2005-08-23 12:05:26 »

Do you depth-sort your blended stuff from back to front?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Reply #3 - Posted 2005-08-23 12:07:09 »

yes, they are two sided. As you can see on pic, from the "back" you can see poly, texture (grass), even terrain behind, but another  grass being cut off. From the "fromt" this is not happening. When I play with different depth function, I can get to see grass behind, but now it is in the front... So, it is not transparency problem after all, I think, but something with rendering order and depth function (now it is GL_LEQUAL)

Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Reply #4 - Posted 2005-08-23 12:08:21 »

Do you depth-sort your blended stuff from back to front?

erikd, I don't know what you mean?


Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #5 - Posted 2005-08-23 12:15:16 »

You should sort the blended polygons (your grass tiles) on the depth, so that the most distant grass tiles will be rendered first, the nearest last.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2005-08-23 12:34:14 »

Not if you use AlphaFunc and only pass 1.0 alpha values, which is perfectly acceptable for grass. Great for intersecting polys (common in grass) which can't be sorted. This saves you the depth-sorting and results into perfect results from any angle.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Reply #7 - Posted 2005-08-23 12:34:34 »

tnx, but it didn't sovle the problem here. Now whole problem is just inverted. When I move with camera behind other grass poly, now he is untransparent for grass, and transparent for terrain... Cry

Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Reply #8 - Posted 2005-08-23 12:51:47 »

You should sort the blended polygons (your grass tiles) on the depth, so that the most distant grass tiles will be rendered first, the nearest last.

So you think  that I should sort the rendering order in my Vector object which contains Grass objects? Each frame, hm... that should be time expensive, but i'll try.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2005-08-23 13:00:39 »

Really look into AlphaFunc as I mentioned above. It will fix all your problems at no effort.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Reply #10 - Posted 2005-08-23 13:25:17 »

riven, i tried to sort polys and it really worked. What I want now is to try your method, but didn't quite understand it. I AM using
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
if that is what you were talking about. Please tell me more  Wink

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2005-08-23 13:33:15 »

AlphaFunc != BlendFunc Smiley

Let's say you want to render a tree, would you really want to depth-sort all leafs every frame?

Let's say the alpha-channel is either 0.0 or 1.0 in your texture. If you only want to show the pixels (and only let those write to the depthbuffer*) that have an alpha of 1.0, you enable alpha-testing and set the parameters with alpha-func.

* depth-buffer writes are the cause you have to depth-sort, so if you get those right, you don't have to sort.



1  
2  
3  
4  
5  
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1.0F);
// or
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.99F);


Now every fragment that is about to be rendered, is tested on it's alpha-value. Only if it passes, the pixel is rendered and the depth-buffer is updated.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Reply #12 - Posted 2005-08-23 13:42:40 »

Yes, it works!!!  Cheesy
Riven, tnx a lot...

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2005-08-23 13:48:50 »

Note that you shuold only enable alpha-testing when you really need it.
From my experience a while ago I remember it was quite a costly check.

Another nice thing is that because the scene is not sorted, the depthbuffer
will prevent the massive overdraw of back-to-front sorted scenes.

Oh, and I'm glad I could help you Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #14 - Posted 2005-08-23 14:11:04 »

Note that you shuold only enable alpha-testing when you really need it.
From my experience a while ago I remember it was quite a costly check.
Gord knows why, but enabling the alpha test turns off hierarcial depth buffer testing (on cards that support it, natch) which can cause a speed hit (I can only assume that they're reusing the same physical bit of circitry for both).

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Reply #15 - Posted 2005-08-25 14:40:52 »

Thanks to you guys (and reading couple of books  Wink ) I managed to make things work. Now grass transparency problems are history, see for example
http://hvor.madpage.com/magicwoodslwjgl.htm
screenshots on my pages...
 

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (36 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (41 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (35 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!