mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.81k stars 35.38k forks source link

Blender Exporter mistakingly making objects shiny #6283

Closed windwarrior closed 9 years ago

windwarrior commented 9 years ago

When exporting files from blender the result in three.js is way more specular then what you see in blender. I believe that is because the materials that get exported are MeshPhongMaterials, where the materials look more like MeshLambertMaterials. Another possiblility is that the lights in three are brighter than in blender.

Attached are (in this order) an render from blender, and a render from three, I also included the blendfiles and a test html file.

Image in blender

three

Here is the test code as well as the blender file: https://gist.github.com/windwarrior/3ba349f36d74d560de90

repsac commented 9 years ago

Yeah that's too bright. If I change the shininess to match Blender's specular intensity of 0.5 it looks like this

screen shot 2015-03-23 at 8 57 49 am

mrdoob commented 9 years ago

FYI @bhouston @WestLangley

repsac commented 9 years ago

Think I will update the exporter to pull this value from shininess. The highlight won't exactly match but the spec shouldn't be blown out like it is now.

windwarrior commented 9 years ago

If I understand correctly there is a difference in the 3 properties blender has (specular color, specular intensity and hardness) and the 2 properties three supports (specular color and shininess).

Are you proposing to put the specular intensity value from blender in the shininess value for three? I think that might be a mistake because I believe shininess in three maps to hardness in blender [1][2]

[1] http://wiki.blender.org/index.php/Doc:2.6/Manual/Materials/Properties/Specular_Shaders [2] http://threejs.org/docs/#Reference/Materials/MeshPhongMaterial (moving the shininess slider here)

(Genuinely interested here!)

repsac commented 9 years ago

Well if shininess is meant to map to hardness then the exporter is doing it correctly because it is pulling from the specular_hardness property in Blender.

This sounds like taking the scene into the Editor and dragging values (shininess, lights, etc) up and down until it (hopefully) looks correct. Then taking the modified values and comparing them to the original values and applying multipliers to the values during the export process.

windwarrior commented 9 years ago

After some experimentation I believe the exporter is doing the right thing, but not on the right scale.

Blender knows three properties to define a shiney material

  1. Its color
  2. Its specular intensity
  3. Its hardness (affects size of the specular highlight)

The exporter maps these to two properties three supports

  1. Its color
  2. Its shininess

As I previously mentioned (and now confirmed), shininess is indeed where the exporter puts hardness. (Which was useless to confirm since you already did that)

What was previously unknown to me is where the specular intesity of blender went, I was afraid it was dismissed altogether. It is not however, given a specular color of 0xffffff (being white), it is multiplied per color by the specular intesity of blender, so multiplying by a specular intensity of 0.5 yields 0x7f7f7f. This works.

Okay, that is the recap for myself because you already know this probably. Now to contribute to this ticket I created another reference scene which has nine apes, on the x axis I varied the specular intensity (from 0.01 to 0.5 to 0.99), and on the (blender) y axis I varied hardness (from 50 to 100 to 150). As you can see, on the Y axis the sizes of the specular highlights do decrease in both blender and three. So also shininess works as intended

Indeed I think we should proceed by tweaking the values so that they match blenders, I could not find a bug in the way the exporter maps the values blender provides to what three supports.

Here are the two pictures of the scene, blender first, three second.

apes_blender

apes_three

And a link to the relevant files: https://gist.github.com/windwarrior/ed793868dd6f7b81ea1c

Hope this helps! (And if it doesn't, please please say so! Its for me also a process of learning, and in that process I like typing stuff out.. :p).

WestLangley commented 9 years ago

A little googling resulted in this: http://blenderartists.org/forum/archive/index.php/t-325185.html

If it is correct, try any formula close to

shininess = 1000 * ( Material.specular_hardness - 1 ) / 510   ( but not less than 1 )

and

specular = Material.specular_color * Material.specular_intensity  (componentwise)

In the second formula, be careful not to produce values out of range, as intensity can be greater than 1.

windwarrior commented 9 years ago

The second formula is already applied, and produces sane values. (Half specular intensity of white yields 07f7f7f) (see my previous post). To confirm that this is happening, in the scene with the nine apes, the second ape on the first row has a specular intensity of 0.5 in blender. Three exports this to "specular": 8355711, which is indeed exactly 0x7f7f7f.

Adapting the hardness does change the specular highlight (obviously), but doesn't fix the problem of the highlights being too bright.

For completeness sake, here is the screenshot of the "fixed" hardness. As you can see, not much has changed in the oversaturated lights. Now I am also confused as of why this is happening, and cannot pinpoint where the bug is exactly...

hardness_adapted

WestLangley commented 9 years ago

We will have to hold on this. There is an issue as to weather your colors are in linear space or sRGB space. three.js is currently under development in properly handling that.

A reasonable value for material.specular in three.js for non-metals is 0x050505 - 0x090909 in linear space. Your values are way too big. material.shininess can range from 1 to 1000 or more.

windwarrior commented 9 years ago

Okay :), thanks for the effort! Will see development unfold eventually!

windwarrior commented 9 years ago

Just for my information, was this problem resolved or unprioritized? I cannot seem to find a fix for this issue.

Please don't read this as a demand for explanation, but more a question out of curiosity :)!

I tested it against the development version of THREE (and the exporter), and saw no chance in behaviour.

mrdoob commented 9 years ago

Just closed it for lack of activity. I'm sure we'll bump into this again soon 😁