Panel based, autoresizing, fullscreen filmgrain

Posted By: Orange Brat

Panel based, autoresizing, fullscreen filmgrain - 03/27/05 18:48

Panel based, autoresizing, fullscreen filmgrain

It uses a single set of six 640 x 480 PCX images, and the scale factors are dependent on this size. If you use a different size, you'll have to change the scale values to match. As is, it takes up just over 6.2MB of video memory when active, and it'll purge itself when grainToggle = 0.

Code:

panel* pnl;
var grainToggle;

bmap grain1 = <grain1.pcx>;
bmap grain2 = <grain2.pcx>;
bmap grain3 = <grain3.pcx>;
bmap grain4 = <grain4.pcx>;
bmap grain5 = <grain5.pcx>;
bmap grain6 = <grain6.pcx>;

panel filmGrainPanel
{
layer = 200;
pos_x = 0;
pos_y = 0;
alpha = 5; //change to suit your needs
flags = transparent,overlay;
}

function filmGrain()
{
pnl = filmGrainPanel;
grainToggle = 1;
while(grainToggle == 1)
{
if(video_mode == 6) { pnl.scale_x = 1; pnl.scale_y = 1; } else { //640x480
if(video_mode == 7) { pnl.scale_x = 1.25; pnl.scale_y = 1.25; } else { //800x600
if(video_mode == 8) { pnl.scale_x = 1.6; pnl.scale_y = 1.6; } else { //1024x768
if(video_mode == 9) { pnl.scale_x = 2; pnl.scale_y = 2.134; } else { //1280x1024
if(video_mode == 11) { pnl.scale_x = 2.5; pnl.scale_y = 2.5; } } } } } //1600x1200
pnl.bmap = grain1; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain2; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain3; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain4; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain5; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain6; pnl.visible = on; sleep(0.09); pnl.visible = off;
}
pnl.visible = off; bmap_purge(grain1); bmap_purge(grain2); bmap_purge(grain3); bmap_purge(grain4); bmap_purge(grain5); bmap_purge(grain6);
}



Here's some starter images. Use Winrar to open it. I highly recommend you create your own(use Gimp filmgrain/noise filters) so your project's grain isn't the same as every other one that uses it: http://www.geocities.com/hainesrs/grain6PCX.rar
Posted By: JimFox

Re: Panel based, autoresizing, fullscreen filmgrain - 03/28/05 04:26

Thanks, Orange Brat!
I feel a bit stupid, but I have no clue what "filmgrain" actually means, except in the literal sense of photographic film. Could you talk me through this?
I would be interested in learning how to have panels autoresize to fill the screeen at any resolution. Does this have anything to do with that?
Regards,
Posted By: Orange Brat

Re: Panel based, autoresizing, fullscreen filmgrain - 03/28/05 08:03

1. Video mode 7 line's scale_x had a wrong value...it has been corrected.
2. Changed the panel name to filmGrainPanel to eliminate a double definition error.

Filmgrain is the noise pattern you see on old movies and on modern ones with an intentional filter placed during post. The Silent Hill games use it as does our very own The Kid, as well as, my own. It gives horror games a little more atmosphere, although it's good to provide an on/off switch for framrerate purposes. In the case of this code, all you have to do is set grainToggle to 0 and it takes care of the cleanup.

The autoresizing is a simple matter of altering the scale_x and scale_y to the appropriate value based on the resolution. I don't know how well it would work with panels with words on them or dithering, but it works fine for noise patterns and I'd think flat color. You could also display the PCX files as screen entities. They automatically resize depending on the resolutino, but it doesn't look as nice as using panels.
Posted By: FeiHongJr

Re: Panel based, autoresizing, fullscreen filmgrain - 04/02/05 07:16

thanks ill have to check it out i know i couldve used them conversion numbers for the panel size a few weeks back ended up going thru figuring out each one manually in the game. i know theres gotta be a math formula to figure it out but im no good at math.. sorry off topic . looks interesting ill give it a go and let you know if i have any problems thanks again

Edit:: im using the panel resize for menus and it does make them appear a little more blocky but it really isnt too bad i guess if you were to go the other way around and start with larger panels then reduce the size depending on screen resolution it might not be as bad. never tried it but that would require more memory so *shrugs*
Posted By: Orange Brat

Re: Panel based, autoresizing, fullscreen filmgrain - 04/02/05 18:17

