Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: pixel shader to scale the image ?  (Read 10142 times)

0 Members and 1 Guest are viewing this topic.

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
pixel shader to scale the image ?
« 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
pixel shader to scale the image ?
« Reply #1 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?
Laurent Gomila - SFML developer

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
pixel shader to scale the image ?
« Reply #2 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)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
pixel shader to scale the image ?
« Reply #3 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?
Laurent Gomila - SFML developer

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
pixel shader to scale the image ?
« Reply #4 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;
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
pixel shader to scale the image ?
« Reply #5 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?
Laurent Gomila - SFML developer

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
pixel shader to scale the image ?
« Reply #6 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.

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
pixel shader to scale the image ?
« Reply #7 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)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
pixel shader to scale the image ?
« Reply #8 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.
Laurent Gomila - SFML developer

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
pixel shader to scale the image ?
« Reply #9 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
pixel shader to scale the image ?
« Reply #10 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?
Laurent Gomila - SFML developer

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
pixel shader to scale the image ?
« Reply #11 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.

 

anything