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

Author Topic: SFML multiple shaders to RenderImage  (Read 5681 times)

0 Members and 1 Guest are viewing this topic.

Xyro

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
SFML multiple shaders to RenderImage
« on: May 09, 2011, 09:55:39 am »
I'm trying to implement multiple global shaders so I came up with this :

Code: [Select]

foreach (Shader shader in globalShaders)
{
     Program.renderImage.Draw(new Sprite(Program.renderImage.Image), shader);
}


But for some reason this gives me really strange artifacts and the only way I found to fix this is by copying the image over to another image(which is going to lag since its done every frame and multiple times as there is more then one shader) then clearing the renderImage and then drawing it.

Is there a workaround so I can make this work ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML multiple shaders to RenderImage
« Reply #1 on: May 09, 2011, 11:02:26 am »
You can't read and write the same image at the same time, so yes you can't do it without at least two images.

But you don't need to copy the image every time, you can use a kind of double-buffering:

RenderImage image1 = new RenderImage(...);
RenderImage image2 = new RenderImage(...);

RenderImage front = image1;
RenderImage back = image2;

...

foreach (Shader shader in globalShaders)
{
    // draw "back" into "front"
    front.Clear();
    front.Draw(new Sprite(back.Image), shader);
    front.Display();

    // swap front and back buffers
    RenderImage temp = front;
    front = back;
    back = temp;
}

// the final result is in the variable "back"
« Last Edit: January 09, 2016, 07:19:45 pm by Laurent »
Laurent Gomila - SFML developer

Xyro

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
SFML multiple shaders to RenderImage
« Reply #2 on: May 09, 2011, 05:52:09 pm »
Worked perfectly, thanks again laurent :)