I'm trying to write a leather material shader. I have a normal map, bump map (grayscaled), specular map, diffuse map, cube maps.

I have done the following

#version 100

precision highp int;
precision highp float;

uniform sampler2D diffuseColorMap;
uniform sampler2D ambientOcclusionMap;
uniform sampler2D normalMap;
uniform sampler2D specularMap;
uniform sampler2D bumpMap;
uniform samplerCube envMap;

varying vec2 texCoord[2];
varying vec3 viewWorld;
uniform float reflectionFactor;
uniform float diffuseFactor;
uniform float opacity;
varying vec3 eyeVector;
varying mat3 world2Tangent;
varying vec3 lightVec;
varying vec3 halfVec;
varying vec3 eyeVec;

void main()
    vec3 normal = 2.0 * texture2D (normalMap, texCoord[0]).rgb - 1.0;
    normal = normalize (normal);

    // compute diffuse lighting
    float lamberFactor= max (dot (vec3(0.0,0.0,1.0), normal), 0.1) ;

    vec3 bumpNormal = texture2D(bumpMap, texCoord[0]).rgb;

    vec3 normalWorld = normalize(world2Tangent * bumpNormal);
    vec3 refDir = viewWorld - 2.0 * dot(viewWorld,normalWorld) * normalWorld;

    vec4 diffuseMaterial = texture2D (diffuseColorMap, texCoord[0]);
    vec4 diffuseLight  =  vec4(1.0,1.0,1.0,1.0);

    // In doom3, specular value comes from a texture 
    vec4 specularMaterial =  texture2D (specularMap, texCoord[0])  ;
    vec4 specularLight = vec4(1.0,1.0,1.0,1.0);
    float shininess = pow (max (dot (halfVec, normal), 0.0), 2.0)  ;
    vec4 reflection = textureCube(envMap, refDir);

    gl_FragColor=diffuseMaterial * diffuseLight * lamberFactor ;
    gl_FragColor+=specularMaterial * specularLight * shininess ;    
    gl_FragColor+= reflection*0.3;

The result is shown:

enter image description here

My question is how would I use the bump map (Grayscale) to the result of the reflection or what's wrong in my shader ?

  • \$\begingroup\$ I don't get a real emboss, I tried with normal map with reflection and still doesn't get dark parts around the bumps, that's why I tried with the bump map (grayscaled) \$\endgroup\$ – andre ahmed Feb 12 '18 at 21:24
  • \$\begingroup\$ That sounds more like an occlusion map, or something you could bake into the albedo. But we're going back and forth a bit too much here. Please edit your question to include a visual example of what you consider a 'real emboss" to look like, and identify the differences from what you have currently. This will help focus answers toward solving the specific problem you've identified. \$\endgroup\$ – DMGregory Feb 12 '18 at 21:39

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.