- Also properly set to version 110 and changed normal and cube map matrices to be 3x3
-precision highp float;
+// precision highp float;
#if LIGHTING_ON
#if PER_VERTEX_COLOR
#if ENVIRONMENT_MAPPING
uniform samplerCube envTex;
- uniform mat4 cubemap_matrix;
+ uniform mat3 cubemap_matrix;
#if ENVIRONMENT_REFLECTION
uniform float matReflectivity;
computeLight(bool(LIGHT3_POSITIONAL) ? lights[3] : lightsPos[3], n, lEye, ambient, diffuse, specular,
bool(LIGHT3_POSITIONAL), bool(LIGHT3_SPOT), bool(LIGHT3_ATT),
bool(LIGHT3_SPOT) ? lightsSpotDir[3] : vec3(0), bool(LIGHT3_SPOT) ? lightsSpotCutOffCos[3] : 0.0, bool(LIGHT3_SPOT) ? lightsSpotExp[3] : 0.0,
- bool(LIGHT3_ATT) ? lightsAtt[3] : vec(1,0,0),
+ bool(LIGHT3_ATT) ? lightsAtt[3] : vec3(1,0,0),
lightsAmbient[3], lightsDiffuse[3], lightsSpecular[3]);
#endif
#if NUM_LIGHTS > 4 && LIGHT4_ON
computeLight(bool(LIGHT6_POSITIONAL) ? lights[6] : lightsPos[6], n, lEye, ambient, diffuse, specular,
bool(LIGHT6_POSITIONAL), bool(LIGHT6_SPOT), bool(LIGHT6_ATT),
bool(LIGHT6_SPOT) ? lightsSpotDir[6] : vec3(0), bool(LIGHT6_SPOT) ? lightsSpotCutOffCos[6] : 0.0, bool(LIGHT6_SPOT) ? lightsSpotExp[6] : 0.0,
- lightsAmbient[6], lightsDiffuse[6], lightsSpecular[6],
- bool(LIGHT6_ATT) ? lightsAtt[6] : vec3(1,0,0));
+ bool(LIGHT6_ATT) ? lightsAtt[6] : vec3(1,0,0),
+ lightsAmbient[6], lightsDiffuse[6], lightsSpecular[6]);
#endif
#if NUM_LIGHTS > 7 && LIGHT7_ON
computeLight(bool(LIGHT7_POSITIONAL) ? lights[7] : lightsPos[7], n, lEye, ambient, diffuse, specular,
bool(LIGHT7_POSITIONAL), bool(LIGHT7_SPOT), bool(LIGHT7_ATT),
bool(LIGHT7_SPOT) ? lightsSpotDir[7] : vec3(0), bool(LIGHT7_SPOT) ? lightsSpotCutOffCos[7] : 0.0, bool(LIGHT7_SPOT) ? lightsSpotExp[7] : 0.0,
- lightsAmbient[7], lightsDiffuse[7], lightsSpecular[7],
- bool(LIGHT7_ATT) ? lightsAtt[7] : vec3(1,0,0));
+ bool(LIGHT7_ATT) ? lightsAtt[7] : vec3(1,0,0),
+ lightsAmbient[7], lightsDiffuse[7], lightsSpecular[7]);
#endif
#if MAT_SPECULAR && SPECULAR_MAPPING
{
float opacity = c.w;
v = refract(eyeToSurface, n, matRefractionETA);
- c = vec4(opacity * c + (1.0 - opacity) * textureCube(envTex, vec3(cubemap_matrix * vec4(v, 1.0))));
+ c = vec4(opacity * c + (1.0 - opacity) * textureCube(envTex, vec3(cubemap_matrix * v)));
}
#endif
reflectivity *= texture2D(reflectTex, texCoord).r;
#endif
v = reflect(eyeToSurface, n);
- c = (1.0 - reflectivity) * c + reflectivity * textureCube(envTex, vec3(cubemap_matrix * vec4(v, 1.0)));
+ c = (1.0 - reflectivity) * c + reflectivity * textureCube(envTex, vec3(cubemap_matrix * v));
}
#endif
#endif
attribute vec3 tangent2;
uniform float nearPlane;
- uniform mat4 normals_matrix;
+ uniform mat3 normals_matrix;
#if PER_VERTEX_COLOR
varying vec4 diffuseColor; // w: opacity
ambientColor = color.xyz;
#endif
- tNormal = mat3(normals_matrix) * normal;
+ tNormal = normals_matrix * normal;
#if NORMALS_MAPPING
- tTangent1 = mat3(normals_matrix) * tangent1;
- tTangent2 = mat3(normals_matrix) * tangent2;
+ tTangent1 = normals_matrix * tangent1;
+ tTangent2 = normals_matrix * tangent2;
#endif
#elif PER_VERTEX_COLOR
fColor = matDiffuse * color;
float modelView[16];
float projection[16];
float matTexture[16];
- float cubemap_matrix[16];
+ float cubemap_matrix[9];
- float normalsMatrix[16];
+ float normalsMatrix[9];
float nearPlane;
float globalAmbient[3];
int i;
#ifdef _DEBUG
- PrintLn("Compiling shader for state: ", state);
+ //PrintLn("Compiling shader for state: ", state);
#endif
+#if defined(__EMSCRIPTEN__)
defs.concatf("#version 100\n");
+#else
+ defs.concatf("#version 110\n");
+#endif
defs.concatf("\n#define NUM_LIGHTS %d", 8);
defs.concatf("\n#define MODELVIEW %d", state.modelView ? 1 : 0);
defs.concatf("\n#define PER_VERTEX_COLOR %d", state.perVertexColor ? 1 : 0);
defs.concatf("\n\n#line 0\n");
#ifdef _DEBUG
- printf((String)defs._string);
+ //puts((String)defs._string);
#endif
return defs;
}
glUniform1f(shader.uNearPlane, nearPlane);
glUniform3fv(shader.uGlobalAmbient, 1, globalAmbient);
- glUniformMatrix4fv(shader.uNormalsMatrix, 1, GL_FALSE, normalsMatrix);
+ glUniformMatrix3fv(shader.uNormalsMatrix, 1, GL_FALSE, normalsMatrix);
if(state.normalsMapping)
glUniform1i(shader.uBumpTex, 1);
if(state.environmentMapping)
{
glUniform1i(shader.uEnvTex, 3);
- glUniformMatrix4fv(shader.uCubeMapMatrix, 1, GL_FALSE, cubemap_matrix);
+ glUniformMatrix3fv(shader.uCubeMapMatrix, 1, GL_FALSE, cubemap_matrix);
if(state.reflection)
glUniform1f(shader.uMatReflectivity, reflectivity);
if(state.refraction)
void setCamera(Camera camera)
{
double * c = camera.inverseTranspose.array;
- float m[16] =
+ float m[9] =
{
- (float) c[0], (float) c[1], (float)-c[2], 0,
- (float)-c[4], (float) c[5], (float) c[6], 0,
- (float)-c[8], (float) c[9], (float) c[10], 0,
- 0, 0, 0, 1
+ (float) c[0], (float) c[1], (float)-c[2],
+ (float)-c[4], (float) c[5], (float) c[6],
+ (float)-c[8], (float) c[9], (float) c[10]
};
- memcpy(cubemap_matrix, m, 16 * sizeof(float));
+ memcpy(cubemap_matrix, m, 9 * sizeof(float));
uniformsModified = true;
}
t.Transpose(inv);
inv.Inverse(t);
{
- float m[16] =
+ float m[9] =
{
- (float)i[0],(float)i[1],(float)i[2],(float)i[3],
- (float)i[4],(float)i[5],(float)i[6],(float)i[7],
- (float)i[8],(float)i[9],(float)i[10],(float)i[11],
- (float)i[12],(float)i[13],(float)i[14],(float)i[15]
+ (float)i[0],(float)i[1],(float)i[2],
+ (float)i[4],(float)i[5],(float)i[6],
+ (float)i[8],(float)i[9],(float)i[10]
};
- memcpy(normalsMatrix, m, 16 * sizeof(float));
+ memcpy(normalsMatrix, m, 9 * sizeof(float));
}
uniformsModified = true;