Hot answers tagged

6

When a matrix is orthogonal, inverse and transpose are equivalent making an inverse transpose equal to the original matrix. So if your model view matrix is orthogonal, the normal matrix will be equal to it. As user41442 pointed out, in most cases modelview matrices are actually orthogonal so this can be a bit of a short hand. There's still cases where it's ...


4

Unexpectedly black pixels sometimes indicate that you've got an infinity or NaN in the shader somewhere. For example normalize(vec3(0,0,0)) will generate a NaN. To me, the most obvious candidate in the above shader is the reflectDirection variable, but I could be wrong. GLSL has isinf() and isnan() functions that you can use to detect those cases. If that ...


2

According to GL spec: void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); *location* Specifies the location of the uniform value to be modified. *count* Specifies the number of matrices that are to be modified. This should be 1 if the ...


1

A guess (too long to put in a comment): If spotFactor becomes 0.6 at a specific pixel, from this float spotFactor = dot(lightDirection, spotLight.direction); then color goes negative here (as you said spotLight.cutoff is 0.71): color = calcPointLight(spotLight.pointLight, normal) * (1.0 - (1.0 - spotFactor)/(1.0-spotLight.cutoff)); will ...


1

There is at least one serious problem in the code. In calcLight(), the test below is invalid. Calling pow with a negative first argument is undefined behaviour, so you need to test specularFactor sooner. float specularFactor = dot(directionToEye, reflectDirection); specularFactor = pow(specularFactor, specularPower); if(specularFactor > 0) ...


1

I didn't see any call to SwapBuffers after your draw commands. That's definitely a problem that will cause a blank screen. As long as there are no OpenGL errors, it's the only problem.


1

I am also looking for some code to make this conversion but..Only God knows why the code above is using that array indexes lol... Maybe he meant something like this? (in case other people wants to use the code too) PVector [] tUV = new PVector[3]; // 2d uv coordinates of the triangle vertices PVector [] t3D = new PVector[3]; // 3d space ...



Only top voted, non community-wiki answers of a minimum length are eligible