[C++] Postprocessing class and shaders (GLSL and HLSL)
[C++] Postprocessing class and shaders (GLSL and HLSL)
I am very new to Irrlicht and coding in C++, but worked with GameStudio for the last five years. During that time I learned very little C++, C-Script, Lite-C and HLSL.
At the moment I am really interested in graphics programming and thus nearly the first thing I wanted to get working with Irrlicht was postprocessing.
I found several snippets but none which really was as I wanted it to be. Because of that I decided to create my own class for postprocessing effects which allows chaining of shaders and sending parameters to them.
I also plan to create a collection of several postprocessing shaders. I´ve got Bloom and inverting colors done in GLSL and HLSL.
It is all released under the MIT-license.
You can download it all, together with a compiled version here: http://files.filefront.com/Irrlicht+Pos ... einfo.html
Please have a look at the readme!
If you have any proposals to improve it, please tell me, as well as any postprocessing shader wishes you have got
Here are two screenshots showing the bloom:
I hope you like it
At the moment I am really interested in graphics programming and thus nearly the first thing I wanted to get working with Irrlicht was postprocessing.
I found several snippets but none which really was as I wanted it to be. Because of that I decided to create my own class for postprocessing effects which allows chaining of shaders and sending parameters to them.
I also plan to create a collection of several postprocessing shaders. I´ve got Bloom and inverting colors done in GLSL and HLSL.
It is all released under the MIT-license.
You can download it all, together with a compiled version here: http://files.filefront.com/Irrlicht+Pos ... einfo.html
Please have a look at the readme!
If you have any proposals to improve it, please tell me, as well as any postprocessing shader wishes you have got
Here are two screenshots showing the bloom:
I hope you like it
Yeah that does sound cool, almost like the Ogre system. I will like to have a look at the code too. One thing I have to say is that I would like to see someone do some HDR rendering with Irrlicht.
EDIT:
Well I tried running this demo, and I have to say, I got a crap load of shader compilation errors.
EDIT:
Well I tried running this demo, and I have to say, I got a crap load of shader compilation errors.
TheQuestion = 2B || !2B
Errors
The GLSL language has no such thing as 'tex2D' the name of the function is 'texture2D'.Irrlicht Engine version 1.4
Microsoft Windows XP Personal Service Pack 2 (Build 2600)
Using renderer: OpenGL 2.1.7412
ATI MOBILITY RADEON XPRESS 200: ATI Technologies Inc.
OpenGL driver version is 1.2 or better.
GLSL version: 1.3
Loaded shader: scripts/common.shader for scripts/common.shader
Loaded shader: scripts/models.shader for scripts/models.shader
Loaded shader: scripts/e7.shader for textures/e7/e7walldesign01b
Loaded texture: textures/e7/e7walldesign01b.jpg
Loaded texture: textures/e7/e7steptop2.jpg
Loaded texture: textures/e7/e7dimfloor.jpg
Loaded texture: textures/e7/e7brickfloor01.jpg
Loaded texture: textures/e7/e7bmtrim.jpg
Loaded texture: textures/e7/e7sbrickfloor.jpg
Loaded texture: textures/e7/e7brnmetal.jpg
Loaded texture: textures/e7/e7beam02_red.jpg
Loaded texture: textures/e7/e7swindow.jpg
Loaded texture: textures/e7/e7bigwall.jpg
Loaded texture: textures/e7/e7panelwood.jpg
Loaded texture: textures/e7/e7beam01.jpg
Loaded texture: textures/gothic_floor/xstepborder5.jpg
Loaded texture: textures/liquids/lavahell.jpg
Loaded texture: textures/e7/e7steptop.jpg
Loaded texture: textures/gothic_trim/metalblackwave01.jpg
Loaded texture: textures/stone/pjrock1.jpg
Loaded texture: models/mapobjects/timlamp/timlamp.tga
Loaded shader: scripts/sfx.shader for textures/sfx/flame1side
Loaded texture: models/mapobjects/gratelamp/gratetorch2.jpg
Loaded texture: models/mapobjects/gratelamp/gratetorch2b.tga
Loaded mesh: 20kdm2.bsp
Needed 45ms to create OctTree SceneNode.(357 nodes, 10684 polys)
GLSL shader failed to compile
Fragment shader failed to compile with the following errors:
ERROR: 0:37: 'tex2D' : no matching overloaded function found
ERROR: 0:37: '=' : cannot convert from 'const float' to 'undefined interpolatio
n 4-component vector of float'
ERROR: 0:40: 'assign' : cannot convert from 'const int' to '3-component vector
of float'
ERROR: 3 compilation errors. No code generated.
GLSL shader failed to compile
Fragment shader failed to compile with the following errors:
ERROR: 0:38: 'tex2D' : no matching overloaded function found
ERROR: 0:38: '=' : cannot convert from 'const float' to '4-component vector of
float'
ERROR: 0:44: 'tex2D' : no matching overloaded function found
ERROR: 3 compilation errors. No code generated.
GLSL shader failed to compile
Fragment shader failed to compile with the following errors:
ERROR: 0:38: 'tex2D' : no matching overloaded function found
ERROR: 0:38: '=' : cannot convert from 'const float' to '4-component vector of
float'
ERROR: 0:44: 'tex2D' : no matching overloaded function found
ERROR: 3 compilation errors. No code generated.
GLSL shader failed to compile
Fragment shader failed to compile with the following errors:
ERROR: 0:38: 'tex2D' : no matching overloaded function found
ERROR: 0:38: '=' : cannot convert from 'const float' to '4-component vector of
float'
ERROR: 0:39: 'tex2D' : no matching overloaded function found
ERROR: 3 compilation errors. No code generated.
TheQuestion = 2B || !2B
i think tex2d is HLSL.
see http://msdn.microsoft.com/en-us/library ... S.85).aspx
direct mapping...
http://www.codeplex.com/hl2glsl/Wiki/Vi ... and%20GLSL
see http://msdn.microsoft.com/en-us/library ... S.85).aspx
direct mapping...
http://www.codeplex.com/hl2glsl/Wiki/Vi ... and%20GLSL
Yes correct, 'tex2D' belongs to HLSL.dlangdev wrote:i think tex2d is HLSL.
see http://msdn.microsoft.com/en-us/library ... S.85).aspx
direct mapping...
http://www.codeplex.com/hl2glsl/Wiki/Vi ... and%20GLSL
EDIT:
Also, I am curious as to why the horizontal and vertical blurring were not combined into one shader instead of multiple passes.
TheQuestion = 2B || !2B
I don´t understand why it works fine for me and some others, but that is probably okay. This code was my first contact with GLSL and thus I don´t really know the differences between HLSL and GLSL yet.Halifax wrote: Yes correct, 'tex2D' belongs to HLSL.
I changed it in my files and will upload it together with the next version of my class and hopefully one or two more shaders in the next days.
It is faster than doing it in one pass with a similar quality because of less texture lookups.Halifax wrote: Also, I am curious as to why the horizontal and vertical blurring were not combined into one shader instead of multiple passes.
http://www.blackpawn.com/texts/blur/default.html[/url]
Ah, okay, I understand Slin. Here are the shaders I got working with GLSL, but it doesn't really do the bloom effect it just blurs the image. Either way the errors are all erased, and I will try to get the bloom effect working for you:
PP_GL_Bloom1
PP_GL_Bloom2
PP_GL_Bloom3
PP_GL_Bloom4
PP_GL_Bloom1
Code: Select all
/***********************************************************************
Copyright (c) 2008 Nils Daumann
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*************************************************************************/
/************************************************************************
GLSL Bloom
Effect 1: Filtering out dark Colors, needs PS 1.4
*************************************************************************/
uniform vec4 vecValues[2];
uniform sampler2D texture1;
void main()
{
vec4 Color = texture2D(texture1,gl_TexCoord[0].xy);
if(dot(Color.rgb,vec3(0.299f,0.587f,0.114f)) < vecValues[0].x)
{
//Color.rgb = 0;
Color.rgb = vec3(0);
}
gl_FragColor = Color;
}
Code: Select all
/***********************************************************************
Copyright (c) 2008 Nils Daumann
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*************************************************************************/
/************************************************************************
GLSL Bloom
Effect 2: Horizontal blur, needs PS 2.0
*************************************************************************/
uniform vec4 vecValues[2];
#define blurRadius 5
uniform sampler2D texture1;
void main()
{
vec4 Color = texture2D(texture1,gl_TexCoord[0].xy);
vec2 tempTex;
tempTex.y = gl_TexCoord[0].y;
for(int i=-blurRadius;i<=blurRadius;i++)
{
tempTex.x = gl_TexCoord[0].x+i*vecValues[0].x;
Color += texture2D(texture1,tempTex.xy);
}
gl_FragColor = Color/(blurRadius*2+1);
}
Code: Select all
/***********************************************************************
Copyright (c) 2008 Nils Daumann
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*************************************************************************/
/************************************************************************
GLSL Bloom
Effect 3: Vertical blur, needs PS 2.0
*************************************************************************/
uniform vec4 vecValues[2];
#define blurRadius 5
uniform sampler2D texture1;
void main()
{
vec4 Color = texture2D(texture1,gl_TexCoord[0].xy);
vec2 tempTex;
tempTex.x = gl_TexCoord[0].x;
for(int i=-blurRadius;i<=blurRadius;i++)
{
tempTex.y = gl_TexCoord[0].y+i*vecValues[0].x;
Color += texture2D(texture1,tempTex.xy);
}
gl_FragColor = Color/(blurRadius*2+1);
}
Code: Select all
/***********************************************************************
Copyright (c) 2008 Nils Daumann
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*************************************************************************/
/************************************************************************
GLSL Bloom
Effect 4: Add the blurred image to the original one, needs PS 2.0
*************************************************************************/
uniform vec4 vecValues[2];
uniform sampler2D texture1;
uniform sampler2D texture2;
void main()
{
vec4 Color = texture2D(texture2, gl_TexCoord[0].xy);
Color += vecValues[0].x * texture2D(texture1, gl_TexCoord[0].xy);
gl_FragColor = Color;
}
TheQuestion = 2B || !2B
Yeah, it might be a problem with ATI cards, that is definitely possible. But no, I don't think it has anything to do with texture sizes because I checked your code and they are all POT textures.
Maybe BlindSide will be here sooner or later though and enlighten us on why this doesn't work no ATI cards.
One thing I have to ask, though, is can you make a build of your code for DX9, and post that please?
Maybe BlindSide will be here sooner or later though and enlighten us on why this doesn't work no ATI cards.
One thing I have to ask, though, is can you make a build of your code for DX9, and post that please?
TheQuestion = 2B || !2B
Here is a an executable of it with directx: http://files.filefront.com/PostProcessi ... einfo.html
The result you get seems as if the second texture isn´t set...
The result you get seems as if the second texture isn´t set...