Hello Guest

Author Topic: Multipass shaders in Otter2d  (Read 1837 times)

0 Members and 1 Guest are viewing this topic.

KrissLaCross

  • Member
  • Posts: 1
    • View Profile
Multipass shaders in Otter2d
« on: November 01, 2016, 03:15:13 PM »
Hi!

So I'm trying to implement a basic multipass shader using this tutorial: https://gamedevelopment.tutsplus.com/tutorials/how-to-write-a-smoke-shader--cms-25587
But I'm struggling with seting up the multipass system aka "The Frame Buffer Trick".
The simpel algorithm goes as follow:
  • Pass A through your shader, render onto B.
  • Render B to the screen.
  • Pass B through shader, render onto A.
  • Render A to your screen.
  • Repeat 1.

Where A and B are either two textures or two buffers. I decided too use two Surfaces, because that makes it easier to create some cool stuf later on.
But I'm struggling with step one, I'm just not really sure how too do this in Otter2d. I tried the following:
Code: [Select]
bufferA.Shader = shader;
bufferB.Draw(bufferA);
bufferB.Render();
tempBuffer = bufferA;
bufferA = bufferB;
bufferB = tempBuffer;

using the this simpel shader:
Code: [Select]
uniform sampler2D texture;

void main() {
vec4 color = texture2D(texture, gl_TexCoord[0].xy);
color.r += 0.01;
gl_FragColor = color;
}

But sadly it doesn't work and I don't know what I'm doing wrong.

I appreciate any help!
Thanks for your time!

~KrissLaCross

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Multipass shaders in Otter2d
« Reply #1 on: November 02, 2016, 03:33:47 PM »
Hey!  I have time for a quick answer at the moment:  Surfaces actually have the "AddShader" method which allows them to automagically take care of each pass.  You can see how this is done around Surface.cs Line 561, and implement this yourself if you want, or if you're using a Surface already you should be able to just keep adding shaders to it and have it use all of them in the order they're added.