Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (NnamueN, 1 invisible), 1,489 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Alpha Test + Alpha Blending #149198
08/20/07 14:21
08/20/07 14:21
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Hello Shader Gurus,

I have a question concerning alpha testing and alphablending. The problem is, that when I set a model with an alpha channel in my level I get sorting errors, as expected. When I now use AlphaTestEnable = true; in a fixed function effect the sorting gets corrected, as expected too. Now if I set AlphaBlendEnable = true; nothing happens. The hard edges of the alpha test remain.

In other words: I'd love to have a correctly sorted model (with AlphaTesting or whatever) and at the same time the alphatranspareny look with its soft edges, as if the AlpaDepthTest never happened. Is that possible?


Always learn from history, to be sure you make the same mistakes again...
Re: Alpha Test + Alpha Blending [Re: Uhrwerk] #149199
08/20/07 17:26
08/20/07 17:26
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline
Expert
mpdeveloper_B  Offline
Expert

Joined: Feb 2006
Posts: 2,185
use ZWriteEnable = true; the only problem is that if you use alot of items with tgas then you will get sorting errors between them, which i don't think can be fixed...


- aka Manslayer101
Re: Alpha Test + Alpha Blending [Re: mpdeveloper_B] #149200
08/20/07 18:51
08/20/07 18:51
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Without ZWriteEnable it wouldn't work either way, would it?!


Always learn from history, to be sure you make the same mistakes again...
Re: Alpha Test + Alpha Blending [Re: Uhrwerk] #149201
08/21/07 17:37
08/21/07 17:37
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline
Expert
mpdeveloper_B  Offline
Expert

Joined: Feb 2006
Posts: 2,185
use Zwriteenable and alphablendenable it should work just fine


- aka Manslayer101
Re: Alpha Test + Alpha Blending [Re: mpdeveloper_B] #149202
08/21/07 17:52
08/21/07 17:52
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I already tried that. It results ins polygons behind the object hidden not being rendered at all, independent rom the alpha channel.


Always learn from history, to be sure you make the same mistakes again...
Re: Alpha Test + Alpha Blending [Re: Uhrwerk] #149203
08/23/07 22:11
08/23/07 22:11
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Quote:

In other words: I'd love to have a correctly sorted model (with AlphaTesting or whatever) and at the same time the alphatranspareny look with its soft edges, as if the AlpaDepthTest never happened. Is that possible?




Who wouldn't like this? It's not possible. Otherwise why do you suppose all games dont render this way?

You can in fact achieve something similar using some rendering tricks, such as two-pass rendering, alpha-to-coverage, or edge detection and blurring.


Sphere Engine--the premier A6 graphics plugin.
Re: Alpha Test + Alpha Blending [Re: Matt_Aufderheide] #149204
08/24/07 01:31
08/24/07 01:31
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Quote:

two-pass rendering, alpha-to-coverage, or edge detection and blurring.



Could you explain this a little further? How can I achieve those things? In a pixel shader? Thanks for looking into this, Matt, your help is highly appreciated here.


Always learn from history, to be sure you make the same mistakes again...
Re: Alpha Test + Alpha Blending [Re: Uhrwerk] #149205
08/24/07 14:18
08/24/07 14:18
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline
Expert
mpdeveloper_B  Offline
Expert

Joined: Feb 2006
Posts: 2,185
what matt also said is that when you use alphablending and fix the zwriting of the model, then it will most definitely cut through all other tga sprites, or models using zwriting and alphablending, so it's not possible to fix this...


- aka Manslayer101
Re: Alpha Test + Alpha Blending [Re: mpdeveloper_B] #149206
08/24/07 22:23
08/24/07 22:23
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Quote:

two-pass rendering, alpha-to-coverage, or edge detection and blurring.




These are three methods I know of to get soft edges and still correct sorting.

2-pass:
render the model once with alphatestenable=true and zwriteenable=false.
render it in a second pass with alphatestenable=false, alphablendenable=true and zwrite false.. also set zfunc=less

Drawback is that you must do two passes, not a problem unless you have a lot of models..

////////////////////////////////////////////////////////////////////////////////
alpha-to-coverage:
hardware method that requires anti-aliasing to be forced on, and hardawre support. you must simply enable the alpha-to-coverage render state, however you may have to do it in a dll usig d3d, very simple todo it though..this line does it:

pointertod3ddevice-> SetRenderState(D3DRS_ADAPTIVETESS_Y, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C'));

////////////////////////////////////////////////////////////////////////////////

edge detection and blurring:

more complex and sophisticated method, requires knowledge of sahders and render-to-texture.

Grab the backbuffer into a texture that's larger than the screen resolution. Then render a screen-aligned-quad with a special shader. In this shader do a Sobel 6-tap edge detection filter, and also store the average of the rgb 6-tap (which is a blur) .. use the edge results to lerp the blur with the plain sample of the back buffer tex...then you have soft edge globally like super anti-aliasing.

...if you dont understand this last section, just ignore this option


Sphere Engine--the premier A6 graphics plugin.
Re: Alpha Test + Alpha Blending [Re: Matt_Aufderheide] #149207
08/24/07 23:10
08/24/07 23:10
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Thank you for your explanations. That makes it all much clearer. As far as I can see the two pass rendering is the most sensefull method here. Writing a .ddl for a single line of code feels somehow ridiculous. Additionally the anti-aliasing could be a framerate killer and users with an older graphics card could get graphic errors?! Last method seems like a real framerate killer.

Thank you very much for helping me out here, Matt, it's a pitty I can rate you only one time 5 stars.

Edit: Works like a charm...
Code:
technique softveg
{
pass one
{
alphaBlendEnable = false;
alphaTestEnable = true;
zWriteEnable = true;
}
pass two
{
alphaBlendEnable = true;
alphaTestEnable = false;
zWriteEnable = false;
zFunc = less;
}
}




Always learn from history, to be sure you make the same mistakes again...
Page 1 of 2 1 2

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1