[Solved] OpenB3D GLSL shader input and uniforms

BlitzMax Forums/MiniB3D Module/[Solved] OpenB3D GLSL shader input and uniforms

RustyKristi(Posted 2016) [#1]
Hi, I think I'm going to take a crack at learning some basic shader stuff so what I would like to know if the uniforms are the same as standard GLSL stuff or it is slightly different like the underscores and first letter caps.

Is this the correct guide for the latest OpenB3D version? http://mew.cx/glsl_quickref.pdf

what I would like to know are common variables like lightdirection, lightcolor, screensize, etc. The normal and depth buffer I sort of got it with the examples given but I need confirmation if that's all in there.

thanks.


markcw(Posted 2016) [#2]
That quickref guide is the right version for the shaders in the wrapper, I made my shaders conform to GLSL 1.10 which is GL 2.0 (which is on a lot of older Macbooks) so it will work in GL 2.1 as well. I don't put a version number in but just now I read this is better practice as it tells the GPU what to do. I haven't tested on GL 3.x but I'm sure the shaders will need updated to work. I'll need to get a new laptop to do that.

The main differences between 110 and 120 is you can't set global variables to a value you have to do that outside, and arrays aren't supported but I found a workaround for that in bumpmap3.frag with the struct FloatArray.

Currently attribute variables are not supported by Openb3d, the SetParameter functions are there but commented, I don't know why they're not added. You can use the built in attributes to do most things like gl_Normal so you're not stuck, attributes are per vertex and only set in the vertex shader.

if the uniforms are the same as standard GLSL stuff or it is slightly different

I'm not really following you there but uniforms are variables you call them what you want and set them outside the shader, variables can start with an _ but not a number.

Most common variables are built in like gl_LightSource[n].position gives you position but not direction, color is in the same struct with names ambient/diffuse/specular, screen size is passed as a uniform - you need to calculate most things yourself with shaders.

I have a list of links which I'll post. The orange book is the GL 2.0 shaders book, the red book is GL 1.1 and blue book is GL 2.0.

GLSL tutorials and demos
https://www.opengl.org/sdk/docs/tutorials/
http://www.lighthouse3d.com/tutorials/
http://www.clockworkcoders.com/oglsl/tutorials.html
http://www.real3dtutorials.com/index.php
http://www.ozone3d.net/tutorials/glsl_texturing.php
http://encelo.netsons.org/programming/opengl/
http://www.eng.utah.edu/~cs5600/slides/GLSL-ATI-Intro.pdf

OpenGL docs
http://wiki.labomedia.org/images/1/10/Orange_Book_-_OpenGL_Shading_Language_2nd_Edition.pdf
http://www.glprogramming.com/red/
http://www.glprogramming.com/blue/
https://www.opengl.org/sdk/docs/man2/
http://www.shaderific.com/glsl-functions/


RustyKristi(Posted 2016) [#3]
Thank you for the links and details munch! very informative. Let's say I need to get a directional light position from bmx code to shader input, do I use this?

gl_LightSource[0].position


markcw(Posted 2016) [#4]
For light direction there's a good example in bumpmap2.frag, for directional light it is
lightDirection = normalize(vec3(gl_LightSource[i].position));

and point/spot light is
vec3 positionToLightSource = vec3(gl_LightSource[i].position - position);
lightDirection = normalize(positionToLightSource);

where position is a varying vec4 (varyings are for sharing data between vert and frag) defined in the vert as (which is vertex world position)
position = gl_ModelViewMatrix * gl_Vertex;



RustyKristi(Posted 2016) [#5]
Thanks got it now! :D