Login  Register

Re: JOGL Shader Questions

Posted by Xerxes Rånby on Mar 26, 2013; 10:11am
URL: https://forum.jogamp.org/JOGL-Shader-Questions-tp4028783p4028826.html

2013-03-25 20:37, bgroenks96 [via jogamp] skrev:
>
>     gouessej wrote
>     I advise you to read a basic course about shaders as you seem not to understand which variables are in input and in output in a shader of a particular type (vertex, pixel, geometry, ...).
>
> I've been reading about shaders, but I'm more confused about JOGL and GLSL specifically.
>
> If you have any particular article or shader-tutorial you would like me to read before continuing my inquiries, please post it, and I will be happy to do so.

Shaders are passed in clear text Strings to your GPU driver. The GPU driver compiles the shader for use by the processing units on your device.
The syntax for shaders differs slightly depending on which OpenGL version you target:

=================
Most of the JogAmp examples uses mobile and desktop compatible GLSL syntax and are using the GL2ES2 profile that is supported on both OpenGL 2 and ES 2 hardware.

OpenGL 2 up to OpenGL version 3.3. shaders can use Vertex, Geometry and Fragment shaders but work only the desktop.
http://www.khronos.org/files/opengl-quick-reference-card.pdf - quick reference card that covers GLSL for Vertex, Geometry and Fragment shaders.

OpenGL ES 2 shaders can only use Vertex and Fragment shaders and work only on mobile.
http://www.khronos.org/opengles/2_X/
I recommend you to print out the OpenGL ES 2 Quick Reference Card that also contains a summary of OpenGL ES Shading Language 1.0:
http://www.khronos.org/opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf
If you need more detailed documentation for GLSL read the specification:
http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf

OpenGL 2 and ES 2 shaders uses similar keywords inside the GLSL language thus it is possible to write Vertex and Fragment shaders in a way that work on both desktop and mobile by using the GLSL GPU compilers preprocessor to hide keywords that are specific to mobile OpenGL ES 2.
The quick way to make a Vertex or Fragment shader OpenGL 2 and ES 2 compatible is by placingthe following 4 lines at the top of the Vertex and Fragment shader:

#ifdef GL_ES
precision mediump float; // Precision Qualifiers
precision mediump int; // GLSL ES section 4.5.2
#endif

the precision qualifiers are mandatory to be specified in mobile OpenGL ES 2 GLSL spec but do not exist in desktop OpenGL 2 GLSL spec.

I have written a simple introduction to OpenGL 2 and ES 2 compatible Vertex and Fragment Shaders here:
http://labb.zafena.se/?p=547
Source: https://github.com/xranby/jogl-demos/blob/master/src/demos/es2/RawGL2ES2demo.java#L44


=================

Below I will list the latest OpenGL specifications and how they differs from the above OpenGL 2 and ES 2:

OpenGL 4.3 (desktop) adds support for three new kind of shaders:
Tessellation Control Language
Tessellation Evaluation Language
Compute Language
http://www.khronos.org/files/opengl43-quick-reference-card.pdf
You also notice that some of the shader keywords have changed from the OpenGL 2 to OpenGL 4.3
The "variant" keyword is now renamed to "out" inside the vertex shader
The "variant" keyword is now renamed to "in" inside the fragment shader

OpenGL ES 3 (mobile)
GLSL version 1.1
http://www.khronos.org/files/opengles3-quick-reference-card.pdf
specificaton: http://www.khronos.org/registry/gles/specs/3.0/GLSL_ES_Specification_3.00.4.pdf
Similar to OpenGL 4.3, ES 3 GLSL also use the new "in" and "out" keywords.
ES 3 have removed all of the restrictions found inside the ES 2 Appendix A specification, these changes require new mobile hardware and drivers that have started to ship in 2013.

It looks like there will be possible to create a new desktop and mobile profile possibly called GL43ES3 that may be both OpenGL 4.3 and ES 3 compatible that can be used by the latest OpenGL hardware on both mobile and desktop.

=================

Online tutorials for OpenGL 2 up to OpenGL version 3.3:

http://dev-fjord.blogspot.se/2011/07/jogl-part-1-introduction.html
http://dev-fjord.blogspot.se/2011/08/jogl-part-2-deferred-renderer.html - this tutorial gives a good outline on how to use Deferred Rendering for multi pass advanced Lighting rendering.
this tutorial focus on how to to manage the user defined Geometry Buffer (G-Buffer).
http://en.wikipedia.org/wiki/Deferred_shading

http://www.arcsynthesis.org/gltut/ - Learning Modern 3D Graphics Programming with focus on OpenGL version 3.3.

Cheers
Xerxes