Opengl shaping issues - strange artifacts of light reflection

I struggled with this for several days. I think I finally narrowed it down to a problem with vertex tangents, but I'm not sure if this is the best way to fix it.

Context is an iPhone app, opengl es2, using my own engine. My shader is a kind of wireframe (normal map) using the enclosed one for the vertex to create the TBN matrix. The vertex shader converts the light vectors and vector vectors into tangent space, passes them to the fragment shader, and calculates the lights. But some kind of geometry in my first two test models shows strange artifacts in the lighting. This is easiest to see in the mirror component.

When trying to debug this, I replaced the regular card with a flat normal png .. all the pixels are 128 128 256. I also strongly encoded the color.

My first model is a button shape. It shows the artifact as a jagged mirror hit on the outer ring. It is important to note that the UV imaging method here was “flat”, so that the sides perpendicular to the imaging basically strip the texture there. I would think that this makes it difficult to calculate the tangents for this geometry, since the two points will have the same texture coordinate.

I tried debug to set gl_FragColor to different variables. When setting it to the vertex normals, we see that the attenuation disappears, which indicates the normality is correct. But by setting it to the vertex tangents, you can see the scallop.

enter image description here

- . . , . , , UV-.

, , ...

Vertex Shader:

v_fragmentTexCoord0 = a_vertexTexCoord0;

gl_Position = u_modelViewProjectionMatrix * vec4(a_vertexPosition,1.0);

vec3 normal = normalize(u_normalMatrix * a_vertexNormal);
vec3 tangent = normalize(u_normalMatrix * a_vertexTangent);
vec3 bitangent = cross(normal, tangent);
mat3 TBNMatrix = mat3(tangent, bitangent, normal);

v_eyeVec =  -a_vertexPosition.xyz;
v_eyeVec *= TBNMatrix;

v_lightVec = u_lightPosition - a_vertexPosition.xyz;
v_lightVec *= TBNMatrix;

v_normal = a_vertexTangent;

:

vec3 norm = texture2D(u_normalSampler, v_fragmentTexCoord0).rgb * 2.0 - 1.0;
vec4 baseColor = vec4(0.6015625,0.0,0.0,1.0); // is normally texture2D(u_textureSampler,v_fragmentTexCoord0);

float dist = length(v_lightVec);
vec3 lightVector = normalize(v_lightVec);
float nxDir = max(0.0, dot(norm, lightVector));
vec4 diffuse = u_lightColorDiffuse * nxDir;
float specularPower = 0.0;
if(nxDir != 0.0)
{
    vec3 cameraVector = v_eyeVec;
    vec3 halfVector = normalize(v_lightVec + cameraVector);
    float nxHalf = max(0.0,dot(norm, halfVector));
    specularPower = pow(nxHalf, u_shininess);
}
vec4 specular = u_lightColorSpecular * specularPower;

gl_FragColor = (diffuse * vec4(baseColor.rgb,1.0)) + specular;

, ... , , 3d-. , - , , ? ? , TBN. 0,0,1 - . , . 1 1. TBN - , , 3d-. - .. , . , , .

TBN-? phong shader .

: , , . UV-, , , . , TBM , .

# 2: , , . 3D-,

, , . , , . , . :

enter image description here

, . . , , , .

- ? ? , ?

+5

All Articles