Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specular map usage incorrect? #76

Open
tristancalderbank opened this issue May 31, 2021 · 2 comments
Open

Specular map usage incorrect? #76

tristancalderbank opened this issue May 31, 2021 · 2 comments

Comments

@tristancalderbank
Copy link

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.

@ssloy
Copy link
Owner

ssloy commented May 31, 2021

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?

@tristancalderbank
Copy link
Author

tristancalderbank commented Jun 1, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants