PDA

View Full Version : GLES shader won't compile on iphone



mlfarrell
02-09-2010, 02:00 PM
This makes no sense. My shader won't build on the iphone, citing a link error that is wrong. See below:



**Link failure!!**
Log contents:
ERROR: No 'main()' function found in linked vertex shaders.
ERROR: No 'main()' function found in linked fragment shaders.

Shaders attached: 4

--Fragment shader--
precision mediump float;

vec4 ShadeFragment();

void main()
{
gl_FragColor = ShadeFragment();
}

--Vertex shader--
//precision mediump float;

vec4 ShadeVertex();

void main()
{
gl_Position = ShadeVertex();
}


--Vertex shader--
//#version 120
//#extension GL_EXT_gpu_shader4 : enable

precision mediump float;

uniform mat4 ModelViewMatrix;
uniform mat4 ModelViewProjMatrix;
uniform mat4 NormalMatrix;
uniform vec4 Color;

attribute vec4 Vertex;
attribute vec4 Normal;

varying vec4 out_color;

/************************************************** *****
* Fixed.vert Fixed Function Equivalent Vertex Shader *
* Automatically Generated by 3Dlabs GLSL ShaderGen *
* http://developer.3dlabs.com *
************************************************** *****/
vec4 Ambient;
vec4 Diffuse;
vec4 Specular;


void pointLight(in int i, in vec3 normal, in vec3 eye, in vec3 ecPosition3)
{
float nDotVP; // normal . light direction
float nDotHV; // normal . light half vector
float pf; // power factor
float attenuation; // computed attenuation factor
float d; // distance from surface to light source
vec3 VP; // direction from surface to light position
vec3 halfVector; // direction of maximum highlights

// Compute vector from surface to light position
VP = vec3 (0,0,1) - ecPosition3;

// Compute distance between surface and light position
d = length(VP);

// Normalize the vector from surface to light position
VP = normalize(VP);

// Compute attenuation
attenuation = 1.0;

halfVector = normalize(VP + eye);

nDotVP = max(0.0, dot(normal, VP));
nDotHV = max(0.0, dot(normal, halfVector));

if (nDotVP == 0.0)
{
pf = 0.0;
}
else
{
pf = pow(nDotHV, 100.0);
}
Ambient += vec4(0);
Diffuse += vec4(1,1,1,1) * nDotVP;
Specular += vec4(1,1,1,1) * pf;
}

vec3 fnormal(void)
{
//Compute the normal
vec3 normal = (NormalMatrix * Normal).xyz;
normal = normalize(normal);
return normal;
}

void flight(in vec3 normal, in vec4 ecPosition, float alphaFade)
{
vec4 color;
vec3 ecPosition3;
vec3 eye;

ecPosition3 = (vec3 (ecPosition)) / ecPosition.w;
eye = vec3 (0.0, 0.0, 1.0);

// Clear the light intensity accumulators
Ambient = vec4 (0.0);
Diffuse = vec4 (0.0);
Specular = vec4 (0.0);

pointLight(0, normal, eye, ecPosition3);

color = Ambient*vec4(0.2, 0.2, 0.2, 1.0) +
Diffuse*Color;
color += Specular;
color = clamp( color, 0.0, 1.0 );
out_color = color;

out_color.a *= alphaFade;
}


vec4 ShadeVertex()
{
vec3 transformedNormal;
float alphaFade = 1.0;

// Eye-coordinate position of vertex, needed in various calculations
vec4 ecPosition = ModelViewMatrix * Vertex;

// Do fixed functionality vertex transform
transformedNormal = fnormal();
flight(transformedNormal, ecPosition, alphaFade);
return ModelViewProjMatrix * Vertex;
}


--Fragment shader--
//#version 120
//#extension GL_EXT_gpu_shader4 : enable

precision mediump float;
varying vec4 out_color;

/************************************************** *****
* Fixed.frag Fixed Function Equivalent Fragment Shader *
* Automatically Generated by 3Dlabs GLSL ShaderGen *
* http://developer.3dlabs.com *
************************************************** *****/

vec4 ShadeFragment()
{
return out_color;
}


Did apple screw up the OpenGLES 2.0 implementation on the iphone simulator?

mlfarrell
02-09-2010, 02:43 PM
apparently opengl es cannot link multiple shaders, so I had to merge the source files.

wow, so many limitations on gles

Xmas
02-10-2010, 02:55 AM
Since you can pass multiple strings to glShaderSource, that should be quite easy to handle.

By the way, I'd recommend using highp precision for vertex position calculations. While mediump is sufficient for most other uses (and out_color could be lowp), vertex transformations often cause problems with anything less than highp.