SFML community forums

Help => Graphics => Topic started by: dydya-stepa on December 01, 2011, 06:34:03 pm

Title: pixel shader to scale the image ?
Post by: dydya-stepa on December 01, 2011, 06:34:03 pm
need to scale image down and up.

non sfml related but maybe anyone know how to do it in opengl ?
Title: pixel shader to scale the image ?
Post by: Laurent on December 01, 2011, 06:36:00 pm
Do you want to display the image scaled, or to create an image which is a scaled version of another?
Title: pixel shader to scale the image ?
Post by: dydya-stepa on December 01, 2011, 06:49:54 pm
i actually want to have a scaling filter. then i'll be able to combine it with other shader effects.

E.g. blur:

Downscale 4x
Blur_x
Blur_y
..
..
Upscale 4x

it'll be much faster rather then blurring the whole image. (i can have multiple blur passes then)
Title: pixel shader to scale the image ?
Post by: Laurent on December 01, 2011, 07:20:07 pm
So you're looking for a scaling algorithm. I think it's pretty easy to find, have you tried to Google it?
Title: pixel shader to scale the image ?
Post by: dydya-stepa on December 01, 2011, 09:06:00 pm
i found how it's done in hlsl :
they just set some properties on a pass - I was thinking something similar exists in glsl.


Code: [Select]
float4 DownFilter( in float2 Tex : TEXCOORD0 ) : COLOR0
{
    float4 Color = 0;

    for (int i = 0; i < 16; i++)
    {
        Color += tex2D( g_samSrcColor, Tex + TexelCoordsDownFilter[i].xy );
    }

    return Color / 16;
}




//-----------------------------------------------------------------------------
// Technique: PostProcess
// Desc: Performs post-processing effect that down-filters.
//-----------------------------------------------------------------------------
technique PostProcess
{
    pass p0
    <
        float fScaleX = 0.25f;
        float fScaleY = 0.25f;
    >
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 DownFilter();
        ZEnable = false;
    }
}
Title: pixel shader to scale the image ?
Post by: Laurent on December 01, 2011, 10:39:17 pm
When you say "something similar", do you mean the whole technique and pass stuff, or just passing variables to the shader?
Title: pixel shader to scale the image ?
Post by: dydya-stepa on December 02, 2011, 12:57:56 pm
i meant i can easily create scaling filter just by saying

float fScaleX = 0.25f;
float fScaleY = 0.25f;

but the sader code stays unaffected.
Title: pixel shader to scale the image ?
Post by: dydya-stepa on December 02, 2011, 01:01:30 pm
but probably i can and will have to imitate this pass thing by just drawing it scaled into RenderTarget - is that possible? then shader would process only new (downscaled) subset of fragments (pixels or whatever)
Title: pixel shader to scale the image ?
Post by: Laurent on December 02, 2011, 01:47:52 pm
Quote
i meant i can easily create scaling filter just by saying

float fScaleX = 0.25f;
float fScaleY = 0.25f;

but the sader code stays unaffected.

You can easily pass values from your C++ code to the shader.

Quote
but probably i can and will have to imitate this pass thing by just drawing it scaled into RenderTarget - is that possible? then shader would process only new (downscaled) subset of fragments (pixels or whatever)

Yes it's possible, and probably much more efficient than using a shader.
Title: pixel shader to scale the image ?
Post by: dydya-stepa on December 02, 2011, 05:30:42 pm
are there already / are you planning to add any support for multipass shaders? for multiple passes in sfml out of the box ?
Title: pixel shader to scale the image ?
Post by: Laurent on December 02, 2011, 07:31:23 pm
What is "support for multipass shaders" for you? What can't you do with the current API?
Title: pixel shader to scale the image ?
Post by: dydya-stepa on December 03, 2011, 10:54:39 am
i can do it with an assembler :) but should I try ?

having passes would be nice. so i don't have to create my own RenderTargetChain. DirectX and XNA has this for example. SFML is at lower level.

I'm just starting opengl and shaders. So i'm not very good in terms and what should be what shouldn't be.