You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
void main() {
float brightness = dot(fragNormal,lightDirection);
gl_FragColor = vec4(ambient + diffuse * max(brightness, 0.0),1);
// gl_FragColor = vec4(1,1,1,1);
}`
and i can't pass the test
anyone can give me some tips?
The text was updated successfully, but these errors were encountered:
Okay, so after mucking about with the diffuse problem for a full day, I've figured it out:
The problem is actually that the normals they give you are data normals. You need to convert those to view normals. The tutorial doesn't cover this well, but you need to perform a transform of the normals by the transpose of the inverse of the model transform and the transpose of the inverse of the view transform (in that order), then normalize that vector (in 3D).
I'll leave you to figure out how to actually do that. Hint: If v is a vector and m is a matrix, transpose(m) * v == v * m.
this is the code in vertex.glsl
`precision mediump float;
attribute vec3 position;
attribute vec3 normal;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 inverseModel;
uniform mat4 inverseView;
uniform mat4 inverseProjection;
uniform vec3 ambient;
uniform vec3 diffuse;
uniform vec3 lightDirection;
varying vec3 fragNormal;
void main() {
gl_Position = projectionviewmodel*vec4(position, 1);
fragNormal = normal;
}
this is the code in fragment.glsl
precision mediump float;uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 inverseModel;
uniform mat4 inverseView;
uniform mat4 inverseProjection;
uniform vec3 ambient;
uniform vec3 diffuse;
uniform vec3 lightDirection;
varying vec3 fragNormal;
void main() {
float brightness = dot(fragNormal,lightDirection);
gl_FragColor = vec4(ambient + diffuse * max(brightness, 0.0),1);
// gl_FragColor = vec4(1,1,1,1);
}`
and i can't pass the test
anyone can give me some tips?
The text was updated successfully, but these errors were encountered: