Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Question about rendering quality

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2017
    Posts
    12

    Question Question about rendering quality

    Hello Everyone,

    I am trying to render a wall in OpenGL using (diffuse, normal and specular) maps and here is the results:
    Click image for larger version. 

Name:	2018-01-25_025553.jpg 
Views:	111 
Size:	39.6 KB 
ID:	2631

    with this shader:
    fragment shader:
    Code :
    uniform sampler2D diffuseMap1;
    uniform sampler2D normalMap1;
    uniform sampler2D specularMap1;
    uniform sampler2D shadowMap;
     
    in VS_OUT1 {
    	vec3 TangentFragPos;
    	vec3 TangentViewPos;
    	mat3 TBN;
    } fs_in1;
     
    in VS_OUT2 {
    	vec3 Normal;
    	vec3 FragPos;
    	vec2 TexCoords;
    	vec3 ViewPos;
    	vec4 FragPosLightSpace;
    } fs_in2;
     
    struct Material {
    	vec3 ambi;
    	vec3 diff;
    	vec3 spec;
    };
     
    struct DirLight {
    	vec3 dir;
    	Material mat;
    };
    uniform DirLight dL;
     
    float ShadowCalculation(sampler2D shadowMap, vec4 fragPosLightSpace)
    { ....... }
     
    vec3 CalcDirLight(DirLight light, mat3 TBN, vec3 viewDir, vec3 color, vec3 normal, vec3 specular, float shadowAmount);
     
    void main()
    {
    	vec3 color = texture(diffuseMap1, fs_in2.TexCoords).rgb;
    	vec3 normal = texture(normalMap1, fs_in2.TexCoords).rgb * 2.0 - 1.0;
    	vec3 specular = texture(specularMap1, fs_in2.TexCoords).rgb;
     
    	float shadow = ShadowCalculation(shadowMap, fs_in2.FragPosLightSpace);
    	vec3 tangentViewDir = normalize(fs_in1.TangentViewPos - fs_in1.TangentFragPos);
    	vec3 resultFromDirLight = CalcDirLight(dL, fs_in1.TBN, tangentViewDir, color, normal, specular, shadow, normals);
     
    	vec3 result = resultFromDirLight;
    	FragColor = vec4(result, 1.0);
    }
     
    vec3 CalcDirLight(DirLight light, mat3 TBN, vec3 viewDir, vec3 color, vec3 normal, vec3 specular, float shadowAmount)
    {
    	vec3 lightDir = TBN * light.dir;
    	float diff = max(dot(normal, lightDir), 0.0);
     
    	vec3 halfwayDir = normalize(lightDir + viewDir);
    	vec3 specularAmount = vec3(pow(max(dot(viewDir, halfwayDir), 0.0), 64.0));
     
    	vec3 ambient = light.mat.ambi * color;
    	vec3 diffuse = light.mat.diff * diff * color;
    	specularAmount *= light.mat.spec * specular;
     
    	return (ambient + shadowAmount * (diffuse + specularAmount));
    }

    And also tried to render the same wall in Blender with the same 3 textures, and here is the results:
    Click image for larger version. 

Name:	render.jpg 
Views:	113 
Size:	93.1 KB 
ID:	2632
    You notice the big difference, how can I achieve this amazing quality of rendering? any help please.
    DiffuseMap:Click image for larger version. 

Name:	wall-diff.jpg 
Views:	109 
Size:	97.9 KB 
ID:	2633
    NormalMap:Click image for larger version. 

Name:	wall-norm.jpg 
Views:	105 
Size:	91.5 KB 
ID:	2634
    SpecularMap:Click image for larger version. 

Name:	wall-spec.jpg 
Views:	107 
Size:	97.0 KB 
ID:	2635
    BlenderFile:https://drive.google.com/open?id=1Ey...EYJ-bgIxBkTvkm

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,570
    Your surface looks very matte, like there's no specular. I'd start with positioning a point light source so its light bounces directly into the eye to give you that specular highlight and go from there. Then assess what the specular component of your lighting calcs.

    Also, I see that your specular contains dot( V, H ). More commonly you see dot( N, H ) here instead.

    See how far that gets you. At some point, you'll probably want to explore doing gamma-correct lighting (e.g. sRGB textures and such).
    Last edited by Dark Photon; 01-24-2018 at 07:25 PM.

  3. #3
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    459
    I would also do like Dark Photon proposed. But for this I would also remove the TBN and replace it with face normals (so disable normal mapping).
    Also locate the light at the same position than in Blender, and with the same parameters.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2017
    Posts
    12
    Thank you all, that really helped me.

    @Silence, what I wanted to do is to add specular maps with normal maps, so there is no point in disabling the normal mapping.

    and here is the resultsClick image for larger version. 

Name:	Capture.JPG 
Views:	35 
Size:	69.8 KB 
ID:	2636

  5. #5
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    459
    Quote Originally Posted by Omar Bsoul View Post
    Thank you all, that really helped me.

    @Silence, what I wanted to do is to add specular maps with normal maps, so there is no point in disabling the normal mapping.

    and here is the resultsClick image for larger version. 

Name:	Capture.JPG 
Views:	35 
Size:	69.8 KB 
ID:	2636
    There was, in order to quickly check if something was wrong with the normal mapping.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •