Hello Guest

GLSL Shaders

  • 20 Replies
  • 27713 Views
*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: GLSL Shaders
« Reply #15 on: October 11, 2011, 09:44:05 »
It sounds like premultiplied alpha will solve your problem. Read this post for details. Keep in mind you don't need to modify your textures, you can do the alpha pre-multiplication in the shader.

Re: GLSL Shaders
« Reply #16 on: October 11, 2011, 11:14:56 »
...That might actually work. Let me test it.

Re: GLSL Shaders
« Reply #17 on: October 11, 2011, 11:35:17 »
It does! Great. :D

EDIT: Actually, the problem persists - Premultiplied alpha simple reduces the result significantly. Let me think about this some more.

EDIT#2: Actually, no, this is weird - my blending function won't take. Let me check my blending code.
« Last Edit: October 11, 2011, 12:01:14 by CodeBunny »

Re: GLSL Shaders
« Reply #18 on: October 11, 2011, 12:03:55 »
Nevermind, it works completely. I was making a dumb mistake.

Thank you very much, spasi!

*

Offline Suds

  • *
  • 11
Re: GLSL Shaders
« Reply #19 on: October 17, 2011, 06:25:33 »
While I agree the existing tutorials aren't adequate, it helps to start from a minimal working example.  I fixed the compile problem on the wiki, plus a logic issue that was causing it to fail.  I'm still not a fan of the way the code is organized, but it at least works now.

I have a single-file versions of that tutorial here, as well as a conversion that uses GL20 instead of ARB extensions.

https://bitbucket.org/chuck/lwjgl-sandbox/src/tip/src/main/java/tutorials/wiki



I was just working through this tutorial, and I was unable to get it to work. So I went over it, line by line. And I found that the printLogInfo method returns true if there was an error, and false if there was not.

Then peppered through the tutorial, there's "if(!printLogInfo(obj)) useShader = false".

In draw, "if(useShader) //use the shader". This translates to english roughly as:

"If there was not not an error, dont use shaders." or, "Only use shaders if there as an error." (I think. double/triple negatives get confusing after a while)

The code worked when I reversed the return values of printLogInfo().

*

Offline Chuck

  • *
  • 42
  • aka sproingie on freenode
Re: GLSL Shaders
« Reply #20 on: October 17, 2011, 17:11:18 »
Code: [Select]
       if (length > 1) {
            // We have some info we need to output.
            ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
            iVal.flip();
            ARBShaderObjects.glGetInfoLogARB(obj, iVal, infoLog);
            byte[] infoBytes = new byte[length];
            infoLog.get(infoBytes);
            String out = new String(infoBytes);
            System.out.println("Info log:\n"+out);
        }
        else return true;
        return false;

It in fact does return false if there was an error and true if it succeeded.  The code style of this method in the wiki tutorial would result in heavy objects being thrown at me if it my peers went over it in a code review.  I really need to fix it, and I suppose update the wiki page too.  I didn't write the tutorial, so the fixes I actually want to apply probably wouldn't respect the author's intent.  Cleaning up the logic here would probably be okay tho.

This may be a more readable demo for shaders, but it does abstract a lot out: https://bitbucket.org/chuck/lwjgl-sandbox/src/tip/src/main/java/sandbox/misc/HelloShader.java

« Last Edit: October 17, 2011, 17:12:56 by Chuck »