tinyrenderer icon indicating copy to clipboard operation
tinyrenderer copied to clipboard

Specular map usage incorrect?

Open tristancalderbank opened this issue 4 years ago • 2 comments

The code that implements the specular map usage in the renderer looks like this currently:

double spec = std::pow(std::max(r.z, 0.), 5+model.specular(uv)); 

Unless I misunderstand it doesn't seem correct to use the pixel values of the specular map as the exponent here because brighter values in the specular texture will result in higher exponents, which means less specularity (because r.z is a value less than 1).

Everything I read online says that brighter spots in the specular map should be more shiny.

For example the similar lesson on LearnOpenGL also doesn't use the specular map values as the exponent.

https://learnopengl.com/Lighting/Lighting-maps

Shader here: https://learnopengl.com/code_viewer_gh.php?code=src/2.lighting/4.3.lighting_maps_exercise2/lighting_maps_exercise2.cpp

Specifically it seems that the shininess exponent is supposed to be constant and instead the specular map is used to control the amount of specular mixed in.

For implementing tinyrenderer I found that I got good results by taking the specular texture value and converting it to a value between [0-1] and using that as the specular coefficient.

tristancalderbank avatar May 31 '21 05:05 tristancalderbank

The whole point to use the exponent is to make the light reflection spot smaller, so the object looks more shiny:

There are different ways to obtain the same effect; it is up to us to choose. Are your renderings more convincing than mine?

ssloy avatar May 31 '21 07:05 ssloy

Here is a comparison where you can see the difference.

Left is original from chapter 6 wiki (using red channel as specular exponent)

Right is mine (using the red channel of the specular map as the kSpecular coefficent value, exponent is constant)

If you compare both with the specular map the right one matches more. The claws/spikes are shiny and the legs are matte.

Whereas the left image the legs are shiny.

image

tristancalderbank avatar Jun 01 '21 04:06 tristancalderbank