1 registered members (AndrewAMD),
816
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: pp pixelation with proper blurring
[Re: Superku]
#469818
12/09/17 17:32
12/09/17 17:32
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hey! I had this kind of a shader made by MasterQ32, but it was also lost with other stuff I had on my laptop. Results looked like this (please ignore the lines): Notice how edges and lines are pixelated correctly. The hole effect used to blur the screen, but I added sharpen shader above it all and it was pretty good. Greets!
|
|
|
Re: pp pixelation with proper blurring
[Re: 3run]
#469876
12/12/17 11:32
12/12/17 11:32
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, In order to get a proper antialias (that is how it is called), I guess your best choice is to perform two linearly interpolated 1:2 downsamples.
#include <acknex.h>
#include <default.c>
#define PRAGMA_PATH "%EXE_DIR%templatesimages"
void main ()
{
video_mode = 8;
wait(1);
level_load ( "" );
ENTITY *entSky = ent_createlayer("skycube+6.tga", SKY | CUBE, 1);
ENTITY *ent = ent_create(SPHERE_MDL, nullvector, NULL);
camera->x = -30;
camera->bmap = bmap_createblack(screen_size.x, screen_size.y, 24);
VIEW *camDown[2];
VIEW *camPrev = camera;
int i=0;
for (; i < 2; i += 1) {
camDown[i] = view_create(1);
var _fraction = pow(2, i + 1);
camDown[i]->size_x = screen_size.x / _fraction;
camDown[i]->size_y = screen_size.y / _fraction;
camDown[i]->bmap = bmap_createblack(camDown[i]->size_x, camDown[i]->size_y, 24);
MATERIAL *_mtl = mtl_create();
_mtl->skill1 = floatv(camDown[i]->size_x);
_mtl->skill2 = floatv(camDown[i]->size_y);
_mtl->skin1 = camPrev->bmap;
effect_load(_mtl, "downsample.fx");
camDown[i]->material = _mtl;
camDown[i]->flags |= SHOW | PROCESS_TARGET;
camPrev->stage = camDown[i];
camPrev = camDown[i];
}
VIEW *camLast = view_create(1);
camLast->material = mtl_create();
effect_load(camLast->material, "upsample.fx");
camLast->flags |= SHOW | PROCESS_TARGET;
camPrev->stage = camLast;
while (!key_esc) {
if (key_1)
DEBUG_BMAP(camera->bmap, 1, 1);
if (key_2)
DEBUG_BMAP(camDown[0]->bmap, 1, 1);
if (key_3)
DEBUG_BMAP(camDown[1]->bmap, 1, 1);
wait(1);
}
sys_exit(NULL);
}
downsample.fx
float4 vecSkill1;
texture mtlSkin1;
sampler ColorSampler = sampler_state { Texture = <mtlSkin1>; MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Clamp; AddressV = Clamp; };
float4 PS(in float2 inPos: VPOS) : COLOR0 {
float2 coor = (inPos.xy + 0.5f) / vecSkill1.xy;
return tex2D(ColorSampler, coor.xy);
}
technique downsample{
pass p0 {
VertexShader = null;
PixelShader = compile ps_3_0 PS();
}
}
upsample.fx
float4 vecViewPort;
texture TargetMap;
sampler ColorSampler = sampler_state { Texture = <TargetMap>; MipFilter = Point; MinFilter = Point; MagFilter = Point; AddressU = Clamp; AddressV = Clamp; };
float4 PS(in float2 inPos: VPOS) : COLOR0 {
float2 coor = (inPos.xy + 0.5f) / vecViewPort.xy;
return tex2D(ColorSampler, coor.xy);
}
technique upsample {
pass p0 {
VertexShader = null;
PixelShader = compile ps_3_0 PS();
}
}
Three downsamples from a double sized camera gives you a 8 steps gradient instead of a 4 steps gradient. Salud!
|
|
|
Re: pp pixelation with proper blurring
[Re: txesmi]
#469881
12/12/17 15:08
12/12/17 15:08
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
I love it! Thank you very much, man! You are a shader master! Edit: one question, how do I update it then I change resolution? My guess is that I need to resize the camDown[i]->bmap, but am I correct? If so, then I need to think of a way to changing the size of it's bmap, rather than recreating it over and over again (I guess). Edit2: also, how do I remove it from the chain if I need to? Removing everything created (material, views and their bmaps) results to some very strange but interesting results I tried to make it work with pp_add and pp_remove, but no luck, since I'm too noob related to shader things Some screens to show you how it looks like (I love it!) My best regards!
Last edited by 3run; 12/12/17 15:50.
|
|
|
Re: pp pixelation with proper blurring
[Re: 3run]
#469895
12/12/17 20:31
12/12/17 20:31
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Great to see the progress. Not a huge fan of the downsampled look, though. regarding txesmi's suggestion: Personally, I'd only use one downsampling pass with a 2x2 blur kernel utilizing linear texture filtering. It would basically give you the same result using less texture samples and only a single pass. On the other hand, I don't think it'll blow the budget to leave things as they are.
POTATO-MAN saves the day! - Random
|
|
|
Re: pp pixelation with proper blurring
[Re: 3run]
#469984
12/17/17 22:03
12/17/17 22:03
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Edit: one question, how do I update it then I change resolution? My guess is that I need to resize the camDown[i]->bmap, but am I correct? If so, then I need to think of a way to changing the size of it's bmap, rather than recreating it over and over again (I guess). Edit2: also, how do I remove it from the chain if I need to? Removing everything created (material, views and their bmaps) results to some very strange but interesting results I tried to make it work with pp_add and pp_remove, but no luck, since I'm too noob related to shader things txesmi@ man, I still hope that you will find some spare time to help me out with this Greets!
|
|
|
Re: pp pixelation with proper blurring
[Re: 3run]
#469995
12/18/17 14:48
12/18/17 14:48
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Removing: Basically you have to remove the postprocess views (including resetting the .stage pointers) and remove all bmap-buffers that were used.
When resizing, for each view that changes size: Remove the bmap, create a new one with the appropriate dimensions and update all your pointers. This has to be done within one frame, otherwise you have to prevent the post-process stages from rendering (basically everything that uses your bmap would break stuff as the pointer is no longer valid).
POTATO-MAN saves the day! - Random
|
|
|
Re: pp pixelation with proper blurring
[Re: Kartoffel]
#469997
12/18/17 16:00
12/18/17 16:00
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Kartoffel@ thank you! I'll give it a try! Best regards!
|
|
|
Re: pp pixelation with proper blurring
[Re: 3run]
#469998
12/18/17 16:14
12/18/17 16:14
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Oh I forgot to add: There sometimes were problems that removing a bmap didn't work properly after it was used as a rendertarget. After a few times of recreating the rendertaret directx throws an error. I'm not sure under which conditions this happens, though. (maybe when not removing everything properly, so the rendertarget is still referenced somewhere from the graphics api and not removed as a result. just a wild guess.)
POTATO-MAN saves the day! - Random
|
|
|
Re: pp pixelation with proper blurring
[Re: 3run]
#470588
01/23/18 13:30
01/23/18 13:30
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
txesmi@ man, I still hope that you will find some spare time to help me out with this I am sorry, I wanted to do some tests before answering but forgot it in the way. Better late than never The main idea was to set the largest render target from the beginning and modify the views size only, instead of rebuilding everything each resolution change. As spected, there is no need of deleting anything. The rendering chain, main cameras render target inclusive, survives to a resolution change, and also to a blank level load as long as I tested it. Very few changes were needed to acoplish the goal. I added two functions that build and remove the whole rendering chain too. I guess that the negative side-effect comes from the fact that the whole render targets are cleared before rendering, a bunch of not visible pixels are also cleared on windowed video modes. Nothing to worry about, I think. Maxime when you leave render targets in peace forever. pixelation01.zip Salud!
|
|
|
Re: pp pixelation with proper blurring
[Re: txesmi]
#470596
01/23/18 20:08
01/23/18 20:08
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hey man! It works pretty great! Thank you very much for your time! The only thing I can notice so far is that 'axe' effect sometimes is blinking or chancing it's length, is that related to pixelation, what do you think? Edit: nahh, it seems that it's just related to framerate Best regards!
|
|
|
|