Skip to content

Conversation

MiiBond
Copy link
Contributor

@MiiBond MiiBond commented Jun 19, 2025

No description provided.

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 19, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 19, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 19, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 19, 2025

@deltakosh deltakosh requested review from Popov72 and sebavan June 20, 2025 15:33
@bjsplat
Copy link
Collaborator

bjsplat commented Jun 20, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@MiiBond
Copy link
Contributor Author

MiiBond commented Jun 20, 2025

I've been playing with mixins to try to remove a lot of duplicate code from the materials. I figured, if we can do this, it'll make my life easier when working on PBR2. I started with using mixins for some defines like UV1, UV2, etc. and the image-processing defines. Then, I tried actually making the imageProcessing logic into a mixin. This removes a whole bunch of duplicated stuff.
See packages\dev\core\src\Materials\imageProcessing.ts
What do we think about this approach? It seems to work with typing but decorators don't work with anonymous class definitions so I had to apply them manually in the constructor.
If we're okay with this, I was thinking about trying to separate out some of the lighting logic (light map, reflection map, irradiance map, SH, etc.).
Ideally, it would be nice to have a bit more of a separation between the lighting and the material model.

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 20, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

1 similar comment
@bjsplat
Copy link
Collaborator

bjsplat commented Jun 23, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

import type { ColorCurves } from "./colorCurves";

// Explicit re-export of types to help TypeScript resolve them in declaration files
export type { Observer } from "../Misc/observable";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting errors in the npm run build:es6 involving ../.. import paths in this mixin.
An AI tool came up with the solution of adding these explicit exports. I don't really understand it but it works. It should be checked by someone who understands issues like this.

@deltakosh deltakosh changed the title Added PBR2 material and option to load using glTF Added OpenPBR material and option to load using glTF Jun 24, 2025
@bjsplat
Copy link
Collaborator

bjsplat commented Jun 24, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@MiiBond
Copy link
Contributor Author

MiiBond commented Jun 24, 2025

I've noticed another issue with my changes that I don't understand. When running a Playground in Typescript mode, I get an error about not being able to find the BABYLON namespace. Any ideas what I might have done to cause that?

@MiiBond MiiBond force-pushed the mbond/pbr2-test-wip branch from fe87eca to 3a5b609 Compare June 25, 2025 20:37
@bjsplat
Copy link
Collaborator

bjsplat commented Jun 25, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

1 similar comment
@bjsplat
Copy link
Collaborator

bjsplat commented Jun 26, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 26, 2025

Building or testing the sandbox has failed.

If the tests failed, results can be found here:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/SANDBOX/refs/pull/16773/merge/testResults/

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 26, 2025

Building or testing the playground has failed.

If the tests failed, results can be found here:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/PLAYGROUND/refs/pull/16773/merge/testResults/

@Popov72
Copy link
Contributor

Popov72 commented Jul 1, 2025

Just so I understand correctly, for now, you have simply copied and pasted the existing PBR vertex/fragment shaders to create the OpenPBR shaders?

I don't know if you have discussed the rewrite with @sebavan, but in my opinion, we should start from scratch without any defines and implement what is necessary for OpenPBR in the cleanest way possible. We can then configure the code with a few defines when necessary (but we should end up with far fewer definitions than we have now).

@MiiBond
Copy link
Contributor Author

MiiBond commented Jul 7, 2025

in my opinion, we should start from scratch without any defines and implement what is necessary for OpenPBR

This is actually what I started doing but I quickly realized that there is a ton of stuff that we still want to support like SH (in VS and FS), pre-filtered IBL, realtime IBL, analytic lights, etc. Also morph targets, skinning, etc. I'm still planning on removing ALL of the current material properties copied from PBRMaterial while retaining the logic for lighting, animation, etc. Ideally, we'll be able to separate lighting from material properties as much as possible in the shader...

@MiiBond MiiBond force-pushed the mbond/pbr2-test-wip branch from df6a640 to e908eee Compare July 10, 2025 01:33
@bjsplat
Copy link
Collaborator

bjsplat commented Jul 10, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jul 10, 2025

Building or testing the sandbox has failed.

If the tests failed, results can be found here:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/SANDBOX/refs/pull/16773/merge/testResults/

