1 |
- {"ast":null,"code":"import { Logger } from \"../Misc/logger.js\";\nimport { Color3 } from \"../Maths/math.color.js\";\nimport { SubSurfaceScatteringPostProcess } from \"../PostProcesses/subSurfaceScatteringPostProcess.js\";\nimport { SceneComponentConstants } from \"../sceneComponent.js\";\nimport { _WarnImport } from \"../Misc/devTools.js\";\n\n/**\n * Contains all parameters needed for the prepass to perform\n * screen space subsurface scattering\n */\nexport class SubSurfaceConfiguration {\n /**\n * Diffusion profile color for subsurface scattering\n */\n get ssDiffusionS() {\n return this._ssDiffusionS;\n }\n /**\n * Diffusion profile max color channel value for subsurface scattering\n */\n get ssDiffusionD() {\n return this._ssDiffusionD;\n }\n /**\n * Diffusion profile filter radius for subsurface scattering\n */\n get ssFilterRadii() {\n return this._ssFilterRadii;\n }\n /**\n * Builds a subsurface configuration object\n * @param scene The scene\n */\n constructor(scene) {\n this._ssDiffusionS = [];\n this._ssFilterRadii = [];\n this._ssDiffusionD = [];\n /**\n * Is subsurface enabled\n */\n this.enabled = false;\n /**\n * Does the output of this prepass need to go through imageprocessing\n */\n this.needsImageProcessing = true;\n /**\n * Name of the configuration\n */\n this.name = SceneComponentConstants.NAME_SUBSURFACE;\n /**\n * Diffusion profile colors for subsurface scattering\n * You can add one diffusion color using `addDiffusionProfile` on `scene.prePassRenderer`\n * See ...\n * Note that you can only store up to 5 of them\n */\n this.ssDiffusionProfileColors = [];\n /**\n * Defines the ratio real world => scene units.\n * Used for subsurface scattering\n */\n this.metersPerUnit = 1;\n /**\n * Textures that should be present in the MRT for this effect to work\n */\n this.texturesRequired = [5, 7, 4, 0];\n // Adding default diffusion profile\n this.addDiffusionProfile(new Color3(1, 1, 1));\n this._scene = scene;\n SubSurfaceConfiguration._SceneComponentInitialization(this._scene);\n }\n /**\n * Adds a new diffusion profile.\n * Useful for more realistic subsurface scattering on diverse materials.\n * @param color The color of the diffusion profile. Should be the average color of the material.\n * @returns The index of the diffusion profile for the material subsurface configuration\n */\n addDiffusionProfile(color) {\n if (this.ssDiffusionD.length >= 5) {\n // We only suppport 5 diffusion profiles\n Logger.Error(\"You already reached the maximum number of diffusion profiles.\");\n return 0; // default profile\n }\n // Do not add doubles\n for (let i = 0; i < this._ssDiffusionS.length / 3; i++) {\n if (this._ssDiffusionS[i * 3] === color.r && this._ssDiffusionS[i * 3 + 1] === color.g && this._ssDiffusionS[i * 3 + 2] === color.b) {\n return i;\n }\n }\n this._ssDiffusionS.push(color.r, color.b, color.g);\n this._ssDiffusionD.push(Math.max(Math.max(color.r, color.b), color.g));\n this._ssFilterRadii.push(this.getDiffusionProfileParameters(color));\n this.ssDiffusionProfileColors.push(color);\n return this._ssDiffusionD.length - 1;\n }\n /**\n * Creates the sss post process\n * @returns The created post process\n */\n createPostProcess() {\n this.postProcess = new SubSurfaceScatteringPostProcess(\"subSurfaceScattering\", this._scene, 1, null, undefined, this._scene.getEngine());\n this.postProcess.autoClear = false;\n return this.postProcess;\n }\n /**\n * Deletes all diffusion profiles.\n * Note that in order to render subsurface scattering, you should have at least 1 diffusion profile.\n */\n clearAllDiffusionProfiles() {\n this._ssDiffusionD = [];\n this._ssDiffusionS = [];\n this._ssFilterRadii = [];\n this.ssDiffusionProfileColors = [];\n }\n /**\n * Disposes this object\n */\n dispose() {\n this.clearAllDiffusionProfiles();\n if (this.postProcess) {\n this.postProcess.dispose();\n }\n }\n /**\n * @internal\n * https://zero-radiance.github.io/post/sampling-diffusion/\n *\n * Importance sample the normalized diffuse reflectance profile for the computed value of 's'.\n * ------------------------------------------------------------------------------------\n * R[r, phi, s] = s * (Exp[-r * s] + Exp[-r * s / 3]) / (8 * Pi * r)\n * PDF[r, phi, s] = r * R[r, phi, s]\n * CDF[r, s] = 1 - 1/4 * Exp[-r * s] - 3/4 * Exp[-r * s / 3]\n * ------------------------------------------------------------------------------------\n * We importance sample the color channel with the widest scattering distance.\n */\n getDiffusionProfileParameters(color) {\n const cdf = 0.997;\n const maxScatteringDistance = Math.max(color.r, color.g, color.b);\n return this._sampleBurleyDiffusionProfile(cdf, maxScatteringDistance);\n }\n /**\n * Performs sampling of a Normalized Burley diffusion profile in polar coordinates.\n * 'u' is the random number (the value of the CDF): [0, 1).\n * rcp(s) = 1 / ShapeParam = ScatteringDistance.\n * Returns the sampled radial distance, s.t. (u = 0 -> r = 0) and (u = 1 -> r = Inf).\n * @param u\n * @param rcpS\n * @returns The sampled radial distance\n */\n _sampleBurleyDiffusionProfile(u, rcpS) {\n u = 1 - u; // Convert CDF to CCDF\n const g = 1 + 4 * u * (2 * u + Math.sqrt(1 + 4 * u * u));\n const n = Math.pow(g, -1.0 / 3.0); // g^(-1/3)\n const p = g * n * n; // g^(+1/3)\n const c = 1 + p + n; // 1 + g^(+1/3) + g^(-1/3)\n const x = 3 * Math.log(c / (4 * u));\n return x * rcpS;\n }\n}\n/**\n * @internal\n */\nSubSurfaceConfiguration._SceneComponentInitialization = _ => {\n throw _WarnImport(\"SubSurfaceSceneComponent\");\n};","map":{"version":3,"names":["Logger","Color3","SubSurfaceScatteringPostProcess","SceneComponentConstants","_WarnImport","SubSurfaceConfiguration","ssDiffusionS","_ssDiffusionS","ssDiffusionD","_ssDiffusionD","ssFilterRadii","_ssFilterRadii","constructor","scene","enabled","needsImageProcessing","name","NAME_SUBSURFACE","ssDiffusionProfileColors","metersPerUnit","texturesRequired","addDiffusionProfile","_scene","_SceneComponentInitialization","color","length","Error","i","r","g","b","push","Math","max","getDiffusionProfileParameters","createPostProcess","postProcess","undefined","getEngine","autoClear","clearAllDiffusionProfiles","dispose","cdf","maxScatteringDistance","_sampleBurleyDiffusionProfile","u","rcpS","sqrt","n","pow","p","c","x","log","_"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Rendering/subSurfaceConfiguration.js"],"sourcesContent":["import { Logger } from \"../Misc/logger.js\";\nimport { Color3 } from \"../Maths/math.color.js\";\nimport { SubSurfaceScatteringPostProcess } from \"../PostProcesses/subSurfaceScatteringPostProcess.js\";\nimport { SceneComponentConstants } from \"../sceneComponent.js\";\nimport { _WarnImport } from \"../Misc/devTools.js\";\n\n/**\n * Contains all parameters needed for the prepass to perform\n * screen space subsurface scattering\n */\nexport class SubSurfaceConfiguration {\n /**\n * Diffusion profile color for subsurface scattering\n */\n get ssDiffusionS() {\n return this._ssDiffusionS;\n }\n /**\n * Diffusion profile max color channel value for subsurface scattering\n */\n get ssDiffusionD() {\n return this._ssDiffusionD;\n }\n /**\n * Diffusion profile filter radius for subsurface scattering\n */\n get ssFilterRadii() {\n return this._ssFilterRadii;\n }\n /**\n * Builds a subsurface configuration object\n * @param scene The scene\n */\n constructor(scene) {\n this._ssDiffusionS = [];\n this._ssFilterRadii = [];\n this._ssDiffusionD = [];\n /**\n * Is subsurface enabled\n */\n this.enabled = false;\n /**\n * Does the output of this prepass need to go through imageprocessing\n */\n this.needsImageProcessing = true;\n /**\n * Name of the configuration\n */\n this.name = SceneComponentConstants.NAME_SUBSURFACE;\n /**\n * Diffusion profile colors for subsurface scattering\n * You can add one diffusion color using `addDiffusionProfile` on `scene.prePassRenderer`\n * See ...\n * Note that you can only store up to 5 of them\n */\n this.ssDiffusionProfileColors = [];\n /**\n * Defines the ratio real world => scene units.\n * Used for subsurface scattering\n */\n this.metersPerUnit = 1;\n /**\n * Textures that should be present in the MRT for this effect to work\n */\n this.texturesRequired = [\n 5,\n 7,\n 4,\n 0,\n ];\n // Adding default diffusion profile\n this.addDiffusionProfile(new Color3(1, 1, 1));\n this._scene = scene;\n SubSurfaceConfiguration._SceneComponentInitialization(this._scene);\n }\n /**\n * Adds a new diffusion profile.\n * Useful for more realistic subsurface scattering on diverse materials.\n * @param color The color of the diffusion profile. Should be the average color of the material.\n * @returns The index of the diffusion profile for the material subsurface configuration\n */\n addDiffusionProfile(color) {\n if (this.ssDiffusionD.length >= 5) {\n // We only suppport 5 diffusion profiles\n Logger.Error(\"You already reached the maximum number of diffusion profiles.\");\n return 0; // default profile\n }\n // Do not add doubles\n for (let i = 0; i < this._ssDiffusionS.length / 3; i++) {\n if (this._ssDiffusionS[i * 3] === color.r && this._ssDiffusionS[i * 3 + 1] === color.g && this._ssDiffusionS[i * 3 + 2] === color.b) {\n return i;\n }\n }\n this._ssDiffusionS.push(color.r, color.b, color.g);\n this._ssDiffusionD.push(Math.max(Math.max(color.r, color.b), color.g));\n this._ssFilterRadii.push(this.getDiffusionProfileParameters(color));\n this.ssDiffusionProfileColors.push(color);\n return this._ssDiffusionD.length - 1;\n }\n /**\n * Creates the sss post process\n * @returns The created post process\n */\n createPostProcess() {\n this.postProcess = new SubSurfaceScatteringPostProcess(\"subSurfaceScattering\", this._scene, 1, null, undefined, this._scene.getEngine());\n this.postProcess.autoClear = false;\n return this.postProcess;\n }\n /**\n * Deletes all diffusion profiles.\n * Note that in order to render subsurface scattering, you should have at least 1 diffusion profile.\n */\n clearAllDiffusionProfiles() {\n this._ssDiffusionD = [];\n this._ssDiffusionS = [];\n this._ssFilterRadii = [];\n this.ssDiffusionProfileColors = [];\n }\n /**\n * Disposes this object\n */\n dispose() {\n this.clearAllDiffusionProfiles();\n if (this.postProcess) {\n this.postProcess.dispose();\n }\n }\n /**\n * @internal\n * https://zero-radiance.github.io/post/sampling-diffusion/\n *\n * Importance sample the normalized diffuse reflectance profile for the computed value of 's'.\n * ------------------------------------------------------------------------------------\n * R[r, phi, s] = s * (Exp[-r * s] + Exp[-r * s / 3]) / (8 * Pi * r)\n * PDF[r, phi, s] = r * R[r, phi, s]\n * CDF[r, s] = 1 - 1/4 * Exp[-r * s] - 3/4 * Exp[-r * s / 3]\n * ------------------------------------------------------------------------------------\n * We importance sample the color channel with the widest scattering distance.\n */\n getDiffusionProfileParameters(color) {\n const cdf = 0.997;\n const maxScatteringDistance = Math.max(color.r, color.g, color.b);\n return this._sampleBurleyDiffusionProfile(cdf, maxScatteringDistance);\n }\n /**\n * Performs sampling of a Normalized Burley diffusion profile in polar coordinates.\n * 'u' is the random number (the value of the CDF): [0, 1).\n * rcp(s) = 1 / ShapeParam = ScatteringDistance.\n * Returns the sampled radial distance, s.t. (u = 0 -> r = 0) and (u = 1 -> r = Inf).\n * @param u\n * @param rcpS\n * @returns The sampled radial distance\n */\n _sampleBurleyDiffusionProfile(u, rcpS) {\n u = 1 - u; // Convert CDF to CCDF\n const g = 1 + 4 * u * (2 * u + Math.sqrt(1 + 4 * u * u));\n const n = Math.pow(g, -1.0 / 3.0); // g^(-1/3)\n const p = g * n * n; // g^(+1/3)\n const c = 1 + p + n; // 1 + g^(+1/3) + g^(-1/3)\n const x = 3 * Math.log(c / (4 * u));\n return x * rcpS;\n }\n}\n/**\n * @internal\n */\nSubSurfaceConfiguration._SceneComponentInitialization = (_) => {\n throw _WarnImport(\"SubSurfaceSceneComponent\");\n};\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,+BAA+B,QAAQ,qDAAqD;AACrG,SAASC,uBAAuB,QAAQ,sBAAsB;AAC9D,SAASC,WAAW,QAAQ,qBAAqB;;AAEjD;AACA;AACA;AACA;AACA,OAAO,MAAMC,uBAAuB,CAAC;EACjC;AACJ;AACA;EACI,IAAIC,YAAYA,CAAA,EAAG;IACf,OAAO,IAAI,CAACC,aAAa;EAC7B;EACA;AACJ;AACA;EACI,IAAIC,YAAYA,CAAA,EAAG;IACf,OAAO,IAAI,CAACC,aAAa;EAC7B;EACA;AACJ;AACA;EACI,IAAIC,aAAaA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACC,cAAc;EAC9B;EACA;AACJ;AACA;AACA;EACIC,WAAWA,CAACC,KAAK,EAAE;IACf,IAAI,CAACN,aAAa,GAAG,EAAE;IACvB,IAAI,CAACI,cAAc,GAAG,EAAE;IACxB,IAAI,CAACF,aAAa,GAAG,EAAE;IACvB;AACR;AACA;IACQ,IAAI,CAACK,OAAO,GAAG,KAAK;IACpB;AACR;AACA;IACQ,IAAI,CAACC,oBAAoB,GAAG,IAAI;IAChC;AACR;AACA;IACQ,IAAI,CAACC,IAAI,G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