Skip to content

Commit

Permalink
MMDLoader: Apply color management to textures. (#26554)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Aug 9, 2023
1 parent 10275da commit 5c638c4
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions examples/jsm/loaders/MMDLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Skeleton,
SkinnedMesh,
SrcAlphaFactor,
SRGBColorSpace,
TextureLoader,
Uint16BufferAttribute,
Vector3,
Expand Down Expand Up @@ -1133,17 +1134,18 @@ class MaterialBuilder {
* MMDToonMaterial doesn't have ambient. Set it to emissive instead.
* It'll be too bright if material has map texture so using coef 0.2.
*/
params.diffuse = new Color().fromArray( material.diffuse );
params.diffuse = new Color().setRGB(
material.diffuse[ 0 ],
material.diffuse[ 1 ],
material.diffuse[ 2 ],
SRGBColorSpace
);
params.opacity = material.diffuse[ 3 ];
params.specular = new Color().fromArray( material.specular );
params.specular = new Color().setRGB( ...material.specular, SRGBColorSpace );
params.shininess = material.shininess;
params.emissive = new Color().fromArray( material.ambient );
params.emissive = new Color().setRGB( ...material.ambient, SRGBColorSpace );
params.transparent = params.opacity !== 1.0;

params.diffuse.convertSRGBToLinear();
params.specular.convertSRGBToLinear();
params.emissive.convertSRGBToLinear();

//

params.fog = true;
Expand Down Expand Up @@ -1452,6 +1454,7 @@ class MaterialBuilder {
t.flipY = false;
t.wrapS = RepeatWrapping;
t.wrapT = RepeatWrapping;
t.colorSpace = SRGBColorSpace;

for ( let i = 0; i < texture.readyCallbacks.length; i ++ ) {

Expand Down

0 comments on commit 5c638c4

Please sign in to comment.