pixelshader for overlays without border seams

Posted By: ventilator

pixelshader for overlays without border seams - 09/20/03 00:13

i wrote a pixelshader which avoids the disadvantages of d3d_autotransparency.

you have to use a 32bit tga texture. all pixels with alpha values above 0.5 will be rendered completely opaque and all other pixels will be rendered completely transparent. it's possible to enable the z-buffer then, so you won't have any sorting errors!

currently it can't be used for sprites because shaders don't seem to work with them...

in my opinion it looks better than overlays looked in a5.24 because there are no jagged edges!

Code:
...

ZWriteEnable=true;
AlphaTestEnable=true;
...
PixelShader=
asm
{
ps.1.3
def c0,1,1,1,1
def c1,0,0,0,0
tex t0 // sample t0
mov r0,t0
cnd r0.a,r0.a,c0,c1 // if(r0.a>0.5){r0.a=1;}else{r0.a=0;}
mul r0.rgb,r0,v0 // modulate with diffuse vertex lighting
};



entities using this shader should have my.flare=off; and my.transparent=off; so that the engine won't unnecessarily sort them!

here is a screenshot:

Posted By: ventilator

Re: pixelshader for overlays without border seams - 09/26/03 04:27

i found out that exactly the same can be done without a pixelshader!

Code:
material mat_vegetation

{
effect=
"
texture texSkin1;
dword mtlSkill1;
technique vegetation
{
pass p0
{
Texture[0]=<texSkin1>;

ZWriteEnable=true;
AlphaTestEnable=true;
AlphaRef=<mtlSkill1>;
AlphaFunc=greater;
//CullMode=none;

ColorArg1[0]=Texture;
ColorOp[0]=Modulate2x;
ColorArg2[0]=Diffuse;
}
}
";
}

starter mat_vegetation_init
{
...
mat_vegetation.skill1=pixel_for_vec(vector(127,0,0),0,8888);
}


this version even allows to adjust the threshold via the first value of the vector in the starter function!
Posted By: lucidman

Re: pixelshader for overlays without border seams - 09/27/03 05:53

Which version of A6 are you using to do this?

Posted By: ventilator

Re: pixelshader for overlays without border seams - 09/27/03 06:01

currently it does only work with the beta version. i guess the directx effects will be available in 6.2 commercial/pro!
Posted By: ventilator

Re: pixelshader for overlays without border seams - 09/29/03 07:54

if you use this material for plant models it could be useful to enable double sided polygons. just add this line:

CullMode=none;
Posted By: Cameron_Aycock

Re: pixelshader for overlays without border seams - 10/01/03 08:00

What type of FPS hit is there for 30-50 of these polys using this technique, vs normal overlays?
Posted By: ventilator

Re: pixelshader for overlays without border seams - 10/01/03 09:26

i haven't done any serious benchmarks yet but with enabled backface culling (which is also enabled with normal overlays) i haven't observed a performance hit. if two-sided polygons get used (CullMode=none;), the fps seem to drop a little. i have a meadow with 500 grass triangles and fps dropped from ~80 to ~72!
Posted By: Matt_Aufderheide

Re: pixelshader for overlays without border seams - 12/04/03 16:00

Question for ventilator.. do you have an idea how i could add this technique to my diff+spec shader? i have tried several methods.. with no success. If do an extra pass at the bieginngin with this fixed function code the alpha mask works wbut the subsequent passes are nullified. ANyone know how this stuff works.. multi passes and alpha blending etc?
Posted By: ventilator

Re: pixelshader for overlays without border seams - 12/04/03 16:10

i don't have much experience with multipass rendering but you could try to add the cnd line

def c0,1,1,1,1
def c1,0,0,0,0
...
cnd r0.a,r0.a,c0,c1 // if(r0.a>0.5){r0.a=1;}else{r0.a=0;}

to both passes? (of course you have to modify it so that it uses the correct alphachannel in both passes...)
Posted By: Matt_Aufderheide

Re: pixelshader for overlays without border seams - 12/04/03 16:48

hmm.. yes i think you're on the right track.. its sort of working.. now i have to figure out how the blending should be set up
Posted By: Darkstorm

Re: pixelshader for overlays without border seams - 01/31/04 06:25

