Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, Quad, AndrewAMD), 936 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Gaussian Blur PP Pixel Shader [Re: Hummel] #350519
12/16/10 18:49
12/16/10 18:49
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Thanks. Any hints, why "#ifdef" is faster than "if()"?
(Sorry, TSG_Torsten for hijacking your thread.)

EDIT: Thanks, Joozey. I missed the "every pixel" in Hummel's explanation.

Last edited by Pappenheimer; 12/16/10 19:19.
Re: Gaussian Blur PP Pixel Shader [Re: Pappenheimer] #350520
12/16/10 19:06
12/16/10 19:06
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Because the compiler evaluates the #ifdef only once, whereas the if() gets executed for every pixel every frame as Hummel says. So the #ifdef is here faster by definition laugh.

TSG_Torsen:
No, no performance issues. My laptop is really crappy at processing stuff like shaders, but this goes fine. Must be said that it isn't exactly a large area of pp shading here tongue. My game is 352x512 pixels grin.

Last edited by Joozey; 12/16/10 19:09.

Click and join the 3dgs irc community!
Room: #3dgs
Re: Gaussian Blur PP Pixel Shader [Re: Hummel] #350521
12/16/10 19:30
12/16/10 19:30
Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
TSG_Torsten Offline OP

User
TSG_Torsten  Offline OP

User

Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
Thanks for the hint with ifdef, haven't thought about it before, and this is quite a good idea!

Anyway, I've re-written the whole shader... So, now it is really direction-independent... voila:


You can set a lot more options now in the shader-file.
By default, PS 3.0 is needed, but take a look into the file if you need a PS 2.0:
Code:
// Gaussian Blur PixelShader 3.0
// By Torsten Simon - © 2010

// Accepts incomming:
// skill1 - strength (0 ... 10)
// mat_name.skill1=floatv(0...10);

#define USE_STATIC_VALUES true
// Remove/Comment this line to use material.Skill2...Skill5 for the values below
#define WIDTH 8
// WIDTH in Pixels to distribute the blur, lower values -> faster rendering
#define WIDTH_SKIP 2
// "Jump" Pixels when blurring, higher values -> faster rendering
#define RADIUS 7
// Radius when blurring, higher values -> faster rendering
#define GLOW 0
// Min: 0, Max: 100, Applying a glowing blur effect


// Please Read:
// This shader uses PS_3_0, but if you use the fast, simple blur-parameters
// you can also use PS_2_0. Therefore, change line 123 to
//	PixelShader = compile ps_2_0 postprocessing_gaussian(); 

/* Some Examples to try

// Default (Small, Smooth)
#define WIDTH 8
#define WIDTH_SKIP 2
#define RADIUS 7

// Fast, Simple Blur (Works with PS_2_0 as well!)
#define WIDTH 8
#define WIDTH_SKIP 4
#define RADIUS 45

// Wide Range
#define WIDTH 30
#define WIDTH_SKIP 8
#define RADIUS 10

// Medium Range
#define WIDTH 20
#define WIDTH_SKIP 8
#define RADIUS 15

*/


#include <define>

float4 vecSkill1;
// Min: 0, Max:10

float4 vecSkill5;

Texture TargetMap;
sampler2D g_samSrcColor = sampler_state { texture = <TargetMap>; MipFilter = Linear;	};

float4 vecViewPort;

#define RENDER vecSkill1.x>0

float4 postprocessing_gaussian(float2 Tex : TEXCOORD0) : COLOR0 
{   
	float4 ret=tex2D(g_samSrcColor, Tex.xy);
	#ifdef RENDER
	
	int width,width_skip,radius,glow;
	
	#ifdef USE_STATIC_VALUES
	width=WIDTH;
	width_skip=WIDTH_SKIP;
	radius=RADIUS;
	glow=GLOW;
	#else
	width=vecSkill1.y;
	width_skip=max(vecSkill1.z,1);
	if(width<width_skip) width=width_skip;
	else width+=width%width_skip;
	radius=max(vecSkill1.w,1);
	glow=vecSkill5.x;
	#endif
	
	// Real sample	
   float4 sampleM  = tex2D(g_samSrcColor, Tex.xy);
   
	// Brightness calculation script
	float fac=(vecSkill1.x)*float(float(((float)width_skip/(float)width)/float(360/radius))/10)*((glow+50)/50.f);
	
	float s=(10-vecSkill1.x)*.1+fac;

	ret=s*sampleM; // return variable
	int i=0;
	int dist=width_skip;

	while(dist<=width)
	{
	float4 pos1;
	float round=radians(i);
	pos1.x=Tex.x+sin(round)*vecViewPort.z*dist;
	pos1.y=Tex.y+cos(round)*vecViewPort.w*dist;
	pos1.z=0;
	pos1.w=0;
	float4 S1=tex2Dlod(g_samSrcColor,pos1);
	ret+=fac*(S1);
	i+=radius;
	if(i>=360) {
		dist+=width_skip;
		i=0;
	}
	}
	#endif
	return ret;
}