You're right...it would probably look better going from larger to smaller, but for noise panels I don't think it matters.
Posted By: FeiHongJr

Re: Panel based, autoresizing, fullscreen filmgrain - 04/02/05 20:45

i agree i was just saying that since you mentioned using it for panels and what not but your right it probally doesnt matter much and does cut back on the overall size and memory the same applies for my game as well since graphix are not really my goal. I just like to complete one still havent got to check it out but it does look promising. I was a huge fan of the first silent hill and had plans of doing a horror type game eventually so this will be a very nice addition thanks again
Posted By: HeelX

Re: Panel based, autoresizing, fullscreen filmgrai - 09/02/06 11:30

I implemented another method that adapts to the screen resolution AND consumes only ~ 150 KB of videomemory by still looking the same as OrangeBrat did it. Have fun!

Here is the link: I am the link! Hell yeah!

From the readme:

--------------------------------------------------------------------
Low memory consumptioning realtime filmgrain
Created by: Christian Behrenberg - 2006-09-02
--------------------------------------------------------------------

Instead of circulate some big sized bitmaps for a realtime filmgrain, I use the natural property of grain: it is tileable. I took a filmgrain sample picture and converted it into a 512x512 DDS texture to save memory. It is only 129 KB big!

The method to emulate the previous method is to shift repeatingly the UV parameters of the skin in random matter. No one will see that you are just shifting the texture and badabing! you have a well done filmgrain effect. To achieve this, I use a screenentity for this. It is a 2 polygonal plane with the typical 4:3 ratio. So, nothing big in here. Additionally, I randomize each cycle the alpha value in a certain range.

With this package I provide 2 MDLs. The MDLs contain already the DDS texture, if you wish to link them to the external files, I added them also. I included two different grainstyles: the first one is the default black and white one, the second is a sepia version whereas I adapted the color of the grain to the typically sepia color. You can easily decide what you want by commenting in/out the corresponding line in the WDL.

To implement the grain just copy the code into your project or include the WDL. To start the refreshing function, just call HUD_grainRefresh(); once.. in your main loop, in your HUD initialization or whatever. You can easily change the variables to create your personal grain-style.

NOTE:

The disadvantage that it is a screenentity is, that it changes size when you change the camera.arc. So you may should write additional lines to compensate that side effect. Just modify dynamically the .x property of the HUD_grain entity.

Have fun and finish that AAA title

THIS CODE AND ITS CONTENTS ARE FREEWARE
if you like to write any thanks into your credits, feel free to send me a note so that I can play your game seeing my grain (what a rhyme!) in action

Greetings
Christian Behrenberg
Posted By: Orange Brat

Re: Panel based, autoresizing, fullscreen filmgrai - 09/02/06 23:54

Thanks for the contribution. That looks as good as what I was doing and for only a fraction of the vid mem.

I actually did something like this a couple years ago. I can't remember why I didn't go with it. I think it was pixelated poorly, so I abandoned it. The U and V are deprecated, so I'll have to convert this over to the shifting material, although I see you already have that in your todo. I can't find it in the template folders(it used to be in effects), but I probably wouldn't know what to do with it anyway.
Posted By: HeelX

Re: Panel based, autoresizing, fullscreen filmgrai - 09/03/06 12:33

I took it from the template of the current beta and modified it, because the template material shifts in mat_effUVrender the texture cyclicly with total_ticks, but I prefer to do that on my own. So.. assign this material and in the refresh function replace .u and .v with skill1 and skill2. I guess its better when you store the effect part in the material in a .fx file, just because this is just the effect itself plus its naming convention and, well, I guess you will access the effect from the original grain material.

Code:

//--------------------------------------------------------------------
// UV Shifting
// FFP Effect, which shifts faster the texture than using .u/v
//--------------------------------------------------------------------
function mat_effUVrender();
function mat_effUVinit();

//primary effect material
material mat_effUV
{
event = mat_effUVinit;
effect = "
matrix matMtl;

technique effUVspeed
{
pass one
{
TextureTransformFlags[0] = Count2;
TextureTransform[0] = <matMtl>;
}
}
technique fallback { pass one { } }
";
}

//helper-function: Init
function mat_effUVinit()
{
mtl.matrix11 = float(1); // default u scale
mtl.matrix21 = 0;
mtl.matrix12 = 0;
mtl.matrix22 = float(1); // default v scale

mtl.event = mat_effUVrender;
mtl.ENABLE_RENDER = on;
}