I know this is an old thread but... whenever I try to use this I get an error stating the mat_overlay.skill1 is an unknown keyword. Obviously I am doing something wrong. Are started definitions only for Pro?
Posted By: Alexander Esslinger

Re: pixelshader for overlays without border seams - 01/31/04 06:58

In the new version use entSkin instead of texSkin and make sure, that the material is defined above your starter function.
Posted By: Darkstorm

Re: pixelshader for overlays without border seams - 01/31/04 07:30

Thanks. I already changed the texSkin and the starter is after the material. I also get a "nonexistant/empty action mat_overlay_init" error. Don't know what's going on. The only reason I am trying to get this to work is that I want to see if it indeed does "fix" the zbuffer sorting problem. I have a ton of double-sided polygons with alpha channels.
Posted By: Steempipe

Re: pixelshader for overlays without border seams - 01/31/04 11:27

I was getting both errors you posted before I removed the ... from the Starter.

starter mat_overlay_init
{
...
mat_overlay.skill1=pixel_for_vec(vector(127,0,0),0,8888);
}

action matoverlay
{
my.material = mat_overlay;
}

Good luck!

Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/01/04 00:13

btw. far cry uses the same method for foliage.


Posted By: Darkstorm

Re: pixelshader for overlays without border seams - 02/01/04 00:53

Hey its me again, The Shader Newb . I finally got rid of the errors but I'm not seeing much in improving the zbuffer sorting. I'm using double-sided polygons with 32bit TGA skins. Is that something that is in the code or do I need to do some research and add it myself? Thanks... again.
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/01/04 01:01

what was causing the error? ...there shouldn't be any sorting errors with this material. could you post a screenshot?
Posted By: Darkstorm

Re: pixelshader for overlays without border seams - 02/01/04 01:36

I'll explain what I'm doing so that if its wrong you can yell at me. I'm using a model with "double sided" polygons with a 32bit TGA skin that has an alpha channel. The leaves in the shots are duplicates in WED of the same model. The stem is a seperate model. I didn't assign any action or material to them because I'm assuming that the shader is assigned to anything using transparency right... maybe?

Shot #1 showing the error

Shot #2 showing the model layout
Posted By: Tobias

Re: pixelshader for overlays without border seams - 02/01/04 01:44

You must not set transparency, because then the polygons are not sorted. Only overlay, but no transparency or alpha channel (dont use a TGA skin).
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/01/04 01:45

Quote:

I didn't assign any action or material to them because I'm assuming that the shader is assigned to anything using transparency right... maybe?


no, you have to assign the material!

Quote:

You must not set transparency, because then the polygons are not sorted. Only overlay, but no transparency or alpha channel (dont use a TGA skin).


with this material you have to use a 32bit tga texture and not the overlay flag!

(entities using this effect should set my.flare=off; and my.transparent=off;!)

...
sorry, the far cry screenshot i posted only works in a seperate browser window!
Posted By: Darkstorm

Re: pixelshader for overlays without border seams - 02/01/04 02:15

See its a good thing I explained my shortcomings isn't it . Don't worry about the Far Cry shot. I have one set as my wallpaper for inspiration.. and frustration.

@Ventilator - I thought I'd let you know that I have already included you in my "poeple to thank" credits for this project. Heck, I should list you as head programmer .
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/01/04 02:18

do you model the plants double sided? if you use CullMode=none; this wouldn't be necessary!
Posted By: Darkstorm

Re: pixelshader for overlays without border seams - 02/01/04 02:23

Really? Hmmm I'll have to try that out. Thanks.

I noticed that setting the entities ambient and albedo doesn't seem to work when using this material. Is that right? If so, what do I need to change in the material to adjust these?
Posted By: slacker

Re: pixelshader for overlays without border seams - 02/01/04 02:57

I am having trouble with this one.

here is my code - the objects come out 100% white.

I am running 6.20 commercial with a ti/4200

my object is single sided polys with a texture and alpha.

I am pretty new to this stuff, any help is greatly appreciated.

material mat_overlay

{

effect=

"

texture entskin1;

dword mtlSkill1;

technique vegetation

{

pass p0

{

Texture[0]=<entskin1>;



ZWriteEnable=true;

AlphaTestEnable=true;

AlphaRef=<mtlSkill1>;

AlphaFunc=greater;

//CullMode=none;


ColorArg1[0]=Texture;

ColorOp[0]=Modulate2x;

ColorArg2[0]=Diffuse;

}

}

";

}
starter mat_overlay_init
{

mat_overlay.skill1=pixel_for_vec(vector(127,0,0),0,8888);
}

