Author Topic: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae  (Read 8200 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #15 on: May 03, 2017, 09:16:17 pm »
That looks quite wrong. Can you create a test case for this that I can compile and see for myself?

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #16 on: May 03, 2017, 10:05:47 pm »
Yes, Sure...
Below is my onDrawFrame()  ->
Code: [Select]
public void onDrawFrame(GL10 gl) {

if (this.hasToCreateBuffer) {
Logger.log("Recreating buffer...");
hasToCreateBuffer = false;
fb = new FrameBuffer(w, h);

}

if (touchTurn != 0) {

plane.rotateY(touchTurn);
plane1.rotateY(touchTurn);

touchTurn = 0;
}

if (touchTurnUp != 0) {
plane.rotateX(touchTurnUp);

plane1.rotateX(touchTurnUp);

touchTurnUp = 0;
}




fb.setRenderTarget(target1);
fb.setBlittingShader(shader1);
fb.clear(new RGBColor(123, 223, 237));
world.renderScene(fb);
world.draw(fb);
fb.display();

fb.setRenderTarget(target2);
fb.setBlittingShader(shader2);
fb.blit(target1, 0, 0, 0, fb.getHeight(), target1.getWidth(), target1.getHeight() , fb.getWidth(), -fb.getHeight(), -1, false);


fb.removeRenderTarget();

fb.blit(target2, 0, 0, 0, fb.getHeight(), target1.getWidth(), target1.getHeight() , fb.getWidth(), -fb.getHeight(), -1, false);

blitNumber(lfps, 5, 5);
            Log.e("fps ","f p s = " +lfps );
//fb.display();

if (System.currentTimeMillis() - time >= 1000) {
lfps = fps;
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}



Is this enough ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #17 on: May 04, 2017, 08:31:10 am »
Can't you just zip your project and send it to me? That would make it much easier for me to get something similar up and running.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #18 on: May 04, 2017, 09:51:25 am »
Oh, and apart from that...your code misses the display()-calls required. That would explain the OOM errors as well, because it creates buffer after buffer without actually using them.
After blitting, you have to add a call to display() to actually swap the display buffers/render into the render target.

See the example that I put a link to above for...well, an example...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #19 on: May 04, 2017, 10:07:40 am »
Here's an example for desktop jPCT:

Code: [Select]
import java.awt.Color;

import com.threed.jpct.FrameBuffer;
import com.threed.jpct.GLSLShader;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Loader;
import com.threed.jpct.Texture;
import com.threed.jpct.World;


public class RTT
{
  private World world;
  private FrameBuffer buffer;


  public static void main(String[] args)
    throws Exception
  {
    new RTT().loop();
  }


  private void loop()
    throws Exception
  {
    buffer = new FrameBuffer(640, 480, FrameBuffer.SAMPLINGMODE_NORMAL);
    buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
    buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

    world = new World();

    Texture t = new Texture("d.png");
    Texture t1 = new Texture(512, 512);
    Texture t2 = new Texture(512, 512);

    GLSLShader shady = new GLSLShader(Loader.loadTextFile("vertex.glsl"), Loader.loadTextFile("fragment.glsl"));
    shady.setUniform("colorMap", 0);

    while (!org.lwjgl.opengl.Display.isCloseRequested())
    {
      buffer.setRenderTarget(t1);
      buffer.setVirtualDimensions(buffer.getWidth(), buffer.getHeight());

      buffer.clear(Color.BLUE);
      world.renderScene(buffer);
      world.draw(buffer);

      buffer.blit(t, 0, 0, 0, 0, t.getWidth(), t.getHeight(), buffer.getWidth(), buffer.getHeight(), -1, false);

      display();
      buffer.removeRenderTarget();
     
      buffer.setRenderTarget(t2);
      buffer.setBlittingShader(shady);
      buffer.blit(t1, 0, 0, 0, 0, t1.getWidth(), t1.getHeight(), buffer.getWidth(), buffer.getHeight(), -1, false);
     
      display();
      buffer.removeRenderTarget();
      buffer.setBlittingShader(null);

      buffer.blit(t2, 0, 0, 0, 0, t1.getWidth(), t1.getHeight(), buffer.getWidth(), buffer.getHeight(), -1, false);
      display();

      Thread.sleep(10);
    }
    buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
    buffer.dispose();
    System.exit(0);
  }


  public void display()
  {
    buffer.update();
    buffer.displayGLOnly();
  }
}


Vertex shader
Code: [Select]
varying vec2 texCoord;

void main(void)
{
gl_Position = ftransform();
texCoord = gl_MultiTexCoord0.xy;
}

Fragment shader
Code: [Select]
varying vec2 texCoord;

uniform sampler2D colorMap;

void main (void)
{
vec4 base = texture2D(colorMap, texCoord);
gl_FragColor = vec4(base.r*2.0,0.0,base.g,base.a);
}

What this basically does, is to blit a texture into a render target, set a blitting shader that eliminates green and boosts red and blit the first target texture into a second one using that shader. It then displays the result by blitting the second target onto the screen.

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #20 on: May 04, 2017, 12:47:48 pm »
Ohh ! I missed the display method ! I see . . .

I'll check the code snippet you provided as soon I reach home... and let you know ... :)

and yes ... sorry for the inconvenience .

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #21 on: May 05, 2017, 09:15:26 pm »
Hello Egon,
I tried to port your Desktop snippet into my demo...But for now it displays me red screen(My Default NPOT texture color)
I'm Uploading a  test Case zip...
And I have few more questions->
1]]
My logcat view was flooded with this->
Code: [Select]
05-05 23:16:09.875 27957-27975/? D/jPCT-AE: Binding buffers (1/1)!
05-05 23:16:09.876 27957-27975/? D/jPCT-AE: Binding texture 2
05-05 23:16:09.876 27957-27975/? D/jPCT-AE: Binding texture 3
05-05 23:16:09.877 27957-27975/? D/jPCT-AE: Binding texture 4
05-05 23:16:09.877 27957-27975/? D/jPCT-AE: Binding texture 5
05-05 23:16:09.877 27957-27975/? D/jPCT-AE: Buffer switches: 4
05-05 23:16:09.877 27957-27975/? D/jPCT-AE: Unbinding buffers (1)!
So is this Normal ? Because It buries other debug messages ...