//helper-function: refresh
function mat_effUVrender()
{
//Skill1 & Skill2 are used for the shifting
mtl.matrix31 = floatd(my.skill1, 256);
mtl.matrix32 = floatd(my.skill2, 256);
}


Posted By: Orange Brat

Re: Panel based, autoresizing, fullscreen filmgrai - 09/03/06 12:55

Thanks. I assigned the mat_effUV material to the filmgrain entity, but it doesn't seem to be doing anything. The random alpha part still works, but the grain texture has disappeared.
Posted By: HeelX

Re: Panel based, autoresizing, fullscreen filmgrai - 09/03/06 13:13

Uhm did you wrote that?

Code:
material mat_grain
{
ambient_blue = 255;
ambient_green = 255;
ambient_red = 255;

diffuse_red = 255;
diffuse_green = 255;
diffuse_blue = 255;

specular_blue = 255;
specular_green = 255;
specular_red = 255;

emissive_blue = 255;
emissive_green = 255;
emissive_red = 255;

albedo = 200;
power = 100;

event = mat_effUVinit;
effect = "grain.fx";
}



and the effect into the fx file?

The UV effect material works here fine on my machine..
Posted By: broozar

Re: Panel based, autoresizing, fullscreen filmgrai - 09/03/06 16:41

i'd love a screenie of it..
Posted By: Orange Brat

Re: Panel based, autoresizing, fullscreen filmgrai - 09/03/06 20:32

I simply added the effect directly to the mat_grain material. My video card is a GeForce FX 5200.

Code:

material mat_grain
{
ambient_blue = 255;
ambient_green = 255;
ambient_red = 255;

diffuse_red = 255;
diffuse_green = 255;
diffuse_blue = 255;

specular_blue = 255;
specular_green = 255;
specular_red = 255;

emissive_blue = 255;
emissive_green = 255;
emissive_red = 255;

albedo = 200;
power = 100;

event = mat_effUVinit;
effect = "
matrix matMtl;

technique effUVspeed
{
pass one
{
TextureTransformFlags[0] = Count2;
TextureTransform[0] = <matMtl>;
}
}
technique fallback { pass one { } }
";
}



Here's a screenshot using the .u and .v. You may not even be able to tell, but it's very noticeable during gameplay. The transparent vertical streaks are rain drops:

http://www.geocities.com/hainesrs/game/shot_0.jpg
Posted By: HeelX

Re: Panel based, autoresizing, fullscreen filmgrai - 09/03/06 21:27

Nice to see it in action .. or in a still

Well, I'm not sure wether it works on NVidia cards or not. I just took it from the template wdl.. too bad that all computer here at home own ATI card. I can test it for you tomorrow perhaps.
Posted By: Orange Brat

Re: Panel based, autoresizing, fullscreen filmgrai - 09/04/06 05:16

I'm sure it does work on them if you culled it from the new template. I'd better be able to get it to work because as of the next version, U and V shifting is out of the engine:

Quote:

The undocumented texture shifting by u,v parameters was discontinued for models (it still works for sprites). For texture shifting apply the fx_uvspeed action from the mtlFX template, which is faster and easier to use than u,v parameters. The uv shifting effect also works with the Standard and Extra editions.




I suppose I could always just do it with the texture itself and use a filmgrain sprite instead of a model.
Posted By: HeelX

Re: Panel based, autoresizing, fullscreen filmgrai - 09/04/06 08:00

I suppose I could always just do it with the texture itself and use a filmgrain sprite instead of a model.

Yes! I did'nt thought about that. The only thing you should really do is the .x-modification relative to the arc.
Posted By: Bahamut

Re: Panel based, autoresizing, fullscreen filmgrai - 09/16/07 20:37

Can you please fix the link to the filmgrain code? Thanks!
Posted By: HeelX

Re: Panel based, autoresizing, fullscreen filmgrai - 09/16/07 21:55

Quote:

Can you please fix the link to the filmgrain code? Thanks!




I will check this out tomorrow. Thanks.
Posted By: Bahamut

Re: Panel based, autoresizing, fullscreen filmgrai - 09/21/07 10:24

Did you check this? I still cannot download...
Posted By: HeelX

Re: Panel based, autoresizing, fullscreen filmgrai - 09/21/07 10:56

The file was linked to my old server and I deleted it.

Here is the corrected link:

http://www.christian-behrenberg.de/archi...006-09-02_1.rar
© 2024 lite-C Forums