0
\$\begingroup\$

I built a model in blender, and am currently trying to import it into my android app using assimp together with opengl, i dont have any issues with the importing but my goal is to make the object look realistic as possible, and this is where my problem lies...I have implemented normal mapping using both the diffuse and normals of my texture but after rendering it the objects looks smooth and glossy, yes the bumps were rendered well and i like it but i need the material to look more like a fabric (cloth/textile), please how can i do this? do i need to update my lighting equation or the issue is with my original diffuse texture?

Here is my original diffuse texture

enter image description here

Here is my rendered model enter image description here

Here's my fragment shader

    void main()
{
    // obtain normal from normal map in range [0,1]
    vec3 normal = texture2D( normalMap, textureCoords ).xyz;
    // transform normal vector to range [-1,1]
    normal = normalize(normal * 2.0 - 1.0);  // this normal is in tangent space

    // get diffuse color
    vec3 color = texture2D( textureSampler, textureCoords ).xyz;
    // ambient
    vec3 ambient = 0.1 * color;
    // diffuse
    vec3 lightDir = normalize(tangentLightPos - tangentFragPos);
    float diff = max(dot(lightDir, normal), 0.0);
    vec3 diffuse = diff * color;
    // specular
    vec3 viewDir = normalize(tangentViewPos - tangentFragPos);
    vec3 reflectDir = reflect(-lightDir, normal);
    vec3 halfwayDir = normalize(lightDir + viewDir);
    float spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0);
    vec3 specular = vec3(0.2) * spec;

   gl_FragColor  = vec4(ambient + diffuse + specular, 1.0);
}

Here's my vertex shader

mat3 transpose(mat3 m) {
    return mat3(m[0][0], m[1][0], m[2][0],
    m[0][1], m[1][1], m[2][1],
    m[0][2], m[1][2], m[2][2]);
}

void main()
{

    gl_Position     = mvpMat * vec4(vertexPosition, 1.0);

    vec3 fragPos = vec3(model * vec4(vertexPosition,1.0));

    vec3 T = normalize(normalMatrix * tangent);
    vec3 N = normalize(normalMatrix * normal);
    T = normalize(T - dot(T, N) * N);
    vec3 B = cross(N, T);

    mat3 TBN = transpose(mat3(T, B, N));

    //values for fragment shader
    tangentLightPos = TBN * lightPos;
    tangentViewPos  = TBN * viewPos;
    tangentFragPos  = TBN * fragPos;
    textureCoords   = vertexUV;
}
\$\endgroup\$
  • \$\begingroup\$ It might help to show the shader code & lighting equation you're using now, as well as the normal map you're using. \$\endgroup\$ – DMGregory Apr 11 at 11:20
  • \$\begingroup\$ Thanks @DMGregory for your reply, have updated my question \$\endgroup\$ – Distjoy Apr 11 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.