action matoverlay
{
my.flare = off;
my.transparent = off;
my.material = mat_overlay;
}

p.s. can someone help me get formatted code into these forums?!
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/01/04 03:06

Quote:

I noticed that setting the entities ambient and albedo doesn't seem to work when using this material. Is that right? If so, what do I need to change in the material to adjust these?


maybe it's necessary to copy the mat_model material parameters to get the same behavior as with standard models. instead of the starter function this example uses a material event function:

Code:
function mtl_vegetation_init

{
vec_set(mtl.emissive_blue,mat_model.emissive_blue);
vec_set(mtl.ambient_blue,mat_model.ambient_blue);
vec_set(mtl.diffuse_blue,mat_model.diffuse_blue);
vec_set(mtl.specular_blue,mat_model.specular_blue);
mtl.power=mat_model.power;
mtl.albedo=mat_model.albedo;
mtl.skill1=pixel_for_vec(vector(128,0,0),0,8888);
}

material mtl_vegetation
{
event=mtl_vegetation_init;
effect=
"
texture entSkin1;
dword mtlSkill1;

technique vegetation
{
pass p0
{
texture[0]=<entSkin1>;
zWriteEnable=true;
alphaTestEnable=true;
alphaRef=<mtlSkill1>;
alphaFunc=greater;
cullMode=none;

colorArg1[0]=texture;
colorOp[0]=modulate2x;
colorArg2[0]=diffuse;
}
}
technique fallback
{
pass p0
{
}
}
";
}



@slacker: strange! i have no idea what could cause this. i use a gf4 too so this shouldn't be a problem... (try to add an empty fallback! )
Posted By: Darkstorm

Re: pixelshader for overlays without border seams - 02/01/04 03:21

That did the trick. You're getting good at this stuff.

Maybe the all white problem is the same issue?
Posted By: slacker

Re: pixelshader for overlays without border seams - 02/01/04 03:24

that did it! No more z-buffer problems -sweet.

My project owes you a 1000 thanks ventilator, for all of your shader support!
Posted By: Darkstorm

Re: pixelshader for overlays without border seams - 02/01/04 03:26

Quote:

My project owes you a 1000 thanks ventilator, for all of your shader support!




I think this is true for quite a few of us. We'll have to find out when that ol birthday is and send a present .
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/01/04 03:36

you're welcome!

...
was the reason for the white objects the missing empty fallback? there seems to be some kind of strange behaviour with missing empty fallbacks on geforce4 cards! i already reported this on the beta forum but it looked like i was the only one with this problem...
Posted By: EX Citer

Re: pixelshader for overlays without border seams - 02/01/04 16:15

Hi all,
If I am not wrong, for backfaces can used the second skin of a model, or?
MfGEX
Posted By: slacker

Re: pixelshader for overlays without border seams - 02/02/04 03:43

No, I commented out the fallback in your code for now - maybe it was the starter work around - not sure how that would affct things..
Posted By: Thomas_Nitschke

Re: pixelshader for overlays without border seams - 02/06/04 23:31

Hi,
ähm ventilator? Da ich aus dem ltzten Post von Slacker nicht ganz schlau werde... hast du evtl. rausgefunden woran das liegt? Ich hab den Shader jetzt bei mir ausprobier (auch gf4ti4200) und habe genau dasselbe problem, auch wenn ich einen leeren fallback hinzufüge!
Und zweitens, könntest du mir vielleicht den hinzuzufügenden Code geben, um den "Waving" Effekt wie beim Waving-Grass Shader zu erreichen? Ich würds ja selber machen, nur hab ich davon (noch) absolut keine Ahnung
Danke im Vorraus!
Posted By: Thomas_Nitschke

Re: pixelshader for overlays without border seams - 02/08/04 18:23

Hey niemand?
Bitte helft mir leuts das ist echt wichtig für mich
Sonst muss ich den Pixelshader nutzen und der läuft mindestens 50% langsamer!
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/08/04 20:41

