Vec4 specularMapPixel = texture2D(spec_tex, f_texcoord).rgba Vec3 ambientLight = vec3(ambientScene)*vec3(mat.Ka) Vec3 lightDirection = tangenteSpace*(vertToLightSource/distance) įloat clampedCosine = max(0.0, dot(-lightDirection, normalize(light.spotDirection))) įloat tempMix = mix(attenuation * pow(clampedCosine, light.spotExponent),0.0,clampedCosine < cos(light.spotCutoff * 3.14159 / 180.0)) //if outside of spotlight nothingĪttenuation = mix(attenuation,tempMix,light.spotCutoff <= 90.0) Īttenuation = mix(attenuation,1.0,) Light.quadraticAttenuation*distance*distance),) Vec3 vertToLightSource = vec3(light.position - position*) įloat distance = length(vertToLightSource) Īttenuation = mix(1.0,1.0/(nstantAttenuation + Vec3 viewDirection = tangenteSpace*normalize(vec3(invView * vec4(0.0, 0.0, 0.0, 1.0) - position)) vec3 normalDirection = normalize(mat3(invTransp)*vertNormal) Vec3 normalDirection = normalize(tangenteSpace*(texture2D( bump_tex, f_texcoord ).rgb*2.0 - 1.0)) This is the diffuse texture and the bump map : There is probably something I didn't understand correctly, I just hope you will be able to help me :)Īnyway this is the result I get (from a free asset used just for testing - the results are fine in blender) :
#Opengl 4.3 textures and lighting code#
I based my code on what I learned with the OpenGL 4.3 Redbook and "Mathematics for 3D game programming and computer graphics" book. I have diffuse, specular and ambient light/texture working fine and now I am implementing the bump mapping.
I am learning OpenGL (and learning the math behind it) and I'm making a simple OBJ viewer, nothing fancy.