@bjsplat
Copy link
Collaborator

bjsplat commented Jul 10, 2025

Building or testing the playground has failed.

If the tests failed, results can be found here:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/PLAYGROUND/refs/pull/16773/merge/testResults/

@bjsplat
Copy link
Collaborator

bjsplat commented Jul 10, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jul 10, 2025

Building or testing the sandbox has failed.

If the tests failed, results can be found here:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/SANDBOX/refs/pull/16773/merge/testResults/

@bjsplat
Copy link
Collaborator

bjsplat commented Jul 10, 2025

Building or testing the playground has failed.

If the tests failed, results can be found here:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/PLAYGROUND/refs/pull/16773/merge/testResults/

@bjsplat
Copy link
Collaborator

bjsplat commented Jul 10, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@MiiBond MiiBond force-pushed the mbond/pbr2-test-wip branch from 350cb2f to 294a1e5 Compare August 27, 2025 16:12
@bjsplat
Copy link
Collaborator

bjsplat commented Aug 27, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Aug 27, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Aug 27, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Aug 27, 2025

Copy link
Member

@sebavan sebavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks all good to me, @Popov72 can you have a look at the PR ?

Copy link
Contributor

@alexchuber alexchuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glTF exporter LGTM!

const geometryTangentTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryTangentTexture);

// TODO - if _useSpecularRoughnessAnisotropyFromTangentTexture isn't true, the anisotropy strength is in a separate
// texture and needs to be merged into the blue channel of the aniosotropy texture for glTF. Is there a good way of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, we don't yet have a clean, abstract way of composing channels from different textures into a new texture. If you were to do it right here and now, you'd have to do it all manually: read the original pixels, compose a new pixel array, decide on things like mimeType and sampling information, then finally export the glTF sampler, image, and texture info.

If you have some ideas in mind, feel free to implement them! But also don't hesitate to leave a TODO or note-- I'd be happy to fill this in (and other similar cases, like the metal/rough textures in _convertMetalRoughFactorsToMetallicRoughnessAsync) later.

Copy link
Contributor

@bghgary bghgary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some high-level comments for now. I will be discussing with Seb on how to not branch so much in the loader.

* @returns A promise that resolves when the load is complete or null if not handled
*/
loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
Copy link
Contributor

@bghgary bghgary Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary. The loader extensions already have access to the main loader and the parent loader, so they already have access to this flag.

@@ -91,6 +92,8 @@ const LazyLoaderAnimationModulePromise = new Lazy(() => import("./glTFLoaderAnim

export { GLTFFileLoader };

let PBRMaterialClass: typeof PBRMaterial | typeof OpenPBRMaterial;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work correctly as a global. Since the determination of what class to use is per loader, this variable should be stored in the loader class itself, or it may get overridden when two assets are loaded simultaneously. Extensions can also access this property to avoid duplicating the logic.

}
mat.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
mat.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
babylonMaterial = mat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unnecessary.

Comment on lines +2206 to +2207
(babylonMaterial as OpenPBRMaterial)._useRoughnessFromMetallicTextureGreen = true;
(babylonMaterial as OpenPBRMaterial)._useMetallicFromMetallicTextureBlue = true;
Copy link
Contributor

@bghgary bghgary Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The glTF loader tries to make sure all shader variants are accounted for in the first synchronous pass. I'm guessing these flags will cause the shader to be different. If so, these should be moved to below, like with the PBRMaterial flags. Same goes for any flags that may affect the shader. We need to make sure they are set synchronously and not in a promise continuation.

@bghgary
Copy link
Contributor

bghgary commented Aug 28, 2025

@MiiBond Here is my idea for avoiding so much branching in the loader.

If we can add a class like this:

class OpenPBRMaterialAdapter {
    private _oldMaterial: PBRMaterial

    public constructor(oldMaterial: PBRMaterial) {
        this._oldMaterial = oldMaterial;
    }

    public set baseMetalness(value) { this._oldMaterial.metallic = value; }
}

Then, we can use this adapter when openPbr is not being used but still have the code be like it's using the open pbr one. Let me know if this doesn't make sense.

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

Successfully merging this pull request may close these issues.

7 participants