Advertisement Jump to content

Writing a leather shader

Recommended Posts

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 normalTangent = 2.0 * texture2D (normalMap, texCoord[0]).rgb - 1.0;
    vec4 x_forw = texture2D( bumpMap, texCoord[0]+vec2(1.0/2048.0, 0.0));

    vec4 x_back = texture2D( bumpMap, texCoord[0]-vec2(1.0/2048.0, 0.0));

    vec4 y_forw = texture2D( bumpMap, texCoord[0]+vec2(0.0, 1.0/2048.0));

    vec4 y_back = texture2D( bumpMap, texCoord[0]-vec2(0.0, 1.0/2048.0));

    vec3 tangX = vec3(1.0, 0.0, 3.0*(x_forw.x-x_back.x));

    vec3 tangY = vec3(0.0, 1.0, 3.0*(y_forw.x-y_back.x));

    vec3 heightNormal = normalize(cross(tangX, tangY));

    heightNormal = heightNormal*0.5 + 0.5;
     float bumpAngle = max(0.0, dot(vec3(0.0,0.0,1.0),heightNormal ));
    vec3 normalWorld = normalize(world2Tangent *heightNormal);
     vec3 refDir = viewWorld - 2.0 * dot(viewWorld,normalWorld) * normalWorld;
    // compute diffuse lighting

        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,heightNormal), 0.0), 2.0)  ;
        vec4 reflection = textureCube(envMap, refDir);

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


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




2018-02-12 (1).png

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!