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

About Light Sources #16

Open
mono0218 opened this issue Jan 10, 2024 · 4 comments
Open

About Light Sources #16

mono0218 opened this issue Jan 10, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@mono0218
Copy link

I imported a PMX MMD stage and the colors look a little pale.
I tried changing the light code to look like the official page, but it didn't cure it.
On this page the colors appear as normal. Is there something wrong with the light code?

@mono0218
Copy link
Author

mono0218 commented Jan 10, 2024

image
image

Codes already tried

const hemisphericLight = new HemisphericLight("HemisphericLight", new Vector3(0, 1, 0), scene);
        hemisphericLight.intensity = 1;
        hemisphericLight.specular.set(0, 0, 0);
        hemisphericLight.groundColor.set(1, 1, 1);

const directionalLight = new DirectionalLight("DirectionalLight", new Vector3(0.5, -1, 1), scene);
        directionalLight.intensity = 1;
        directionalLight.shadowMaxZ = 20;
        directionalLight.shadowMinZ = -15;
const directionalLight = new DirectionalLight("DirectionalLight", new Vector3(0, 75, -130), scene);
        directionalLight.direction = new Vector3(100,-75,-260)
        directionalLight.intensity = 10000;
        directionalLight.autoCalcShadowZBounds = false
        directionalLight.autoUpdateExtends = false
        directionalLight.shadowMaxZ = 1000
        directionalLight.shadowMinZ = -1000
        directionalLight.orthoTop = 1000
        directionalLight.orthoBottom = -1000
        directionalLight.orthoLeft = -1000
        directionalLight.orthoRight= -1000
        directionalLight.shadowOrthoScale = 1000

        const shadowGenerator = new ShadowGenerator(2048, directionalLight, true,);
        shadowGenerator.usePercentageCloserFiltering = true
        shadowGenerator.filteringQuality = ShadowGenerator.QUALITY_HIGH
        shadowGenerator.forceBackFacesOnly = false
        shadowGenerator.frustumEdgeFalloff = 0.1
        shadowGenerator.bias = 0.01;

I would appreciate any advice you could give me.

@noname0310
Copy link
Owner

noname0310 commented Jan 10, 2024

This appears to happen when the diffuse color of the model's material is not (1, 1, 1).

Some MMD models use the approach of setting the diffuse color to (0.5, 0.5, 0.5) and the ambient color to (1, 1, 1) to create a material that looks bright in the dark.

However, if we simply import the deffuse and ambient parameters into the StandardMaterial in babylon.js, we will get different lighting results due to the different way ambient color works in babylon.js.

In simple terms, this is due to the different behavior of babylon.js and MMD materials,
and can be resolved by applying either of the two codes below.

option1:

const pmxLoader = SceneLoader.GetPluginForExtension(".pmx") as PmxLoader; // If you're using a bpmx loader, modify this
const pmxMaterialBuilder = pmxLoader.materialBuilder as MmdStandardMaterialBuilder;
pmxMaterialBuilder.afterBuildSingleMaterial = (material): void => {
    material.diffuseColor.add(material.ambientColor);
    material.ambientColor.set(0, 0, 0);
};

option2:

scene.ambientColor = new Color3(1, 1, 1);

The second option is theoretically similar to MMD, although the first option usually yields better results

If you have any other questions, feel free to open an issue and I'll get back to you shortly.

@noname0310
Copy link
Owner

If you're using post-processing, tone mapping may be the cause

defaultPipeline.imageProcessing.toneMappingEnabled = false;

@noname0310 noname0310 self-assigned this Jan 10, 2024
@noname0310 noname0310 added the question Further information is requested label Jan 10, 2024
@noname0310
Copy link
Owner

In 0.41.0, the renderer code was refactored across the board, and you should now see exactly the same results as MMD.

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

No branches or pull requests

2 participants