User avatar
PeterO
Posts: 4234
Joined: Sun Jul 22, 2012 4:14 pm

Convert #version 330 shaders for PI

Fri Jun 01, 2018 4:59 pm

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
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
Paeryn
Posts: 2103
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Convert #version 330 shaders for PI

Fri Jun 01, 2018 7:33 pm

Briefly looking at it those changes should be enough. Though that first one should be "attribute vec3 i_position"
She who travels light — forgot something.

User avatar
PeterO
Posts: 4234
Joined: Sun Jul 22, 2012 4:14 pm

Re: Convert #version 330 shaders for PI

Fri Jun 01, 2018 8:00 pm

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
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
Paeryn
Posts: 2103
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Convert #version 330 shaders for PI

Fri Jun 01, 2018 9:14 pm

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.
She who travels light — forgot something.

User avatar
PeterO
Posts: 4234
Joined: Sun Jul 22, 2012 4:14 pm

Re: Convert #version 330 shaders for PI

Fri Jun 01, 2018 9:44 pm

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
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “OpenGLES”

Who is online

Users browsing this forum: No registered users and 3 guests