Main Menu

GLSL Shaders

Started by CodeBunny, September 19, 2011, 03:03:59

Previous topic - Next topic

spasi

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.

CodeBunny

...That might actually work. Let me test it.

CodeBunny

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.

CodeBunny

Nevermind, it works completely. I was making a dumb mistake.

Thank you very much, spasi!

Suds

Quote from: Chuck on September 30, 2011, 19:36:32
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().

Chuck

       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