Solved
-
The_Glitch
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Solved
The issue was indeed the shader in Irrlicht it seems you don't need to pass any viewport info just the standard vertex shader then use the blur pixel shader.
Last edited by The_Glitch on Sun Oct 26, 2014 9:32 pm, edited 2 times in total.
Re: Another Render To Texture issue....
Your first two drawAll call's don't seem to have a point (you just overdraw them later on again). And the point where you overdraw them again also has no point if you work screenquad's as those will be your final render. So I think you have 2 renders which basically do nothing but cost time. On the other hand you don't seem to ever render into default_scene as you only set that, change some visiblity and then already reset the rendertarget again without ever having rendered anything into it.
I don't know about your problem with blurring as you didn't post that code. But generally you don't blur the texture you pass in, but use a second texture for the result. If you do that your original texture is not modified and you can re-use it for more steps.
I don't know about your problem with blurring as you didn't post that code. But generally you don't blur the texture you pass in, but use a second texture for the result. If you do that your original texture is not modified and you can re-use it for more steps.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
The_Glitch
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: Another Render To Texture issue....
Well I've been reading into post processing there are steps I didn't include I'll trip it to barebones and see what I can do. Also for the blur I just take the render to texture and apply is to a screenquad which has a blur shader applied to the quad. If I need to use that result do I just add another screenquad that overlays both screenquads? You know like one quad with a normal texture and the 2nd screenquad with the blur shader.
Re: Another Render To Texture issue....
No, you don't need 2 screenquads. You can put several textures in a single material - so you only need one screensquad + a material with several textures + a corresponding shader that combines those textures. Otherwise it would become really complicated :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
The_Glitch
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: Another Render To Texture issue....
Yeah that's my problem. If I draw a quad and pass the render to texture that needs to be blurred for lets say a simple glow, In order to keep those blurred results do I need to build onto that shader? I thought you could blur the texture on the quad then somehow render that back into the render texture again so that If I need another shader to use those results it would be there to do so.
Re: Another Render To Texture issue....
Sorry, I just don't get what you mean. Build onto that shader? What do you mean?
Think of render-target-textures as the image results of a function. You pass in any number of textures and you get as result the render-target-texture. Then you can use that texture in the next shader as input texture. It really works like variables in functions.
Normal Code:
result = function(parameter1, parameter2);
result2 = function2(paremeter1, result);
Same code when thinking in shaders:
rendertargettexture1 = shader(materialtexture1, materialtexture2)
rendertargettexture2 = shader(materialtexture1, rendertargettexture1)
So yes - if you use different variables for the results (aka different rtt's) then they stay around and you can re-use them in the next shader.
I can't help the feeling that we are somehow talking over each other ... maybe you need to draw images so I understand what your problem actually is.
Think of render-target-textures as the image results of a function. You pass in any number of textures and you get as result the render-target-texture. Then you can use that texture in the next shader as input texture. It really works like variables in functions.
Normal Code:
result = function(parameter1, parameter2);
result2 = function2(paremeter1, result);
Same code when thinking in shaders:
rendertargettexture1 = shader(materialtexture1, materialtexture2)
rendertargettexture2 = shader(materialtexture1, rendertargettexture1)
So yes - if you use different variables for the results (aka different rtt's) then they stay around and you can re-use them in the next shader.
I can't help the feeling that we are somehow talking over each other ... maybe you need to draw images so I understand what your problem actually is.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
The_Glitch
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: Another Render To Texture issue....
Yeah I think so to I'll see what I can come up with later and I'll post or pm you.
-
The_Glitch
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: Another Render To Texture issue....
Alright I came back to this issue. I've simplified things by using Irrlichts render to texture example and I still can't get it to blur I'm starting to think it's the shader myself.
And heres the simple blur shader.
I even passed the screensize in the shader itself to try and find the problem.
Code: Select all
#include <irrlicht.h>
#include "driverChoice.h"
#include "CScreenQuadSceneNode.h"
using namespace irr;
using namespace video;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
IrrlichtDevice* device = 0;
bool UseHighLevelShaders = true;
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
class Blur_Shader : public video::IShaderConstantSetCallBack
{
public:
Blur_Shader() : FirstUpdate(true)
{
}
virtual void OnSetConstants(video::IMaterialRendererServices* services,
s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
if (FirstUpdate)
{
WorldViewProjID = services->getVertexShaderConstantID("matViewProjection");
// width = services->getVertexShaderConstantID("viewWidth");
//Height = services->getVertexShaderConstantID("viewHeight");
}
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
core::matrix4 matWorldViewProj = worldViewProj;
services->setVertexShaderConstant(WorldViewProjID, worldViewProj.pointer(), 16);
/*
float Width_float = 1600.0f;
float Height_float = 900.0f;
services->setVertexShaderConstant(width, reinterpret_cast<f32*>(&Width_float), 1);
services->setVertexShaderConstant(Height, reinterpret_cast<f32*>(&Height_float), 1);
*/
}
private:
s32 WorldViewProjID;
//s32 width;
//s32 Height;
bool FirstUpdate;
};
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;
// ask the user if we should use high level shaders for this example
driverType = video::EDT_DIRECT3D9;
// create a NULL device to detect screen resolution
IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
core::dimension2d<u32> deskres = nulldevice->getVideoModeList()->getDesktopResolution();
nulldevice->drop();
// create device and exit if creation failed
// create device
MyEventReceiver receiver;
// now the dimensions can be used to create the real device
device = createDevice(video::EDT_DIRECT3D9, /*core::dimension2d<u32> (1024, 768)*/deskres, 32, true, false, true, &receiver);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT);
io::path vsFileName2; // filename for the vertex shader
io::path psFileName2; // filename for the pixel shader
// Cg can also handle this syntax
psFileName2 = "C://Users//GodMan//Desktop//shader-pipeline//bin//Win32-VisualStudio//media//shaders//glow_great.hlsl";
vsFileName2 = psFileName2; // both shaders are in the same file
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
s32 blur_shader = 0;
if (gpu)
{
Blur_Shader* mc_8 = new Blur_Shader();
// create the shaders depending on if the user wanted high level
// or low level shaders:
// Choose the desired shader type. Default is the native
// shader type for the driver, for Cg pass the special
// enum value EGSL_CG
const video::E_GPU_SHADING_LANGUAGE shadingLanguage =
video::EGSL_CG; video::EGSL_DEFAULT;
// create material from high level shaders (hlsl, glsl or cg)
blur_shader = gpu->addHighLevelShaderMaterialFromFiles(
vsFileName2, "vs_main", video::EVST_VS_2_0,
psFileName2, "ps_main", video::EPST_PS_2_0, // Remember to change this to there shader names!!!!!!!!!!!!!!!
mc_8, video::EMT_SOLID, 0, shadingLanguage);
mc_8->drop();
}
// load and display animated fairy mesh
scene::IAnimatedMeshSceneNode* fairy = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("../../media/faerie.md2"));
if (fairy)
{
fairy->setMaterialTexture(0,
driver->getTexture("../../media/faerie2.bmp")); // set diffuse texture
fairy->setMaterialFlag(video::EMF_LIGHTING, true); // enable dynamic lighting
fairy->getMaterial(0).Shininess = 20.0f; // set size of specular highlights
fairy->setPosition(core::vector3df(-10,0,-100));
fairy->setMD2Animation ( scene::EMAT_STAND );
}
scene::ISceneNode* n = smgr->addCubeSceneNode();
if (n)
{
n->setMaterialTexture(0, driver->getTexture("../../media/t351sml.jpg"));
n->setMaterialFlag(video::EMF_LIGHTING, false);
}
// add white light
smgr->addLightSceneNode(0, core::vector3df(-15,5,-105),
video::SColorf(1.0f, 1.0f, 1.0f));
// set ambient light
smgr->setAmbientLight(video::SColor(0,60,60,60));
// create test cube
scene::ISceneNode* test = smgr->addCubeSceneNode(60);
// let the cube rotate and set some light settings
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(
core::vector3df(0.3f, 0.3f,0));
test->setPosition(core::vector3df(-100,0,-100));
test->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting
test->addAnimator(anim);
anim->drop();
// set window caption
device->setWindowCaption(L"Irrlicht Engine - Render to Texture and Specular Highlights example");
// create render target
video::ITexture* rt = 0;
scene::ICameraSceneNode* fixedCam = 0;
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
{
rt = driver->addRenderTargetTexture(core::dimension2d<u32>(1024,1024), "RTT1", ECF_A8R8G8B8);
test->setMaterialTexture(0, rt); // set material of cube to render target
// add fixed camera
//fixedCam = smgr->addCameraSceneNode(0, core::vector3df(10,10,-80),
// core::vector3df(-10,10,-100));
}
else
{
// create problem text
gui::IGUISkin* skin = env->getSkin();
gui::IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
gui::IGUIStaticText* text = env->addStaticText(
L"Your hardware or this renderer is not able to use the "\
L"render to texture feature. RTT Disabled.",
core::rect<s32>(150,20,470,60));
text->setOverrideColor(video::SColor(255,255,255,255));
}
// add fps camera
scene::ICameraSceneNode* fpsCamera = smgr->addCameraSceneNodeFPS();
fpsCamera->setPosition(core::vector3df(-50,50,-150));
// disable mouse cursor
device->getCursorControl()->setVisible(false);
CScreenQuadSceneNode *quad = new CScreenQuadSceneNode(smgr->getRootSceneNode(), smgr, 0);
quad->flipHorizontal()
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0);
if (receiver.IsKeyDown(KEY_ESCAPE))
exit(0);
if (rt)
{
// draw scene into render target
// set render target texture
driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,0));
// make cube invisible and set fixed camera as active camera
//test->setVisible(false);
// smgr->setActiveCamera(fixedCam);
// draw whole scene into render buffer
smgr->drawAll();
// set back old render target
// The buffer might have been distorted, so clear it
driver->setRenderTarget(0, true, true, 0);
// make the cube visible and set the user controlled camera as active one
//test->setVisible(false);
//smgr->setActiveCamera(fpsCamera);
}
// draw scene normally
smgr->drawAll();
env->drawAll();
quad->setMaterialType((video::E_MATERIAL_TYPE)blur_shader);
quad->getMaterial(0).setTexture(0, rt);
quad->render();
driver->endScene();
// display frames per second in window title
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Render to Texture and Specular Highlights example";
str += " FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop(); // drop device
return 0;
}
And heres the simple blur shader.
Code: Select all
float4x4 matViewProjection;
float viewWidth = 1600.0f;
float viewHeight = 900.0f;
struct VS_INPUT
{
float4 Position : POSITION0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
};
VS_OUTPUT vs_main( VS_INPUT Input )
{
VS_OUTPUT Output;
Output.Position = float4(Input.Position.xy, 0,1) ;
Output.Texcoord.x = Input.Position.x - viewWidth;
Output.Texcoord.y = Input.Position.y - viewHeight;
return( Output );
}
sampler glow_scene: register(s0);
struct PS_INPUT
{
float2 Texcoord : TEXCOORD0;
};
float4 ps_main(float2 Texcoord: TEXCOORD0) : COLOR
{
float2 samples[12] = {
-0.326212, -0.405805,
-0.840144, -0.073580,
-0.695914, 0.457137,
-0.203345, 0.620716,
0.962340, -0.194983,
0.473434, -0.480026,
0.519456, 0.767022,
0.185461, -0.893124,
0.507431, 0.064425,
0.896420, 0.412458,
-0.321940, -0.932615,
-0.791559, -0.597705,
};
float4 sum = tex2D(glow_scene, Texcoord);
for (int i = 0; i < 12; i++){
sum += tex2D(glow_scene, Texcoord + 0.128 * samples[i]) ;
}
return sum /13;
}
-
The_Glitch
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: Another Render To Texture issue....
Alright I think I found the solution or the issue. If I used a render target texture of 1024 x 1024 the shader doesn't seem to blur larger textures but If I keep it between 128 x 128 or 256 x 256 or even 512 x 512 It seems to work fine. I'm not sure entirely If it's just the low resolution of the texture or If it's actually blurring the texture, but it appears to be working thanks cutealien.