PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : ATi Smartshader: 3x3 Blur Shader zu einem 2x2 Blur Shader umschreiben??


Mr. Lolman
2004-02-20, 23:59:45
So schaut der 3x3 Shader aus:


shader convolutionPixelShader =
"!!ARBfp1.0

# This is a general purpose 3x3 convolution filter. Unused instructions
# and constants will get culled out by the driver so no need to remove them here.

PARAM texCoord00 = program.local[0];
PARAM texCoord01 = program.local[1];
PARAM texCoord02 = program.local[2];
PARAM texCoord10 = program.local[3];
PARAM texCoord12 = program.local[5];
PARAM texCoord20 = program.local[6];
PARAM texCoord21 = program.local[7];
PARAM texCoord22 = program.local[8];

# These constants are setup to do a blur filter.
PARAM const00 = {0.0769, 0.0769, 0.0769, 0.0};
PARAM const01 = {0.1538, 0.1538, 0.1538, 0.0};
PARAM const02 = {0.0769, 0.0769, 0.0769, 0.0};
PARAM const10 = {0.1538, 0.1538, 0.1538, 0.0};
PARAM const11 = {0.0769, 0.0769, 0.0769, 0.0};
PARAM const12 = {0.1538, 0.1538, 0.1538, 0.0};
PARAM const20 = {0.0769, 0.0769, 0.0769, 0.0};
PARAM const21 = {0.1538, 0.1538, 0.1538, 0.0};
PARAM const22 = {0.0769, 0.0769, 0.0769, 0.0};

TEMP finalPixel;
TEMP coord00;
TEMP coord01;
TEMP coord02;
TEMP coord10;
TEMP coord11;
TEMP coord12;
TEMP coord20;
TEMP coord21;
TEMP coord22;

OUTPUT oColor = result.color;

# Generate all the texture coordinates for the 9 texture lookups
ADD coord00, texCoord00, fragment.texcoord[0];
ADD coord01, texCoord01, fragment.texcoord[0];
ADD coord02, texCoord02, fragment.texcoord[0];
ADD coord10, texCoord10, fragment.texcoord[0];
ADD coord12, texCoord12, fragment.texcoord[0];
ADD coord20, texCoord20, fragment.texcoord[0];
ADD coord21, texCoord21, fragment.texcoord[0];
ADD coord22, texCoord22, fragment.texcoord[0];

# Do the texture lookups for the 3x3 kernel
TEX coord00, coord00, texture[0], 2D;
TEX coord01, coord01, texture[0], 2D;
TEX coord02, coord02, texture[0], 2D;
TEX coord10, coord10, texture[0], 2D;
TEX coord11, fragment.texcoord[0], texture[0], 2D;
TEX coord12, coord12, texture[0], 2D;
TEX coord20, coord20, texture[0], 2D;
TEX coord21, coord21, texture[0], 2D;
TEX coord22, coord22, texture[0], 2D;

# Multiply all texture lookups by their weights and sum them up
MUL finalPixel, coord00, const00;
MAD finalPixel, coord10, const10, finalPixel;
MAD finalPixel, coord20, const20, finalPixel;
MAD finalPixel, coord01, const01, finalPixel;
MAD finalPixel, coord11, const11, finalPixel;
MAD finalPixel, coord21, const21, finalPixel;
MAD finalPixel, coord02, const02, finalPixel;
MAD finalPixel, coord12, const12, finalPixel;
MAD oColor, coord22, const22, finalPixel;
END";

shader copyPixelShader =
"!!ARBfp1.0
OUTPUT oColor = result.color;
TEMP pixel;
TEX pixel, fragment.texcoord[0], texture[0], 2D;
MOV oColor, pixel;
END";

surface temp = allocsurf(width, height);

convolutionPixelShader.constant[0] = {-ds_dx, -dt_dy, 0, 0};
convolutionPixelShader.constant[1] = {0, -dt_dy, 0, 0};
convolutionPixelShader.constant[2] = {ds_dx, -dt_dy, 0, 0};
convolutionPixelShader.constant[3] = {-ds_dx, 0, 0, 0};
convolutionPixelShader.constant[4] = {ds_dx, 0, 0, 0};
convolutionPixelShader.constant[5] = {-ds_dx, dt_dy, 0, 0};
convolutionPixelShader.constant[6] = {0, dt_dy, 0, 0};
convolutionPixelShader.constant[7] = {ds_dx, dt_dy, 0, 0};

texture[0].source = backbuffer;
destination temp;
apply convolutionPixelShader;


texture[0].source = temp;
destination backbuffer;
apply copyPixelShader;

