|
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
|
|
|
|