Postprocessing over panels

Posted By: 3run

Postprocessing over panels - 12/09/12 23:02

I have nice "old movie" postprocessing shader, and I want it to affect on HUD (inventory etc). So I wanted to ask, is it possible to make postprocessing shaders somehow affect on panels? I have a small idea in my head (as I'm noob at shaders, this idea has no point), maybe there is a way, to create one blank panel, set it's layer around 99 (so it will be over all other panels) stretch it to the screen's size and attach "somehow" postprocessing shader?? Thank you for your time! Any kind of help is appreciated!
Posted By: txesmi

Re: Postprocessing over panels - 12/10/12 08:39

It seems a good way to go when the process has nothing to do with the render/panels colors and so.
Code:
MATERIAL *mtlEffect = mtl_create ();
mtlEffect.effect = "myeffect.fx";

PANEL *panSource = pan_create ( "", 1 );
...
panSource.bmap = bmap_createblack ( panSource.size_x, panSource.size_y, 32 );
set ( panSource, SHOW );

...

while ( 1 )
{
   bmap_process ( panSource.bmap, NULL, mtlEffect );
   wait(1);
}



Otherway I know two other similar ways to go.

If you want to process just the panels, render them over a render target and show it throught an other panel with a bmap_process.
Code:
MATERIAL *mtlEffect = mtl_create ();
mtlEffect.effect = "myeffect.fx";

PANEL *panSource = pan_create ( "", 99 );
...
panSource.render_target = bmap_createblack ( panSource.size_x, panSource.size_y, 32 );
set ( panSource, SHOW );

PANEL *panDestiny = pan_create ( "", 1 );
panSource.bmap = bmap_createblack ( panSource.size_x, panSource.size_y, 32 );
set ( panDestiny, SHOW );

...

while ( 1 )
{
   bmap_process ( panDestiny.bmap, panSource.render_target, mtlEffect );
   wait(1);
}



If you want process the camera too, you can go like in the example above and include the camera render target in a material skin, or you can enlarge the render chain with a process_target view.

Code:
PANEL *panSource = pan_create ( "", 1 );
...
panSource.render_target = bmap_createblack ( panSource.size_x, panSource.size_y, 32 );
set ( panSource, SHOW );

MATERIAL *mtlEffect = mtl_create ();
mtlEffect.effect = "myeffect.fx";
mtlEffect.skin1 = panSource.render_target;

VIEW *camFinal = view_create ( 1 );
camFinal.material = mtlEffect;
set ( camFinal, SHOW | PROCESS_TARGET | CHILD );

camera.stage = camFinal;



In both cases, you'll need to check the texture sampler sources of the shader.

hope it helps,
salud!
Posted By: 3run

Re: Postprocessing over panels - 12/10/12 11:28

I wanted to try the second solution, but it says that "render_target" isn't member of a panel.
BTW, if I do by second solution, for all other panels, do I need to do anything? Thank you for your help man.
Posted By: 3dgs_snake

Re: Postprocessing over panels - 12/10/12 12:44

Hi,

The true name is "target_map".
Posted By: 3run

Re: Postprocessing over panels - 12/10/12 12:53

Hi snake, I tried to replace "render_target" with "target_map", but it crashes each frame from the while loop:
Quote:
bmap_process ( panDestiny.bmap, panSource.target_map, mtlEffect );
I guess problem was that bmap for "panDestiny" wasn't defined...
Posted By: txesmi

Re: Postprocessing over panels - 12/10/12 13:00

ops, that is true blush target_map!

You can render all the panels in the same render target, but I remember some troubles with alpha...

edit___
the source panel should have a content, too
Posted By: 3run

Re: Postprocessing over panels - 12/10/12 13:03

In the same render target? You mean like this:
Code:
bmap_process(panel.bmap, panSource.target_map, mtlEffect);

I'm noob at rendering, shaders stuff, so please don't be confused grin

Edit: "content" ?
Posted By: txesmi

Re: Postprocessing over panels - 12/10/12 13:09

i mean use same bmap as render target in all the panels.

Code:
BMAP *bmpRT = bmap_createblack ( screen_size.x, screen_size.y, 32 );
PANEL *pan1 = pan_create ( "", 1 );
pan1.target_map = bmpRT;
PANEL *pan2 = pan_create ( "", 2 );
pan2.target_map = bmpRT;
PANEL *pan3 = pan_create ( "", 3 );
pan3.target_map = bmpRT;

while (1)
{
   bmap_process ( panVisible, bmpRT, mtlEffect );
   wait(1);
}



whit content i mean, a background bmap, or a digit, or so. Something to render in the render target. grin


edit__
sorry, I miss with the hurry in the code above...
Code:
MATERIAL *mtlEffect = mtl_create ();
mtlEffect.effect = "pp_oldMovie.fx";

PANEL *panSource = pan_create ( "", 99 );
panSource.size_x = 128; // Define the size, otherwise...
panSource.size_y = 128; // 
panSource.bmap = bmap_createblack ( panSource.size_x, panSource.size_y, 32 ); // ir has 0 values!!

panSource.target_map = bmap_createblack ( panSource.size_x, panSource.size_y, 32 );
set ( panSource, SHOW );

PANEL *panDestiny = pan_create ( "", 1 );
panDestiny.bmap = bmap_createblack ( panSource.size_x, panSource.size_y, 32 ); // panDestiny bmap was pan Source, my fault...
set ( panDestiny, SHOW );

while(1){
	bmap_process(panDestiny.bmap, panSource.target_map, mtlEffect);
	wait(1);
}

Posted By: 3run

Re: Postprocessing over panels - 12/10/12 13:32

fucking shaders... I still can't get it... mad
Code:
MATERIAL* mtlEffect = mtl_create ();
mtlEffect.effect = "pp_oldMovie.fx";

PANEL* panSource = pan_create("", 99 );
panSource.size_x = 128; // Define the size, otherwise...
panSource.size_y = 128; // 
panSource.bmap = bmap_createblack(panSource.size_x, panSource.size_y, 32); // ir has 0 values!!
panSource.target_map = bmap_createblack(panSource.size_x, panSource.size_y, 32);
set(panSource, SHOW);

PANEL* panDestiny = pan_create("", 1);
panDestiny.bmap = bmap_createblack(panSource.size_x, panSource.size_y, 32); // panDestiny bmap was pan Source, my fault...
set(panDestiny, SHOW);

PANEL* test_pan = pan_create("bmap = inv_temp.bmp;", 1);
test_pan.target_map = panSource.bmap;
set(test_pan, SHOW);

while(1){
	bmap_process(panDestiny.bmap, panSource.target_map, mtlEffect);
	bmap_process(test_pan.bmap, panSource.target_map, mtlEffect);
	wait(1);
}

I've defined size as you've said (can I use screen size, or isn't that necessary?), I've set target map of a new panel to the bmap of the main (source) panel, all I can see, is that my (test pan) panel is smaller than it was (playing with the size of the source panel doesn't affect on it), and it's isn't affected by shader! What am I doing wrong? frown
Posted By: txesmi

Re: Postprocessing over panels - 12/10/12 14:40

try this. it is tested grin

Code:
#include <acknex.h>

MATERIAL *mtlEffect =
{
	effect = "
		float4 vecCycle;
		texture TargetMap;
		sampler ColorSampler = sampler_state { Texture = <TargetMap>; };
		
		float4 PS ( in float2 inTex: TEXCOORD0 ) : COLOR0
		{
			float2 Coord = inTex.xy * vecCycle.y;
			float4 Color1 = tex2D ( ColorSampler, Coord );
			Color1.a = 1.0f;
			return Color1;
		}
		
		technique blur
		{
			pass p0
			{
				VertexShader = null;
				PixelShader  = compile ps_2_0 PS();
			}
		}
	";
}


function main ()
{
	video_set(256,256,32,2);
	wait(1);
	
	FONT *fntArial = font_create ( "Arial#30" );
	STRING *strText = str_create ( "ABCDEFGHIJKL" );
	PANEL *panSource = pan_create ( "", 1 );
	panSource.size_x = 256;
	panSource.size_y = 256;
	pan_setstring ( panSource, 0, 0, 0, fntArial, strText );
	pan_setstring ( panSource, 0, 0, 30, fntArial, strText );
	pan_setstring ( panSource, 0, 0, 60, fntArial, strText );
	pan_setstring ( panSource, 0, 0, 90, fntArial, strText );
	set ( panSource, SHOW );
	panSource.target_map = bmap_createblack ( 256, 256, 32 );
	
	PANEL *panDestiny = pan_create ( "", 1 );
	panDestiny.bmap = bmap_createblack ( 256, 256, 32 );
	set ( panDestiny, SHOW );
	
	while ( !key_esc )
	{
		bmap_process ( panDestiny.bmap, panSource.target_map, mtlEffect );
		wait(1);
	}
	
	sys_exit ( NULL );
}

Posted By: 3run

Re: Postprocessing over panels - 12/10/12 15:07

Yeah, it works now, thank you my friend laugh
© 2024 lite-C Forums