Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] SSAO buffer texture wrong  (Read 335 times)
0 Members and 1 Guest are viewing this topic.
Offline mudlee

Junior Devvie


Medals: 4
Exp: 5 years



« Posted 2018-05-11 08:03:28 »

Hi guys.

I need some help regarding to SSAO. I've followed this popular tutorial: https://learnopengl.com/Advanced-Lighting/SSAO.
Somehow, the occlusion factor is always 1, so no changes can be observed.

I debugged through the code and:
  • The GBuffer textures are correct
  • The problem is might be the SSAO texture itself.

So... when I generate the ssao texture onto the screen, it's totally red and if I change the ssao shader output value to any float, it remains red. That's why I think, the problem is somewhere over there.

The code is the same as in the tutorial, but here it is the ssao buffer:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
FBO = glGenFramebuffers();
blurFBO = glGenFramebuffers();

glBindFramebuffer(GL_FRAMEBUFFER, FBO);

LOGGER.debug("> Creating color texture...");
int ssaoColorTexture = glGenTextures();
glBindTexture(GL_TEXTURE_2D, ssaoColorTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Engine.properties.getWindowWidth(), Engine.properties.getWindowHeight(), 0, GL_RGB, GL_FLOAT, (ByteBuffer) null);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ssaoColorTexture, 0);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
     throw new RuntimeException("SSAO buffer is not completed");
}


In the fragment shader I just use
1  
layout (location = 0) out float OUT_Color;


And assign it:
1  
OUT_Color =1.0f

And the value above does not affect the texture in the FBO.

What can be the problem, where should I continue debugging?
Offline orange451

JGO Kernel


Medals: 363
Projects: 6
Exp: 6 years


Your face? Your ass? What's the difference?


« Reply #1 - Posted 2018-05-11 14:23:52 »

Well, you've assigned your texture to:
1  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED...)

So, it only has the red channel of color.


--
But if I understand correctly... even if you output something like:
1  
OUT_Color = 0.0f;

It is still red?


--
Are you drawing a fullscreen quad on your screen with that shader bound? Otherwise nothing will change, because there's nothing being sent to the fragment shader.


Also... a lot of this code looks like it was lazily taken from John Chapman's blog...

First Recon. A java made online first person shooter!
Offline mudlee

Junior Devvie


Medals: 4
Exp: 5 years



« Reply #2 - Posted 2018-05-11 14:35:16 »

I do the exact same stuff that is on the page I linked. After the SSAO texture is generated, I pass it to the last shader where it affects the final color. As I saw it has no effect on the fragment's color, I started to debug if something is wrong with the SSAO texture.

First, I checked the GBuffer textures, all are good. Second, I checked the SSAO texture if its wrong and it is. No matter what I set to the OUT_Color, the texture will be completely red.

I tried what if I expect RGBA and output a vec4 from the shader with a fixed value. In that case, the texture turned to white and no matter what I set for the OUT_Color, it remains white. Now I think the problem is around the framebuffer code, but went 10 times through it and looks good. Maybe I have to sleep and retry tomorrow Smiley

BTW, when I write I checked the texture I mean I draw it onto the upper right using nanovg.

Here is the render logic:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
    public void onRender() {
        GL11.glClearColor(1f, 1f, 1f, 1f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);

        batches.values().forEach(RenderBatch::initGPUDataStores); // it sets up VAO, VBO, etc

        computeSSAOGeometryData(() -> {
            ssaoGeometryShader.bind();
            batches.values().forEach(renderBatch -> {
                // TODO: what if it does not have texture?
                ssaoGeometryShader.updateMaterialDiffuseTexture(renderBatch);
                renderBatch.render();
            });
            ssaoGeometryShader.unbind();
        });

        computeSSAOTexture(() -> {
            ssaoShader.bind();
            batches.values().forEach(renderBatch -> {
                renderBatch.render();
            });
            ssaoShader.unbind();
        });

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        batches.values().forEach(renderBatch -> {
            renderBatch.getMaterial().getShader().bind();

            ((StandardShader)renderBatch.getMaterial().getShader()).ssao(ssaoBuffer);

            renderBatch.render();
            renderBatch.getMaterial().getShader().unbind();
        });
    }

    private void computeSSAOGeometryData(Runnable batchRendering) {
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, gBuffer.getGFBO());
        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT);

        batchRendering.run();

        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    }

    private void computeSSAOTexture(Runnable batchRendering) {
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, ssaoBuffer.getFBO());
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

        batchRendering.run();

        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline mudlee

Junior Devvie


Medals: 4
Exp: 5 years



« Reply #3 - Posted 2018-05-14 07:52:10 »

And forgot to mention that the code was taken (ported to java) from learnopengl.com where the guy clearly wrote down that he used John Chapman's as a source.
Offline mudlee

Junior Devvie


Medals: 4
Exp: 5 years



« Reply #4 - Posted 2018-05-16 13:25:15 »

I think, I found some issues, so I collect all of them here for the future generation.

  • Don't forget to disable GL_BLEND during the geometry pass
  • The texture was completely red, because something went wrong in the SSAO shader and the I used white in the glClearColor which was a basic completly white base, so the whole turned into red
  • Some of the GPUs' drivers don't support GL_RGB16F, you have to use GL_RGBA16F or GL_RGBA32F in the GBuffer for normals and positions

The SSAO texture is still not OK, I'll write back when I find the problem.
Offline mudlee

Junior Devvie


Medals: 4
Exp: 5 years



« Reply #5 - Posted 2018-05-16 14:57:43 »

SSAO texture is now OK, there were one more typo Smiley
Pages: [1]
  ignore  |  Print  
 
 

 
DesertCoockie (56 views)
2018-05-13 18:23:11

nelsongames (88 views)
2018-04-24 18:15:36

nelsongames (78 views)
2018-04-24 18:14:32

ivj94 (763 views)
2018-03-24 14:47:39

ivj94 (95 views)
2018-03-24 14:46:31

ivj94 (647 views)
2018-03-24 14:43:53

Solater (108 views)
2018-03-17 05:04:08

nelsongames (189 views)
2018-03-05 17:56:34

Gornova (430 views)
2018-03-02 22:15:33

buddyBro (1090 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!