![Image](http://farm3.static.flickr.com/2223/2539480217_98eded00ca.jpg)
![Image](http://farm4.static.flickr.com/3262/2539485573_fafb06c67e.jpg)
Heres you're problem, ATI (Well especially the 200M which Halifax has) don't support uniform arrays in GLSL (Only HLSL), atleast under Irrlicht atm. Infact it used to not work on any card, but we fixed it by acquiring the right uniform location, unfortunately ATI cards still refuse to accept them. So whats happening here is "vecValues[0].x" is evaluating to 0 (Because the 200M can't find the uniform variable since its in an array), and no bloom gets added!uniform vec4 vecValues[2];
Main.cpp'firstScreen' Registers:[begin:1, count:1]
'vecValue0' Registers:[begin:0, count:1]
HLSL Variable to set not found: 'vecValue2'. Available variables are:
'colorMap' Registers:[begin:0, count:1]
'firstScreen' Registers:[begin:1, count:1]
'vecValue0' Registers:[begin:0, count:1]
HLSL Variable to set not found: 'vecValue3'. Available variables are:
'colorMap' Registers:[begin:0, count:1]
'firstScreen' Registers:[begin:1, count:1]
'vecValue0' Registers:[begin:0, count:1]
Code: Select all
#include "PostProcessing.h"
#include <Irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
int main(int argc, char **argv)
{
IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9);
video::IVideoDriver *driver = device->getVideoDriver();
scene::ISceneManager *smgr = device->getSceneManager();
gui::IGUIEnvironment *guienv = device->getGUIEnvironment();
device->getFileSystem()->addZipFileArchive("map-20kdm2.pk3");
smgr->addOctTreeSceneNode(smgr->getMesh("20kdm2.bsp"));
smgr->addCameraSceneNodeFPS();
//invert colors
// PostProcessing *PP_Test = new PostProcessing(smgr,"Shaders/PP_GL_Invert.fx","Shaders/PP_DX_Invert.fx",video::EPST_PS_1_4,512,256);
//build up the effect chain for bloom
PostProcessing *PP_Test = new PostProcessing(smgr,"Shaders/PP_GL_Bloom1.fx","Shaders/PP_DX_Bloom1.fx",video::EPST_PS_3_0,512,256);
PP_Test->setShaderParameters(0.5f);
PostProcessing *Test2 = PP_Test->addMaterial("Shaders/PP_GL_Bloom2.fx","Shaders/PP_DX_Bloom2.fx",video::EPST_PS_3_0,128,128);
Test2->setShaderParameters(0.01f);
Test2 = Test2->addMaterial("Shaders/PP_GL_Bloom3.fx","Shaders/PP_DX_Bloom3.fx",video::EPST_PS_3_0,128,128);
Test2->setShaderParameters(0.01f);
Test2 = Test2->addMaterial("Shaders/PP_GL_Bloom4.fx","Shaders/PP_DX_Bloom4.fx",video::EPST_PS_3_0,512,256);
Test2->setShaderParameters(0.7f);
Test2->setSecondMap(PP_Test->getFirstMap(),video::ETC_CLAMP);
//the main loop
while(device->run())
{
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,150,180,255));
//render the scene into the postprocessing texture
driver->setRenderTarget(PP_Test->getFirstMap(), true, true, video::SColor(255,150,180,255));
smgr->drawAll();
driver->setRenderTarget(0);
//render the effect chain
PP_Test->renderEffect();
guienv->drawAll();
driver->endScene();
}
}
device->drop();
}
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.
*/
#ifndef _POSTPROCESSING_H_
#define _POSTPROCESSING_H_
#include <irrlicht.h>
using namespace irr;
class PostProcessing_SetShaderConstants : public video::IShaderConstantSetCallBack
{
public:
PostProcessing_SetShaderConstants();
virtual void OnSetConstants(video::IMaterialRendererServices *services,
s32 userdata);
//void setShaderParameters(f32 *paras){shaderparameters = paras;}
void setShaderParameter(u32 index, f32 param);
private:
f32 sp[8];
};
/**
* \brief Class which manages postprocessing effects
*
* To apply the effect, run
* \code
* driver->setRenderTarget(postprocessing->getFirstMap(), true, true, video::SColor(255,150,180,255));
* \endcode
* or similar before you render anything and run
* \code
* driver->setRenderTarget(0);
* postprocessing->renderEffect();
* \endcode
* to actually run the shaders and render the result to the screen.
*/
class PostProcessing
{
public:
/**
* \brief Constructor
* \param smgr Scene manager which is used for the post progressing
* \param filename_gl Path to the GLSL script
* \param filename_dx Path to the HLSL script
* \param type_ps Type of the pixel shader
* \param res_x Horizontal resolution of the used texture
* \param res_y Vertical resolution of the used texture
*/
PostProcessing(scene::ISceneManager *smgr,
const c8 *filename_gl,
const c8 *filename_dx,
video::E_PIXEL_SHADER_TYPE type_ps,
s32 res_x,
s32 res_y);
/**
* \brief Destructor
*/
~PostProcessing();
/**
* \brief Adds another stage and inserts it after this stage
* \param filename_gl Path to the GLSL script
* \param filename_dx Path to the HLSL script
* \param type_ps Type of the pixel shader
* \param res_x Horizontal resolution of the used texture
* \param res_y Vertical resolution of the used texture
*/
PostProcessing *addMaterial(const c8 *filename_gl,
const c8 *filename_dx,
video::E_PIXEL_SHADER_TYPE type_ps,
s32 res_x,
s32 res_y);
/**
* \brief Renders this postprocessing chain
*/
void renderEffect();
/**
* \brief Sets the second texture
*/
void setSecondMap(video::ITexture *tex, video::E_TEXTURE_CLAMP mode)
{
secondmap = tex;
material.setTexture(1,secondmap);
material.TextureLayer[1].TextureWrap = mode;
}
/**
* \brief Sets the parameters of the shader
*/
void setShaderParameters(f32 para1 = 0, f32 para2 = 0, f32 para3 = 0, f32 para4 = 0,
f32 para5 = 0, f32 para6 = 0, f32 para7 = 0, f32 para8 = 0)
{
shaderparameters[0] = para1;
shaderparameters[1] = para2;
shaderparameters[2] = para3;
shaderparameters[3] = para4;
shaderparameters[4] = para5;
shaderparameters[5] = para6;
shaderparameters[6] = para7;
shaderparameters[7] = para8;
}
/**
* \brief Returns a pointer to the material
*/
video::SMaterial *getMaterial(){return(&material);}
/**
* \brief Returns a pointer to the first texture
*/
video::ITexture *getFirstMap(){return(firstmap);}
/**
* \brief Returns a pointer to the second texture
*/
video::ITexture *getSecondMap(){return(secondmap);}
private:
PostProcessing_SetShaderConstants shadercallback;
scene::ISceneManager *scenemgr;
video::IVideoDriver *driver;
video::S3DVertex vertices[4];
video::SMaterial material;
s32 matid;
f32 shaderparameters[8];
PostProcessing *prevstage;
PostProcessing *nextstage;
video::ITexture *firstmap;
video::ITexture *secondmap;
};
#endif
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.
*/
#include "PostProcessing.h"
PostProcessing_SetShaderConstants::PostProcessing_SetShaderConstants()
{
for (u32 i = 0; i < 8; i ++)
sp[i] = 0.0f;
}
void PostProcessing_SetShaderConstants::OnSetConstants(video::IMaterialRendererServices *services, s32 userdata)
{
// set the materialparameters
//services->setPixelShaderConstant("vecValues",shaderparameters, 8);
services->setPixelShaderConstant("vecValue0", &sp[0], 1);
services->setPixelShaderConstant("vecValue1", &sp[1], 1);
services->setPixelShaderConstant("vecValue2", &sp[2], 1);
services->setPixelShaderConstant("vecValue3", &sp[3], 1);
services->setPixelShaderConstant("vecValue4", &sp[4], 1);
services->setPixelShaderConstant("vecValue5", &sp[5], 1);
services->setPixelShaderConstant("vecValue6", &sp[6], 1);
services->setPixelShaderConstant("vecValue7", &sp[7], 1);
if(userdata == 1)
{
//set Textures for openGL Shaders
int texture1 = 0;
services->setPixelShaderConstant("texture1",(float*)&texture1, 1);
int texture2 = 1;
services->setPixelShaderConstant("texture2",(float*)&texture2, 1);
}
}
void PostProcessing_SetShaderConstants::setShaderParameter(u32 index, f32 param)
{
if (index > 7)
return;
sp[index] = param;
}
PostProcessing::PostProcessing(scene::ISceneManager *smgr, const c8 *filename_gl,
const c8 *filename_dx, video::E_PIXEL_SHADER_TYPE type_ps, s32 res_x, s32 res_y)
{
driver = smgr->getVideoDriver();
if(driver->getDriverType() == video::EDT_OPENGL || driver->getDriverType() == video::EDT_DIRECT3D9)
{
vertices[0] = video::S3DVertex(-1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 1.0f);
vertices[1] = video::S3DVertex(-1.0f, 1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 0.0f);
vertices[2] = video::S3DVertex( 1.0f, 1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 0.0f);
vertices[3] = video::S3DVertex( 1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 1.0f);
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
scenemgr = smgr;
prevstage = NULL;
nextstage = NULL;
setShaderParameters();
//shadercallback.setShaderParameters(&shaderparameters[0]);
shadercallback.setShaderParameter(0, shaderparameters[0]);
shadercallback.setShaderParameter(1, shaderparameters[1]);
shadercallback.setShaderParameter(2, shaderparameters[2]);
shadercallback.setShaderParameter(3, shaderparameters[3]);
shadercallback.setShaderParameter(4, shaderparameters[4]);
shadercallback.setShaderParameter(5, shaderparameters[5]);
shadercallback.setShaderParameter(6, shaderparameters[6]);
shadercallback.setShaderParameter(7, shaderparameters[7]);
if(driver->getDriverType() == video::EDT_OPENGL)
{
matid = gpu->addHighLevelShaderMaterialFromFiles
(
"PP_GL_Vertex.fx",
"main",
video::EVST_VS_1_1,
filename_gl,
"main",
type_ps,
&shadercallback,
video::EMT_SOLID,
1
);
}else
{
matid = gpu->addHighLevelShaderMaterialFromFiles
(
"PP_DX_Vertex.fx",
"main",
video::EVST_VS_1_1,
filename_dx,
"main",
type_ps,
&shadercallback,
video::EMT_SOLID,
0
);
}
firstmap = driver->createRenderTargetTexture(core::dimension2d<s32>(res_x,res_y));
secondmap = NULL;
material.Wireframe = false;
material.Lighting = false;
material.setTexture(0,firstmap);
material.TextureLayer[0].TextureWrap = video::ETC_CLAMP;
material.MaterialType = (video::E_MATERIAL_TYPE)matid;
}
}
PostProcessing::~PostProcessing()
{
if(nextstage != NULL)
{
delete nextstage;
}
}
PostProcessing *PostProcessing::addMaterial(const c8 *filename_gl, const c8 *filename_dx,
video::E_PIXEL_SHADER_TYPE type_ps, s32 res_x, s32 res_y)
{
nextstage = new PostProcessing(scenemgr,filename_gl,filename_dx,type_ps,res_x,res_y);
return nextstage;
}
void PostProcessing::renderEffect()
{
u16 indices[] = {0,1,2,0,2,3};
driver->setMaterial(material);
if(nextstage != NULL)
{
driver->setRenderTarget(nextstage->getFirstMap(), true, true, video::SColor(255,150,180,255));
driver->drawIndexedTriangleList(vertices, 6, indices, 2);
driver->setRenderTarget(0);
nextstage->renderEffect();
}else
{
driver->drawIndexedTriangleList(vertices, 6, indices, 2);
}
}
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.
*************************************************************************/
/************************************************************************
HLSL Bloom
Effect 1: Filtering out dark Colors, needs PS 1.4
*************************************************************************/
//float4 vecValues[2];
sampler2D colorMap : register(s0);
float vecValue0, vecValue1, vecValue2, vecValue3, vecValue4, vecValue5, vecValue6, vecValue7;
float4 main( float2 Tex:TEXCOORD0 ) : COLOR0
{
float4 Color = tex2D(colorMap, Tex.xy);
if(dot(Color.rgb, float3(0.299f, 0.587f, 0.114f)) < vecValue0)
{
Color.rgb = 0;
}
return 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.
*************************************************************************/
/************************************************************************
HLSL Bloom
Effect 2: Horizontal blur, needs PS 2.0
*************************************************************************/
//float4 vecValues[2];
static int blurRadius = 5;
sampler2D colorMap : register(s0);
float vecValue0, vecValue1, vecValue2, vecValue3, vecValue4, vecValue5, vecValue6, vecValue7;
float4 main(float2 Tex:TEXCOORD0):COLOR0
{
float2 pos[11];
pos[0] = float2(-5.0,0.0);
pos[1] = float2(-4.0,0.0);
pos[2] = float2(-3.0,0.0);
pos[3] = float2(-2.0,0.0);
pos[4] = float2(-1.0,0.0);
pos[5] = float2(0.0,0.0);
pos[6] = float2(1.0,0.0);
pos[7] = float2(2.0,0.0);
pos[8] = float2(3.0,0.0);
pos[9] = float2(4.0,0.0);
pos[10] = float2(5.0,0.0);
float samples[11];
samples[0] = 0.01222447;
samples[1] = 0.02783468;
samples[2] = 0.06559061;
samples[3] = 0.12097757;
samples[4] = 0.17466632;
samples[5] = 0.19741265;
samples[6] = 0.17466632;
samples[7] = 0.12097757;
samples[8] = 0.06559061;
samples[9] = 0.02783468;
samples[10] = 0.01222447;
float4 Color = float4(0.0,0.0,0.0,0.0);
float2 tempTex = Tex;
int i;
for (i = 0; i < 11; i ++)
{
Color += tex2D(colorMap, tempTex + (pos[i] * vecValue0)) * samples[i];
}
return Color;
//float4 Color = tex2D(colorMap,Tex.xy);
//float2 tempTex;
//tempTex.y = Tex.y;
//for(int i=-blurRadius;i<=blurRadius;i++)
//{
// tempTex.x = Tex.x+i*vecValues[0].x;
// Color += tex2D(colorMap,tempTex.xy);
//}
//return 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.
*************************************************************************/
/************************************************************************
HLSL Bloom
Effect 3: Vertical blur, needs PS 2.0
*************************************************************************/
//float4 vecValues[2];
static int blurRadius = 5;//number of px
sampler2D colorMap : register(s0);
float vecValue0, vecValue1, vecValue2, vecValue3, vecValue4, vecValue5, vecValue6, vecValue7;
float4 main(float2 Tex:TEXCOORD0):COLOR0
{
float2 pos[11];
pos[0] = float2(0.0,-5.0);
pos[1] = float2(0.0,-4.0);
pos[2] = float2(0.0,-3.0);
pos[3] = float2(0.0,-2.0);
pos[4] = float2(0.0,-1.0);
pos[5] = float2(0.0,0.0);
pos[6] = float2(0.0,1.0);
pos[7] = float2(0.0,2.0);
pos[8] = float2(0.0,3.0);
pos[9] = float2(0.0,4.0);
pos[10] = float2(0.0,5.0);
float samples[11];
samples[0] = 0.01222447;
samples[1] = 0.02783468;
samples[2] = 0.06559061;
samples[3] = 0.12097757;
samples[4] = 0.17466632;
samples[5] = 0.19741265;
samples[6] = 0.17466632;
samples[7] = 0.12097757;
samples[8] = 0.06559061;
samples[9] = 0.02783468;
samples[10] = 0.01222447;
float4 Color = float4(0.0,0.0,0.0,0.0);
float2 tempTex = Tex;
int i;
for (i = 0; i < 11; i ++)
{
Color += tex2D(colorMap, tempTex + (pos[i] * vecValue0)) * samples[i];
}
return Color;
// float4 Color = tex2D(colorMap,Tex.xy);
// float2 tempTex;
// tempTex.x = Tex.x;
// for(int i=-blurRadius;i<=blurRadius;i++)
// {
// tempTex.y = Tex.y+i*vecValues[0].x;
// Color += tex2D(colorMap,tempTex.xy);
// }
// return 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
*************************************************************************/
//float4 vecValues[2];
sampler2D colorMap : register(s0);
sampler2D firstScreen : register(s1);
float vecValue0, vecValue1, vecValue2, vecValue3, vecValue4, vecValue5, vecValue6, vecValue7;
float4 main(float2 Tex: TEXCOORD0):COLOR0
{
float4 Color = tex2D(firstScreen,Tex.xy);
Color += vecValue0*tex2D(colorMap,Tex);
return Color;
}
No that is just in the constructor of the shader constant callback. But in the PostProcessing construtor it sets the values to whatever the values are from the shaderparameters array.Slin wrote:Thanks for your explanation BlindSide
Halifax, I sometimes get those errors as well and I have no idea why...
But also look at your code again, even if it would work, the values would all be 0. You don´t assign another value to sp.
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.
*/
#include "PostProcessing.h"
void PostProcessing_SetShaderConstants::OnSetConstants(video::IMaterialRendererServices *services, s32 userdata)
{
if(userdata == 0)
{
// set the materialparameters
services->setPixelShaderConstant("vecValues",shaderparameters, 8);
}else
{
int i;
c8 *constname;
// set the materialparameters
for(i = 0; i < 8; i++)
{
constname = new char[strlen("Value") + (int)log(i+1) + 2];
snprintf(constname, strlen("Value") + (int)log(i+1) + 2, "%s%d", "Value", i);
services->setPixelShaderConstant((const c8*)constname,&shaderparameters[i], 1);
delete[] constname;
}
//set Textures for openGL Shaders
int texture = 0;
services->setPixelShaderConstant("Texture0",(float*)&texture, 1);
texture += 1;
services->setPixelShaderConstant("Texture1",(float*)&texture, 1);
}
}
PostProcessing::PostProcessing(scene::ISceneManager *smgr, const c8 *filename_gl,
const c8 *filename_dx, video::E_PIXEL_SHADER_TYPE type_ps, s32 res_x, s32 res_y, PostProcessing *previous)
{
driver = smgr->getVideoDriver();
if(driver->getDriverType() == video::EDT_OPENGL || driver->getDriverType() == video::EDT_DIRECT3D9)
{
vertices[0] = video::S3DVertex(-1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 1.0f);
vertices[1] = video::S3DVertex(-1.0f, 1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 0.0f);
vertices[2] = video::S3DVertex( 1.0f, 1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 0.0f);
vertices[3] = video::S3DVertex( 1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 1.0f);
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
scenemgr = smgr;
prevstage = previous;
nextstage = NULL;
setShaderParameters();
shadercallback.setShaderParameters(&shaderparameters[0]);
if(driver->getDriverType() == video::EDT_OPENGL)
{
matid = gpu->addHighLevelShaderMaterialFromFiles
(
"PP_GL_Vertex.fx",
"main",
video::EVST_VS_1_1,
filename_gl,
"main",
type_ps,
&shadercallback,
video::EMT_SOLID,
1
);
}else
{
matid = gpu->addHighLevelShaderMaterialFromFiles
(
"PP_DX_Vertex.fx",
"main",
video::EVST_VS_1_1,
filename_dx,
"main",
type_ps,
&shadercallback,
video::EMT_SOLID,
0
);
}
firstmap = driver->createRenderTargetTexture(core::dimension2d<s32>(res_x,res_y));
secondmap = NULL;
material.Wireframe = false;
material.Lighting = false;
material.setTexture(0,firstmap);
material.TextureLayer[0].TextureWrap = video::ETC_CLAMP;
material.MaterialType = (video::E_MATERIAL_TYPE)matid;
}
}
PostProcessing::~PostProcessing()
{
if(nextstage != NULL)
{
delete nextstage;
}
}
PostProcessing *PostProcessing::addMaterial(const c8 *filename_gl, const c8 *filename_dx,
video::E_PIXEL_SHADER_TYPE type_ps, s32 res_x, s32 res_y)
{
nextstage = new PostProcessing(scenemgr,filename_gl,filename_dx,type_ps,res_x,res_y,this);
return nextstage;
}
void PostProcessing::renderEffect()
{
u16 indices[] = {0,1,2,0,2,3};
driver->setMaterial(material);
if(nextstage != NULL)
{
driver->setRenderTarget(nextstage->getFirstMap(), true, true, video::SColor(255,150,180,255));
driver->drawIndexedTriangleList(vertices, 6, indices, 2);
driver->setRenderTarget(0);
nextstage->renderEffect();
}else
{
driver->drawIndexedTriangleList(vertices, 6, indices, 2);
}
}
Yeah I was just trying it out because working with the GLSL version wasn't an option last night. Something was really messed up, and I am guessing it was with my drivers or something, but a restart fixed it. But for some reason when I compiled with OpenGL the program ran at about 1 FPS and took a crap load of time to start up, but with Direct3D9 it ran at about 80 FPS and starting up fast so that I could debug easier. At the least, I was just messing around.BlindSide wrote:First of all, that advice was meant for GLSL not HLSL, so I have no idea why you are doing this in HLSL even though HLSL worked fine anyway.
Was that directed at me?BlindSide wrote: By the way, I'm extremely confused here, why is an HLSL file labeled with GLSL ...
I don't quite understand why you are using all that for setting the values. Do you plan on extending pass 8 user data variables in the shaders? If not, then I don't see why you can't just set it explicity, or use the internal Irrlicht strings.Slin wrote: It works nice if the PostProcessing.cpp looks like this (it does only effect something when using OpenGL):