zeckensack
2004-02-21, 01:51:22
Quincunx-Filter. Hier fehlt noch das 2xAA. Die Kombination aus AA und Postfilter, die Quincunx darstellt, lässt sich auf diesem Weg nicht nachbilden, denn dafür müsste man Subpixel als Inputs nehmen können.

shader convolutionPixelShader =
"!!ARBfp1.0

# this is the whacky Quincunx filter kernel, but without the AA component
# and constants will get culled out by the driver so no need to remove them here.

PARAM texCoord00 = program.local[0];
PARAM texCoord02 = program.local[1];
PARAM texCoord20 = program.local[2];
PARAM texCoord22 = program.local[3];

# all five samples use the same filter weight
PARAM const_weight = {0.2000, 0.2000, 0.2000, 0.0};

TEMP finalPixel;
TEMP coord00;
TEMP coord02;
TEMP coord11;
TEMP coord20;
TEMP coord22;

OUTPUT oColor = result.color;

# Generate all the texture coordinates for the 9 texture lookups
ADD coord00, texCoord00, fragment.texcoord[0];
ADD coord02, texCoord02, fragment.texcoord[0];
ADD coord20, texCoord20, fragment.texcoord[0];
ADD coord22, texCoord22, fragment.texcoord[0];

# Do the texture lookups for the kernel
TEX coord00, coord00, texture[0], 2D;
TEX coord02, coord02, texture[0], 2D;
TEX coord11, fragment.texcoord[0], texture[0], 2D;
TEX coord20, coord20, texture[0], 2D;
TEX coord22, coord22, texture[0], 2D;

# Multiply all texture lookups by the weight and sum them up
MUL finalPixel, coord00, const_weight;
MAD finalPixel, coord20, const_weight, finalPixel;
MAD finalPixel, coord11, const_weight, finalPixel;
MAD finalPixel, coord02, const_weight, finalPixel;
MAD oColor, coord22, const_weight, finalPixel;
END";

shader copyPixelShader =
"!!ARBfp1.0
OUTPUT oColor = result.color;
TEMP pixel;
TEX pixel, fragment.texcoord[0], texture[0], 2D;
MOV oColor, pixel;
END";

surface temp = allocsurf(width, height);

convolutionPixelShader.constant[0] = {-ds_dx, -dt_dy, 0, 0};
convolutionPixelShader.constant[1] = {ds_dx, -dt_dy, 0, 0};
convolutionPixelShader.constant[2] = {-ds_dx, dt_dy, 0, 0};
convolutionPixelShader.constant[3] = {ds_dx, dt_dy, 0, 0};

texture[0].source = backbuffer;
destination temp;
apply convolutionPixelShader;


texture[0].source = temp;
destination backbuffer;
apply copyPixelShader;

aths
2004-02-21, 02:12:16
Wie probiert man das Programm aus?

zeckensack
2004-02-21, 02:28:45
Original geschrieben von aths
Wie probiert man das Programm aus?
http://www.forum-3dcenter.org/vbulletin/showthread.php?threadid=126029

Genauer: http://www.driverheaven.net/smartshader/pssEffects.zip

Damit kannst du dir eigene "Smartshader-Effekte" basteln, die dann über das ATI-Control-Panel erreichbar sind.

aths
2004-02-21, 12:56:59
Das funzt leider nur in OpenGL. Dein Programm, zs, blurrt viel stärker als Quincunx.

Xmas
2004-02-21, 14:28:47
Natürlich, weil es Pixel statt Subpixel sind. Damit ist ja auch der Blur-Radius höher. Zudem ist die Gewichtung ungünstiger.

Mr. Lolman
2004-02-21, 15:13:15
Hm, und Subpixel kann man mit dem Smartshader/filter Tool wahrscheinlich nicht ansteuern!?

Kann man sich im Grunde genommen das so vorstellen, dass bei aktivierten Smartshadereffekten, der Bildinhalt in eine Textur gerendert wird, die dann mit photoshopähnlichen 2D Filtern überlagert wird!?

Xmas
2004-02-21, 15:20:23
Ja, genau so ist es. Die Smartshader-Effekte sind rein 2D und haben nur Zugriff auf die "Framebuffer-Textur" und eigene Texturen.

aths
2004-02-21, 19:17:31
Original geschrieben von Xmas
Natürlich, weil es Pixel statt Subpixel sind. Damit ist ja auch der Blur-Radius höher. Zudem ist die Gewichtung ungünstiger. Auf Texturen bezogen macht das nix, wenn man korrekt Gewichtet.

