Friday 15 May 2015

matrix - WebGL shading/lighting too dark on some triangles -


I have a light problem in which some triangle appears to show poor shading artifacts where the shading is not as smooth Is the surface of the entire polygon (a wall, for example). That is, the polygon creates a triangle that looks slightly darker or lighter than it is in the neighborhood.

I'm trying to get a simple directional light here:

What is the top courtesy code:

  gl_Position = uPMatrix * uMVMatrix * vec4 (aVertexPosition.xyz, 1.0) ); VNormal = vec3 (uNMatrix * vec4 (aVertexNormal.xyz, 1.0)); VColor = aVertexMaterialColor;  

And here is the piece shader code:

  vec3 light = normalize (vec3 (0.5, 0.2, 1.0)); Float zodiac = maximum (dot (vnormal, light), 0.0); Vec4 final color = vColor; Finalcolor.rgb * = Amount;  

The problem is that the wall with the windows shows different banding where the individual triangles are darker than others. I can not control the geometry I am receiving, but I believe that the triangle is properly defined, as is normal.

The uPMatrix is ​​the projection matrix, the uMVMatrix model is the visual matrix, and the uNMatrix general matrix is ​​explained here how the normal matrix (gl-matrix) is created:

  var MvMatrix = this.getModelViewMatrix (); Var nMatrix = this.nMatrix; Matte copy 4 (nmatrix, mvmatrix); Mat4.invert (nMatrix, nMatrix); Mat4.transpose (nMatrix, nMatrix);  

Any ideas what I am doing wrong, or how can I easily shade the whole wall?

  gl_Position = uPMatrix * uMVMatrix * vec4 (aVertexPosition.xyz, 1.0); VNormal = vec3 (uNMatrix * vec4 (aVertexNormal.xyz, 1.0)); VColor = aVertexMaterialColor;  
  vec3 light = normal (vec3 (0.5, 0.2, 1.0)); Float zodiac = maximum (dot (vnormal, light), 0.0); Vec4 final color = vColor; Finalcolor.rgb * = Amount;  

To get some variation in color on its surface for a triangle, should have some different input (well, or gl_FragCoord < / Code>, but this is another thing) which is really different. Since your two different vnormal and vColor are dependent on two attributes, one of the following must be true:

  • aVertexMaterialColor < / Code> is not the same for all three corners.
  • aVertexNormal is not the same for all three corners.

Mostly, this is normal; Assume that your geometry comes from a file, you have not properly loaded (normal) normal, or you have not given the modeling tool the correct instructions for making flat-shading normals.

Here is a debugging move:

  finalcolor.rgb = vnormal * 0.5 + vec3 (0.5);  

This will make all your vertices color according to your normal, will refuse content colors and lighting. You will get a unique color, but if you look at any surfaces with shaded colors, then those triangles are normal, which are not all the same.

(Any flat surface should be formed with the same normal triangle; Also, those samples should be straightened in the plane of the triangle.)


No comments:

Post a Comment