2]]
if I remove blitnumber() method ...(or any fb.blit() in general) which is present immediately after my fb.blit(target....) then it ignores my shader applied on to the screen and displays me normal render .
Is this behavior normal ?
« Last Edit: May 05, 2017, 09:20:40 pm by SonicBurst2 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #22 on: May 06, 2017, 07:10:00 pm »
I downloaded your example, but I'm not sure what to make of it. You have a shader1, that you never use. You have a target and a target2 that you never use...!?

I'm not sure how it's supposed to work, but the basic idea would be something like this:

  • assign the render target for the first step
  • render the first step, call display(), remove the render target
  • assign the render target for the second step
  • render/blit the second step, call display(), remove the target
  • blit the result

Also keep in mind that assigning a blitting shader doesn't do anything if you don't blit anything. In your code, you don't assign shader1 at all, then you set "target" as a render target, render the scene in "target", blit "target1" (which is red) all over it and then blit the (still red) "target1" into the actual frame buffer without a target. I fail to see the point in that.

About the second question...that might be related to the blitting buffers. In case of doubt, render the dummy world after blitting if all you do in one pass is blitting . That will flush the blitting buffer for sure. Or, as a cheap alternative, blit a transparent texture onto the final image (1*1 pixel is enough).

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #23 on: May 06, 2017, 07:25:54 pm »
Sorry My bad.... I had actually uploaded the wrong file ! :-\
I have re-uploaded the file ...
which is giving me red screen...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #24 on: May 07, 2017, 06:53:34 pm »
Hmm...that one refers to grass, face_norm and img...neither of which is in the package... ???

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #25 on: May 07, 2017, 07:27:37 pm »
Ohh yes! ,I removed them because it was exceeding the file size limit....they were quite big ~512*512 ...
May I please ask you to find this attached image and replace the grass and face_norm with the same ?

Sorry for the inconvenience caused , I am feeling embarrassed now :-[

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #26 on: May 07, 2017, 08:53:21 pm »
Ok, I had a look, but I wasn't able to compile the shaders (tried on PowerVR). You are using some 3.0 language constructs, so that I would have to set that version but if you do, a lot of stuff has to be changed as well like (varying -> out, attribute -> in, texture2D() -> texture()) and while I tried to do that, I ran into some issue that I didn't have the time solve ATM.

Anyway, I still think that your render logic is flawed. I think it should look something like this:

Code: [Select]
fb.setVirtualDimensions(target.getWidth(), target.getHeight());

// Render scene into target
fb.setRenderTarget(target);
fb.clear(new RGBColor(123, 223, 237));
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

// Blur target by blitting it into target1
fb.setRenderTarget(target1);
fb.setBlittingShader(shader1);
fb.blit(target, 0, 0, 0, fb.getHeight(), target1.getWidth(), target1.getHeight() , fb.getWidth(), -fb.getHeight(), -1, false);
                        // Maybe a transparent dummy blit here to flush the pipeline
fb.display();
fb.removeRenderTarget();

// Blur target1 by blitting it into target2
fb.setRenderTarget(target2);
fb.setBlittingShader(shader2);
fb.blit(target1, 0, 0, 0, fb.getHeight(), target1.getWidth(), target1.getHeight() , fb.getWidth(), -fb.getHeight(), -1, false);
                         // Maybe a transparent dummy blit here to flush the pipeline
fb.display();
fb.removeRenderTarget();
fb.setBlittingShader(null);

fb.blit(target2, 0, 0, 0, fb.getHeight(), target2.getWidth(), target2.getHeight() , fb.getWidth(), -fb.getHeight(), -1, false);
fb.display();

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #27 on: May 08, 2017, 10:19:15 am »
I'll try this code soon... :)
But regarding the shader problem , it compiles fine on my pretty old device(snapdragon 410 , with adreno 306 , 2 GB RAM ).
I'll try to get my hands on the PowerVR device for verifying, if possible . BTW , which device was used for testing ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #28 on: May 08, 2017, 10:58:00 am »
A Redmi Note 2, which was the cheapest one that I could get with a PowerVR 6xxx chip.

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #29 on: May 11, 2017, 09:25:22 pm »
Thank you Egon !...
The Code snippet worked.. :)