zeckensack
2004-02-21, 19:36:46
Original geschrieben von aths
Auf Texturen bezogen macht das nix, wenn man korrekt Gewichtet. Hier noch eine Variante mit dem hoffentlich korrekten Effekt auf die Texturen.

shader convolutionPixelShader =
"!!ARBfp1.0

# this more closely approximates Quincunx's effect on textures, but still lacks the correct AA

PARAM texCoord02 = program.local[0];
PARAM texCoord20 = program.local[1];
PARAM texCoord22 = program.local[2];

# the three overlapped samples use the same filter weight
PARAM overlapped_weight = {0.2000, 0.2000, 0.2000, 0.0};
# the top left sample is weighted twice as strong
PARAM top_left_weight = {0.4000, 0.4000, 0.4000, 0.0};


TEMP finalPixel;
TEMP coord00;
TEMP coord02;
TEMP coord20;
TEMP coord22;

OUTPUT oColor = result.color;

# Generate all the texture coordinates for the 3 overlapped samples
ADD coord02, texCoord02, fragment.texcoord[0];
ADD coord20, texCoord20, fragment.texcoord[0];
ADD coord22, texCoord22, fragment.texcoord[0];

# Do the texture lookups for the kernel
TEX coord00, fragment.texcoord[0], texture[0], 2D;
TEX coord02, coord02, texture[0], 2D;
TEX coord20, coord20, texture[0], 2D;
TEX coord22, coord22, texture[0], 2D;

# Multiply all texture lookups by the weight and sum them up
MUL finalPixel, coord00, top_left_weight;
MAD finalPixel, coord20, overlapped_weight, finalPixel;
MAD finalPixel, coord02, overlapped_weight, finalPixel;
MAD oColor, coord22, overlapped_weight, finalPixel;
END";

shader copyPixelShader =
"!!ARBfp1.0
OUTPUT oColor = result.color;
TEMP pixel;
TEX pixel, fragment.texcoord[0], texture[0], 2D;
MOV oColor, pixel;
END";

surface temp = allocsurf(width, height);

convolutionPixelShader.constant[0] = { 0, -dt_dy, 0, 0};
convolutionPixelShader.constant[1] = {ds_dx, 0, 0, 0};
convolutionPixelShader.constant[2] = {ds_dx, - dt_dy, 0, 0};

texture[0].source = backbuffer;
destination temp;
apply convolutionPixelShader;


texture[0].source = temp;
destination backbuffer;
apply copyPixelShader;


Das ist btw ein einfacher 2x2 Boxfilter-Kernel, wobei allerdings die benachbarten Pixel überlappt sind.

Das Original-Quincunx funktioniert ja so:

O.O
.O.
O.ODie 'Ohren' sind jeweils eine Pixel-Position voneinander entfernt. Die Samples "rechts oben", "rechts unten" und "links unten" stammen von benachbarten Pixeln. Die Samples "Mitte" und "oben links" sind die beiden AA-Subpixel des aktuellen Pixels. Hier sample ich nur den einen Pixel, der mir zur Verfügung steht, gewichte ihn aber doppelt.
Das ist in Kombination mit 2xRGMS fast echtes Quincunx, jedoch fliesst auch in die Samples aus den benachbarten Pixeln schon mehr Kanteninformation ein (da dies ja bereits runtergefilterte Paare von Subpixeln sind, und nicht wie bei Quincunx einzelne Subpixel).

Endorphine
2004-02-21, 19:50:00
Der zweite Shader produziert bei mir in der SmartShaderErrorLog.txt nur ein lapidares "Attempt to use uninitialized identifier 'ds_dy'". 8[

Edit: Liegt's an dem fehlenden Leerzeichen in der Zeile? Ich probier's mal. :D
#2: Das war's nicht. ;(

zeckensack
2004-02-21, 19:59:11
Original geschrieben von Endorphine
Der zweite Shader produziert bei mir in der SmartShaderErrorLog.txt nur ein lapidares "Attempt to use uninitialized identifier 'ds_dy'". 8[

Edit: Liegt's an dem fehlenden Leerzeichen in der Zeile? Ich probier's mal. :D
#2: Das war's nicht. ;( Mein Fehler. Statt ds_dy muss es dt_dy heissen.
Ich hab's oben korrigiert :)

PS: Ich habe den Code nur geschrieben, aber nicht getestet. Das gleiche gilt auch für die erste Variante ;)

Mr. Lolman
2004-02-21, 19:59:20
bei mir funzt er auch nicht :ratlos:

/edit: Zu langsam. Gleich nochmal testen :D

Endorphine
2004-02-21, 20:16:51
Funzt. :)

