Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (howardR), 650 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
pp pixelation with proper blurring #469812
12/09/17 11:43
12/09/17 11:43
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Hey guys!

I was wondering if any one can help me out with pixelation shader. I could do this by setting camera->bmap to a small sized panel, but I need to get proper pixelation with blurring (to keep lines, edges etc correct after downsampling, if that's how it's called).

Greets.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: pp pixelation with proper blurring [Re: 3run] #469815
12/09/17 17:06
12/09/17 17:06
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Do you have an example of what you want to achieve (and optionally an example of how it's NOT supposed to look like)?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
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 Offline OP
Senior Expert
3run  Offline 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!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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 Offline
Serious User
txesmi  Offline
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.



Click to reveal..

Code:
#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
Code:
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
Code:
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 Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I love it! Thank you very much, man! You are a shader master! laugh

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 grin I tried to make it work with pp_add and pp_remove, but no luck, since I'm too noob related to shader things frown

Some screens to show you how it looks like (I love it!)



My best regards!

Last edited by 3run; 12/12/17 15:50.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: pp pixelation with proper blurring [Re: 3run] #469890
12/12/17 17:43
12/12/17 17:43
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline
Serious User
jumpman  Offline
Serious User

Joined: Apr 2002
Posts: 1,246
ny
awesome, would love to see a video!

Re: pp pixelation with proper blurring [Re: jumpman] #469894
12/12/17 19:44
12/12/17 19:44
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Thank you man! Hopefully soon I'll post a video or a small demo for testing.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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 Offline
Expert
Kartoffel  Offline
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. grin


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 Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: 3run
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 grin I tried to make it work with pp_add and pp_remove, but no luck, since I'm too noob related to shader things frown


txesmi@ man, I still hope that you will find some spare time to help me out with this grin


Greets!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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 Offline
Expert
Kartoffel  Offline
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
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