technique PostProcess 
{
	pass p1 
	{
		AlphaBlendEnable = false;	
		VertexShader = null;
		PixelShader = compile ps_3_0 postprocessing_gaussian();
	}
}



As always, C & C are welcome laugh

[Edit:] And I'm again curious if you run into any performance issue... no problems for me so far @ATI HD 5870 laugh

Have fun!

Regards
TSGames

Last edited by TSG_Torsten; 12/16/10 21:41.
Re: Gaussian Blur PP Pixel Shader [Re: TSG_Torsten] #350523
12/16/10 19:50
12/16/10 19:50
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Isn't that incredibly slow? I suggest you blur in x and then in y-direction and exploit the linear interpolation feature of texture sampling.

edit:
http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/

Last edited by Joey; 12/16/10 19:52.
Re: Gaussian Blur PP Pixel Shader [Re: Joey] #350524
12/16/10 19:59
12/16/10 19:59
Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
TSG_Torsten Offline OP

User
TSG_Torsten  Offline OP

User

Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
I'm new to shaders, so if there are ways to design it better (and, for sure, there are wink ), feel free to do and re-post it wink

I'm checking the activity of my GPU, and I've got less than 10% @1980x1080 and 30 FPS, so there are no performance problems for me so far...

Regards
TSGames

Re: Gaussian Blur PP Pixel Shader [Re: Joey] #350525
12/16/10 19:59
12/16/10 19:59
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Can you make the width, glow and radius also in vecSkill variables? I'd like to change those by events in the game. I tried, but I keep getting errors at the WIDTH in the while loop. Converted the vecskill2 to an integer, but same problem.

I do get a performance issue now. Framerate drops considerably when I use your wide range sample.

EDIT: I say vecSkill2, but that one is still part of the float4 of skill1. skill5 is better tongue.

Last edited by Joozey; 12/16/10 21:32.

Click and join the 3dgs irc community!
Room: #3dgs
Re: Gaussian Blur PP Pixel Shader [Re: Joozey] #350529
12/16/10 20:19
12/16/10 20:19
Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
TSG_Torsten Offline OP

User
TSG_Torsten  Offline OP

User

Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
I also tried to use vecSkill's to change - but I ran into the same problems. I still didn't find a way to make it possible to change this vars by the engine.

Try using a higher radius (for example 20) or a higher width_skip (for example 14), may it should be faster than.

Regards
TSGames

Re: Gaussian Blur PP Pixel Shader [Re: TSG_Torsten] #350531
12/16/10 20:25
12/16/10 20:25
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
I briefly tried the shader in joey's link, but that thing doesn't do a very good job. On high range it becomes a cross rather than a complete blur. It requires a vertical blur for each horizontal sample I think. So that's 9*9=81 samples anyway. not 9+9.

Ill ponder a bit more with the vecskills, really want it to work tongue. And yeah I can have a nice setting that gives me a good FPS, luckily.

Last edited by Joozey; 12/16/10 20:26.

Click and join the 3dgs irc community!
Room: #3dgs
Re: Gaussian Blur PP Pixel Shader [Re: Joozey] #350536
12/16/10 20:59
12/16/10 20:59
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
the tex2d in your loop causes the gradient error to be triggered. If you use tex2dlod, and fill in float4(pos1.x,pos1.y,0,0) for the texture argument, it will work laugh. Found the solution here, also the only thread about it on the whole internet. In English at least. Shaders are SO completely undocumented.

http://www.gamedev.net/community/forums/topic.asp?topic_id=466629

the [loop] keyword as suggested there didnt work for me.

Last edited by Joozey; 12/16/10 20:59.

Click and join the 3dgs irc community!
Room: #3dgs
Re: Gaussian Blur PP Pixel Shader [Re: Joozey] #350540
12/16/10 21:43
12/16/10 21:43
Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
TSG_Torsten Offline OP

User
TSG_Torsten  Offline OP

User

Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
Thank you for this great tip! But i really don't understand why it doesn't work for the other function... Confusing laugh

I've updated the code above and you can remove the USE_STATIC_VALUES define if you want to use dynamic ones... (if you didn't already have rewritten the shader wink )

Regards
TSGames

Last edited by TSG_Torsten; 12/16/10 21:51.
Page 2 of 3 1 2 3

Moderated by  adoado, checkbutton, mk_1, Perro 

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