PDA

View Full Version : Question about rendering quality



Omar Bsoul
01-24-2018, 05:35 PM
Hello Everyone,

I am trying to render a wall in OpenGL using (diffuse, normal and specular) maps and here is the results:
2631

with this shader:
fragment shader:


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:
2632
You notice the big difference, how can I achieve this amazing quality of rendering? any help please.
DiffuseMap:2633
NormalMap:2634
SpecularMap:2635
BlenderFile:https://drive.google.com/open?id=1Ey1RK1Mt9vw-tsh9kpEYJ-bgIxBkTvkm

Dark Photon
01-24-2018, 06:16 PM
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).

Silence
01-24-2018, 11:13 PM
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.

Omar Bsoul
01-25-2018, 02:35 AM
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 results2636

Silence
01-25-2018, 05:04 AM
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 results2636

There was, in order to quickly check if something was wrong with the normal mapping.