ich weiß nicht genau was du willst? ...wenn du zusätzlich zu diesem effekt die sinus bewegung haben willst, musst du beim waving grass shader den pixel shader weglassen und vor dem vertex shader diesen effekt einfügen.
Posted By: Thomas_Nitschke

Re: pixelshader for overlays without border seams - 02/08/04 22:55

Hi,
danke für die Antwort! Das ist ein Teil meines Problems.
Der andere Teil ist leider noch wichtiger: Ich wollte wissen, ob du rausgefunden hast woran das liegt, dass bei gf4 Karten alles weiß bleibt? Ist bei mir nämlich auch ( auch mit leerem fallbaack) der Fall, und slacker hat ja leider nicht genau beschrieben wie ers wegbekommen hat.
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/08/04 23:24

ich habe keine ahnung an was das liegen könnte. hast du die version die die mat_model eigenschaften kopiert ausprobiert? vielleicht kann dir slacker erklären wie er das problem lösen konnte?
Posted By: Thomas_Nitschke

Re: pixelshader for overlays without border seams - 02/17/04 15:45

Hi,
okay jetzt hab ichs zum Laufen gebracht, danke für die Hilfe
Prompt hab ich aber noch eine Frage ... ist es irgendwie möglich, die Sonnenlicht-Beeinflussung abzustellen? Was ich meine ist, dass der Shader die "Aufstellwände" eines Gras-Mesh ja je nach Sonnenwinkel unterschiedlich hell darstellt. Was manchmal etwas komisch oder unnatürlich aussieht.
In Kurzform, was muss ich am Code ändern, wenn das einzige Lighting-Feature was ich haben will, die Anpassung an die Bodenhelligkeit ist?
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/17/04 15:52

...vielleicht kannst du das problem beheben indem du my.albedo und/oder material.albedo auf 0 stellst?
Posted By: Thomas_Nitschke

Re: pixelshader for overlays without border seams - 02/18/04 00:34

Hi,
danke für die schnelle Hilfe, leider liegts daran wohl auch nicht. Ich habe my.albedo und material.albedo gleichermaßen auf 0 gesetzt, ohne eine Veränderung zu bemerken.
Vielleicht kannst du mit einem Screenshot was anfangen:

Links der Fehler, rechts normales Gras, was komischerweise entsteht, wenn ich die Entity nicht gedreht habe.
Zu Deutsch, sobald ich das Gras-Mesh drehe (ab ungefähr 45°) kommt es zu diesem Fehler, aber nur (!) bei cullMode = none, scheint also etwas mit den Doppelseitigen Polygonen zu tun zu haben.
Irgendwelche Ideen?
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/18/04 11:49

hmmm... ich habe momentan keine zeit um herumzuexperimentieren aber wenn es so nicht klappt sollte vielleicht doch der pixelshader verwendet werden und die shadowmap mit <veclight> in die beleuchtungsberechnung miteinbezogen werden.
Posted By: ventilator

Re: pixelshader for overlays without border seams - 02/19/04 23:48

was du auch noch ausprobieren könntest ist diffuse r g b des materials auf 0 zu stellen. wahrscheinlich hat albedo in a6 gar keine auswirkung.
Posted By: Thomas_Nitschke

Re: pixelshader for overlays without border seams - 10/27/04 23:02

Nach laaanger Zeit mal wieder ein Post hierzu
(@ventilator):Ich hab den Fixed-Function Overlay-Effekt von dir jetzt zum laufen gebracht und mit der Beleuchtung keine Probleme mehr, aber ich hätte gerne die Bewegung aus dem Waving Grass Shader implementiert. Wenn ich das richtig verstehe, wird diese Bewegung doch über Vertexshader berechnet und PS ist daher nicht nötig. Aber wie baue ich diesen Bewegungseffekt in das FFP-Pverlay Script ein? Ich hab davon null Ahnung o_O daher ist jede Hilfe absolut willkommen...

EDIT: Oh und noch ne Frage fällt mir ein! Ist es möglich, bei dem FFP-Overlay die "Toleranz" einzustellen. mit der die Alphamap behandelt wird? Bislang werden hellere Grauwerte in der Alphamap einfach nicht dargestellt, weshalb man mit diesem Effekt bisher keine Farbverläufe oder "runde" Kanten erzeugen kann... Geht das irgendwie?
© 2024 lite-C Forums