video frame region post-process effect

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
guruhenry
Posts: 16
Joined: Tue Aug 03, 2010 1:53 pm
Location: Italy

video frame region post-process effect

Post by guruhenry »

Hi,
I'm studying how to post-process a region of a video frame, for example to apply a mosaic effect in a small quad region.

In each rendering cycle I have:
1. a texture that represents the current source frame
2. a quad that represents the effect rectangular region
3. a RTT as a destination of the process, that will contain the processed frame

Let me summarize my workflow:
step 1: texture A is copied to the destination RTT to create the background
step 2: the quad polygon which represents the FX region is drawn to the RTT using the texture A as a source to fetch the source frame pixels and process them, through the following shader:

...
struct PS_OUTPUT
{
float4 RGBColor : COLOR0; // Pixel color
};

sampler2D tex0 : register(s0);

PS_OUTPUT pixelMain( float4 Position : POSITION,
float4 Diffuse : COLOR0,
float2 TexCoord : TEXCOORD0,
float2 VPosition : VPOS)
{
PS_OUTPUT Output;

const float2 fInvViewportDimensions = float2(1.0f/Resolution.x, 1.0f/Resolution.y); // Resolution is the frame resolution
const float factor = 15.0f; // Mosaic resolution

float2 src = float2(VPosition * fInvViewportDimensions + fInvViewportDimensions * 0.5f);

src.x = saturate(floor(src.x * factor) / factor);
src.y = saturate(floor(src.y * factor) / factor);

Output.RGBColor = tex2D(tex0, src);
return Output;
}

And now the problem: using a texture created with addTexture as source texture, modifying the factor value some black vertical and/or horizontal stripes appear.
Using a temporary RTT (addRenderTargetTexture) as source texture (adding an extra step in which I copy the texture A to tempRTT) all works well, also modifying the factor value.
What's the difference between the standard source texture and the temp RTT in this workflow? I would like to avoid the extra step mentioned.

Can anyone help me to find a solution?

Many thanks in advance
guruhenry
Posts: 16
Joined: Tue Aug 03, 2010 1:53 pm
Location: Italy

Re: video frame region post-process effect

Post by guruhenry »

Hi,

Isn't there anyone that have an idea about why using a texture loaded from a file as a source in my shader has a different behaviour than a RTT filled with the same texture (draw2DImage) and used as source?
Is there anyone that knowing Irrlicht or the shader technology in the deep see something wrong in my workflow?

Thanks
CuteAlien
Admin
Posts: 10038
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: video frame region post-process effect

Post by CuteAlien »

Maybe different resolutions between your original source texture and the rtt you use? Then the resolution calculations would be wrong in one case maybe.
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
guruhenry
Posts: 16
Joined: Tue Aug 03, 2010 1:53 pm
Location: Italy

Re: video frame region post-process effect

Post by guruhenry »

RTT:
m_poRenderTarget0 = m_poVideoDriver->addRenderTargetTexture(dimension2d<u32>(m_sResolution.m_lWidth, m_sResolution.m_lHeight), "RTT0", ECF_A8R8G8B8);

Texture:
m_pInputTexture = m_poVideoDriver->addTexture(dimension2d<u32>(m_sResolution.m_lWidth, m_sResolution.m_lHeight), "Surface", ECF_A8R8G8B8);

...same resolution...
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Re: video frame region post-process effect

Post by sudi »

I am guessing it has something to do with the texture filtering applied.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Post Reply