Page 1 of 1

Convert #version 330 shaders for PI

Posted: Fri Jun 01, 2018 4:59 pm
by PeterO
I've just come across these useful shaders for Phong shading
http://www.sunandblackcat.com/tipFullVi ... topicid=30

But they are for version 330and use a few features unavailable in the GLSL version on the PI.

Is anyone familiar with back porting shaders ?

I think I can just replace
"layout(location = 0) in vec3 i_position;" with "attrib vec3 i_position"
"out vec3 o_normal;" with "varying vec3 o_normal"

"in vec3 o_normal;" with "varying vec3 o_normal"
"layout(location = 0) uniform sampler2D u_diffuseTexture;" with "uniform sampler2D u_diffuseTexture;"
"out vec4 resultingColor;" with gl_fragColor

and they should work....

PeterO

Re: Convert #version 330 shaders for PI

Posted: Fri Jun 01, 2018 7:33 pm
by Paeryn
Briefly looking at it those changes should be enough. Though that first one should be "attribute vec3 i_position"

Re: Convert #version 330 shaders for PI

Posted: Fri Jun 01, 2018 8:00 pm
by PeterO
Yes, attrib needed to be attribute.

But there were several other problems with that code. As it stood it couldn't ever have compiled ! Note the variable names are different between the declarations and the use (missing "s" when used). Also a few integers "0" and "1" needed to be "0.0" and "1.0".

Code: Select all

// parameters of the material and possible values
uniform vec3 u_matAmbientReflectances; // = vec3(1, 1, 1);
uniform vec3 u_matDiffuseReflectances; // = vec3(1, 1, 1);
uniform vec3 u_matSpecularReflectances; // = vec3(1, 1, 1);
uniform float u_matShininess; // = 64;

/////////////////////////////////////////////////////////

// returns intensity of reflected ambient lighting
vec3 ambientLighting()
{
   return u_matAmbientReflectance * u_lightAmbientIntensity;
}
Now I'm working on parsing the materials ".mtl" file to get extract the colours values and texture file names.

PeterO

Re: Convert #version 330 shaders for PI

Posted: Fri Jun 01, 2018 9:14 pm
by Paeryn
Didn't spot the extra letters in the names (I assumed they would have got that right).

You're right on the literals for ES2's glsl, though I think automatic promotion from integer to float is allowed in newer glsl.

Re: Convert #version 330 shaders for PI

Posted: Fri Jun 01, 2018 9:44 pm
by PeterO
Paeryn wrote:
Fri Jun 01, 2018 9:14 pm
Didn't spot the extra letters in the names (I assumed they would have got that right).
Yes, it took me a while to see because searching for the variables (as used) found the definitions....
You're right on the literals for ES2's glsl, though I think automatic promotion from integer to float is allowed in newer glsl.
Yes, I'm building the code on a x86_64 platform as well as on the PI, and those changes were only needed on the PI. I think the PC has a version 3 of openGL ES. I've got the shaders to compile and link on both platforms but I've not tried using them yet.

PeterO