galacean / engine

A typescript interactive engine, support 2D, 3D, animation, physics, built on WebGL and glTF.
https://www.galacean.com/engine
MIT License
4.3k stars 308 forks source link

PBR Material interface redesign #195

Open GuoLei1990 opened 3 years ago

GuoLei1990 commented 3 years ago

Actually I want to use occlusionRoughnessMetallicTexture insteadof roughnessMetallicTexture + occlusionTexture in metallic workflow, but consider the current stage glTF compatibility and API consistency, we made some compromises: Metallic workflow: OcclusionTexture + MetallicRoughnessTexture Specular workflow: OcclusionTexture + specularGlossinessTexture

Consider optimization in the future: Metallic workflow: OcclusionRoughnessMetallicTexture Specular workflow: OcclusionTexture + specularGlossinessTexture

API Design(WIP):

/**
 * PBR base material.
 */
export declare abstract class PBRBaseMaterial extends BaseMaterial {
    private _baseColor;
    private _baseTexture;
    private _normalTexture;
    private _emissiveColor;
    private _emissiveTexture;
    private _tilingOffset;
    private _occlusionTexture;
    private _occlusionIntensity;
    private _detailTilingOffset;
    /**
     * Base color.
     */
    get baseColor(): Color;
    set baseColor(value: Color);
    /**
     * Base texture.
     */
    get baseTexture(): Texture2D;
    set baseTexture(value: Texture2D);
    /**
     * Normal texture.
     */
    get normalTexture(): Texture2D;
    set normalTexture(value: Texture2D);
    /**
     * Normal texture intensity.
     */
    get normalTextureIntensity(): number;
    set normalTextureIntensity(value: number);
    /**
     * Emissive color.
     */
    get emissiveColor(): Color;
    set emissiveColor(value: Color);
    /**
     * Emissive texture.
     */
    get emissiveTexture(): Texture2D;
    set emissiveTexture(value: Texture2D);
    /**
     * Occlusion texture.
     */
    get occlusionTexture(): Texture2D;
    set occlusionTexture(v: Texture2D);
    /**
     * Occlusion texture intensity.
     */
    get occlusionTextureIntensity(): number;
    set occlusionTextureIntensity(v: number);
    /**
     * Parallax texture.
     */
    get parallaxTexture(): Texture2D;
    set parallaxTexture(value: Texture2D);
    /**
     * Parallax texture intensity.
     */
    get parallaxTextureIntensity(): number;
    set parallaxTextureIntensity(value: number);
    /**
     * Tiling and offset of main textures.
     */
    get tilingOffset(): Vector4;
    set tilingOffset(value: Vector4);
    /**
     * Detail mask.
     */
    get detailMask(): Texture2D;
    set detailMask(value: Texture2D);
    /**
     * Detail texture.
     */
    get detailTexture(): Texture2D;
    set detailTexture(value: Texture2D);
    /**
     * Detail nromal texture.
     */
    get detailNormalTexture(): Texture2D;
    set detailNormalTexture(value: Texture2D);
    /**
     * Tiling and offset of detail texture.
     */
    get detailTilingOffset(): Vector4;
    set detailTilingOffset(value: Vector4);
    /**
     * Clear coat texture.
     */
    get clearCoatTexture(): Texture2D;
    set clearCoatTexture(value: Texture2D);
    /**
     * Clear coat texture intensity.
     */
    get clearCoatTextureIntensity(): number;
    set clearCoatTextureIntensity(value: number);
    /**
     * Clear coat roughness.
     */
    get clearCoatRoughness(): number;
    set clearCoatRoughness(value: number);
    /**
     * Clear coat roughness texture.
     */
    get clearCoatRoughnessTexture(): Texture2D;
    set clearCoatRoughnessTexture(value: Texture2D);
    /**
     * Clear coat normal texture.
     */
    get clearCoatNormalTexture(): Texture2D;
    set clearCoatNormalTexture(value: Texture2D);
    /**
     * Clear coat normal texture intensity.
     */
    get clearCoatNormalTextureIntensity(): Texture2D;
    set clearCoatNormalTextureIntensity(value: Texture2D);
}
/**
 * PBR metallic-roughness workflow material.
 */
export declare class PBRMaterial extends PBRBaseMaterialX {
    private _metallic;
    private _roughness;
    private _roughnessMetallicTexture;
    /**
     * Metallic.
     */
    get metallic(): number;
    set metallic(value: number);
    /**
     * Roughness.
     */
    get roughness(): number;
    set roughness(value: number);
    /**
     * Roughness metallic texture.
     * @remarks G channel is roughness, B channel is metallic
     */
    get roughnessMetallicTexture(): Texture2D;
    set roughnessMetallicTexture(v: Texture2D);
}
/**
 * PBR specular-glossiness workflow material.
 */
export declare class PBRSpecularMaterial extends PBRBaseMaterialX {
    private _specularColor;
    private _specularGlossinessTexture;
    private _glossiness;
    /**
     * Specular color.
     */
    get specularColor(): Color;
    set specularColor(value: Color);
    /**
     * Glossiness.
     */
    get glossiness(): number;
    set glossiness(value: number);
    /**
     * Specular glossiness texture.
     * @remarks RGB is specular, A is glossiness
     */
    get specularGlossinessTexture(): Texture2D;
    set specularGlossinessTexture(value: Texture2D);
}

Design: @GuoLei1990 , @zhuxudong

PR: @zhuxudong

PR reviewers: @yangfengzzz , @gz65555 , @GuoLei1990

zhuxudong commented 3 years ago