Der Shader bringt meine R9700 übrigens fast zum glühen, der Kühler wird irrsinnig heiss. :jump3: Schon seltsam, der Kern wird scheinbar erst richtig ausgelastet wenn Shader laufen...

zeckensack
2004-02-21, 20:47:17
Variante drei mit angepassten Gewichtungen.
Entstanden auf Anraten von aths (http://www.forum-3dcenter.org/vbulletin/showthread.php?postid=1586747#post1586747).

Nochmals geändert

3/6 1/6 5/8 1/8
=>
1/6 1/6 1/8 1/8

Der restliche Code ist gleich geblieben.

shader convolutionPixelShader =
"!!ARBfp1.0

# this more closely approximates Quincunx's effect on textures, but still lacks the correct AA

PARAM texCoord02 = program.local[0];
PARAM texCoord20 = program.local[1];
PARAM texCoord22 = program.local[2];

# the three overlapped samples use the same filter weight
PARAM overlapped_weight = {0.125, 0.125, 0.125, 0.0};
# the top left sample is weighted five times as strong
PARAM top_left_weight = {0.625, 0.625, 0.625, 0.0};


TEMP finalPixel;
TEMP coord00;
TEMP coord02;
TEMP coord20;
TEMP coord22;

OUTPUT oColor = result.color;

# Generate all the texture coordinates for the 3 overlapped samples
ADD coord02, texCoord02, fragment.texcoord[0];
ADD coord20, texCoord20, fragment.texcoord[0];
ADD coord22, texCoord22, fragment.texcoord[0];

# Do the texture lookups for the kernel
TEX coord00, fragment.texcoord[0], texture[0], 2D;
TEX coord02, coord02, texture[0], 2D;
TEX coord20, coord20, texture[0], 2D;
TEX coord22, coord22, texture[0], 2D;

# Multiply all texture lookups by the weight and sum them up
MUL finalPixel, coord00, top_left_weight;
MAD finalPixel, coord20, overlapped_weight, finalPixel;
MAD finalPixel, coord02, overlapped_weight, finalPixel;
MAD oColor, coord22, overlapped_weight, finalPixel;
END";

shader copyPixelShader =
"!!ARBfp1.0
OUTPUT oColor = result.color;
TEMP pixel;
TEX pixel, fragment.texcoord[0], texture[0], 2D;
MOV oColor, pixel;
END";

surface temp = allocsurf(width, height);

convolutionPixelShader.constant[0] = { 0, -dt_dy, 0, 0};
convolutionPixelShader.constant[1] = {ds_dx, 0, 0, 0};
convolutionPixelShader.constant[2] = {ds_dx, - dt_dy, 0, 0};

texture[0].source = backbuffer;
destination temp;
apply convolutionPixelShader;


texture[0].source = temp;
destination backbuffer;
apply copyPixelShader;

Crushinator
2004-02-22, 02:44:26
Zecki,

irgendwas stimmt entweder mit dem Shader, dem Treiber (CAT 4.2 unter Win98SE) oder mit meinem Rechn0r nicht, denn ich habe Deine letzte Variante gerade 10 Minuten lang unter Quake3 ausprobiert und konnte anhand des Schw4nzometers (FPS-Anzeige) feststellen, daß mit der Zeit die Framerate von den obligatorischen 90 nach und nach bis auf 30 fps zurückgeht, ohne daß der Grund ersichtlich ist. Es passiert quasi auch, wenn man einfach nur im Kreis rumläuft. Danach habe ich nochmal RtCW (Single-Player) angeschmissen und konnte das geschilderte dort auch beobachten. Hast Du oder jemand anderer evtl. eine Idee, woran das liegen könnte? Bin ich vielleicht der Einzige, der dieses Problem hat?

P.S.: Es passiert auch mit dem Original 3x3 Shader, der dabei war.

/edit: Selbiges mit dem "Classic" Shader. :o

Mr. Lolman
2004-02-22, 04:15:18
Anscheinend gibts da irgendwo ein Speicherleck. Nach rund 15min spielen gabs ne Speicherauslastung von ~1,3GB, wovon sich Q3a 650MB gekrallt hat. Auch sinken bei mir kontinuierlich die fps (von 125 auf ~30), selbst wenn man nur herumsteht.

zeckensack
2004-02-22, 07:21:08
Guten Morgen, die Herren :)
Ich würde sagen das ist dann wohl ATI's Problem. Schreibt den Jungs mal, dass bei Verwendung von Smartshader-Effekten ein Speicherleck auftritt.

http://apps.ati.com/driverfeedback/