Ported Shader 'Unknow error'

edited April 2014 in GLSL / Shaders

I am trying to test out these pixel shaders in Processing. The shaders are originally from console emulators and written in Cg.

The author provided a tool to convert from Cg to GLSL ES 1.0 and even a webGL-based viewer for testing them. This works great for me, but when I try using the GLSL shader in a sketch I get java.lang.RuntimeException: Cannot link shader program: Unknow error.

Here's a pastebin of one of the converted shaders - http://pastebin.com/u2hHXy0T
Like I said it works in WebGL but not via loadShader(). I don't know enough about shader language to try to debug (complete newbie to it) - can anyone tell me why it might be & if there's a solution?

Many thanks in advance!

Answers

  • Hi, shader programming is a complex topic, but there are many resources available online to get started. Shaders used within programming frameworks like Processing, OpenFrameworks, three.js, or the RetroArch viewer you mention in your post, have additional format/conventions that you need to follow, so porting from one to another might be a bit tricky.

    The PShader tutorial is a good starting point to learn the conventions adopted in Processing to send data to the shaders.

    From a quick look at the code in the pastebin, I'd say that it first needs to be split in separate files, one for the vertex shader, and the other for the fragment shader: everything after #if defined(VERTEX) until right before #elif defined(FRAGMENT) should go into a vertex shader file, while the code after #elif defined(FRAGMENT) and before #endif should go into the fragment shader.

    The other big problem is with the naming convention of the uniforms, which are different between Processing and RetroArch. For instance, I believe MVPMatrix should be renamed to transform in Processing, but not quite sure about the others. FrameDirection, FrameCount, OutputSize, etc. probably need to be set manually from the sketch code using the PShader.set() function. All of this can be quite difficult to figure out without knowing GLSL, so again I'd recommend to start by taking a look at the PShader tutorial and other pages linked from there.

  • edited April 2014

    Once again thanks so much for your help Anticode and sorry for my ignorance…!

    The shader is only 1% of my project (a filter to smooth off lo-res pixels like how 8-bit console emulators do) so at first I was hoping to skip learning GLSL until later and just implement some pre-existing code. I briefly looked at the PShader tutorial, in there it states " Processing follows the specification set by OpenGL ES" so I assumed WebGL code would run seamlessly but I see now that it's not quite that simple.

    Now my aim is to learn WebGL with resources like learningwebgl.com enough to program some 2D pixel FX. When I am at that stage and after fully reading the PShader tutorial will I understand how to port to Processing? for example things like the MVPMatrix > transform naming conventions you mentioned?

    TBH, even after learning GLSL I doubt I'll understand the complex maths involved in emulating CRT/NTSC but I hope I will know enough to port 8-X :-)

    Thanks again for your time and patience!

Sign In or Register to comment.