@onerjs/addons 8.32.0 → 8.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/atmosphere/Shaders/ShadersInclude/atmosphereFunctions.js +18 -3
- package/atmosphere/Shaders/ShadersInclude/atmosphereFunctions.js.map +1 -1
- package/atmosphere/Shaders/aerialPerspective.fragment.js +3 -2
- package/atmosphere/Shaders/aerialPerspective.fragment.js.map +1 -1
- package/atmosphere/Shaders/compositeAerialPerspective.fragment.js +2 -1
- package/atmosphere/Shaders/compositeAerialPerspective.fragment.js.map +1 -1
- package/atmosphere/Shaders/compositeGlobeAtmosphere.fragment.js +9 -6
- package/atmosphere/Shaders/compositeGlobeAtmosphere.fragment.js.map +1 -1
- package/atmosphere/Shaders/compositeSky.fragment.js +9 -6
- package/atmosphere/Shaders/compositeSky.fragment.js.map +1 -1
- package/atmosphere/Shaders/diffuseSkyIrradiance.fragment.js +3 -4
- package/atmosphere/Shaders/diffuseSkyIrradiance.fragment.js.map +1 -1
- package/atmosphere/Shaders/multiScattering.fragment.js +4 -3
- package/atmosphere/Shaders/multiScattering.fragment.js.map +1 -1
- package/atmosphere/Shaders/skyView.fragment.js +3 -2
- package/atmosphere/Shaders/skyView.fragment.js.map +1 -1
- package/atmosphere/Shaders/transmittance.fragment.js +2 -1
- package/atmosphere/Shaders/transmittance.fragment.js.map +1 -1
- package/atmosphere/atmosphere.js +3 -3
- package/atmosphere/atmosphere.js.map +1 -1
- package/atmosphere/atmosphereOptions.js +1 -1
- package/atmosphere/atmosphereOptions.js.map +1 -1
- package/atmosphere/atmospherePBRMaterialPlugin.d.ts +2 -0
- package/atmosphere/atmospherePBRMaterialPlugin.js +9 -1
- package/atmosphere/atmospherePBRMaterialPlugin.js.map +1 -1
- package/atmosphere/atmospherePerCameraVariables.js +1 -1
- package/atmosphere/atmospherePerCameraVariables.js.map +1 -1
- package/atmosphere/atmospherePhysicalProperties.js +1 -1
- package/atmosphere/atmospherePhysicalProperties.js.map +1 -1
- package/atmosphere/atmospherePhysicalPropertiesOptions.js +1 -1
- package/atmosphere/atmospherePhysicalPropertiesOptions.js.map +1 -1
- package/atmosphere/diffuseSkyIrradianceLut.js +7 -5
- package/atmosphere/diffuseSkyIrradianceLut.js.map +1 -1
- package/atmosphere/index.js +1 -1
- package/atmosphere/index.js.map +1 -1
- package/atmosphere/sampling.js +1 -1
- package/atmosphere/sampling.js.map +1 -1
- package/atmosphere/transmittanceLut.js +5 -4
- package/atmosphere/transmittanceLut.js.map +1 -1
- package/package.json +2 -2
- package/atmosphere/test/unit/sampling.test.d.ts +0 -1
- package/atmosphere/test/unit/sampling.test.js +0 -77
- package/atmosphere/test/unit/sampling.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sampling.js","sourceRoot":"","sources":["../../../../dev/addons/src/atmosphere/sampling.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"sampling.js","sourceRoot":"","sources":["../../../../dev/addons/src/atmosphere/sampling.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,KAAK,EAAE,oDAAyC;AAGzD,MAAM,kBAAkB,GAAG,GAAgB,EAAE;IACzC,OAAO;QACH,CAAC,EAAE,MAAM,CAAC,GAAG;QACb,CAAC,EAAE,MAAM,CAAC,GAAG;QACb,CAAC,EAAE,MAAM,CAAC,GAAG;QACb,CAAC,EAAE,MAAM,CAAC,GAAG;KAChB,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;AACvC,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;AACvC,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;AACvC,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAC7B,CAAS,EACT,CAAS,EACT,OAAe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Copyright (c) Microsoft Corporation.\r\n// Licensed under the MIT License.\r\n\r\nimport { Clamp } from \"core/Maths/math.scalar.functions\";\r\nimport type { IColor4Like } from \"core/Maths/math.like\";\r\n\r\nconst MakeTempColor4Like = (): IColor4Like => {\r\n return {\r\n r: Number.NaN,\r\n g: Number.NaN,\r\n b: Number.NaN,\r\n a: Number.NaN,\r\n };\r\n};\r\n\r\nconst TmpColor1 = MakeTempColor4Like();\r\nconst TmpColor2 = MakeTempColor4Like();\r\nconst TmpColor3 = MakeTempColor4Like();\r\nconst TmpColor4 = MakeTempColor4Like();\r\n\r\n/**\r\n * Samples the texture data at the given uv coordinate using bilinear interpolation.\r\n * Note this will not match GPU sampling behavior exactly.\r\n * Currently assumes clamping behavior.\r\n * @param u - The u coordinate to sample.\r\n * @param v - The v coordinate to sample.\r\n * @param widthPx - The width of the texture in texels.\r\n * @param heightPx - The height of the texture in texels.\r\n * @param data - The texture data to sample.\r\n * @param result - The color to store the sample.\r\n * @param normalizeFunc - The function to normalize the texel values. Default is to divide by 255.\r\n * @returns The result color.\r\n */\r\nexport function Sample2DRgbaToRef<T extends IColor4Like>(\r\n u: number,\r\n v: number,\r\n widthPx: number,\r\n heightPx: number,\r\n data: Uint8Array | Uint16Array | Float32Array,\r\n result: T,\r\n normalizeFunc = (value: number) => value / 255.0\r\n): T {\r\n if (widthPx <= 0 || heightPx <= 0) {\r\n throw new Error(\"Sample2DRgbaToRef: widthPx and heightPx must be positive.\");\r\n }\r\n\r\n const expectedLength = widthPx * heightPx * 4;\r\n if (data.length < expectedLength) {\r\n throw new Error(`Sample2DRgbaToRef: data length (${data.length}) is less than required (${expectedLength}).`);\r\n }\r\n\r\n // Default to clamping behavior, but could support others.\r\n u = Clamp(u);\r\n v = Clamp(v);\r\n\r\n // Compute 4 nearest neighbor texels.\r\n const fractionalTexelX = Math.max(u * widthPx - 0.5, 0);\r\n const fractionalTexelY = Math.max(v * heightPx - 0.5, 0);\r\n const xLeft = Math.floor(fractionalTexelX);\r\n const xRight = Math.min(xLeft + 1, widthPx - 1);\r\n const yBottom = Math.floor(fractionalTexelY);\r\n const yTop = Math.min(yBottom + 1, heightPx - 1);\r\n\r\n // Sample nearest neighbor texels.\r\n const lowerLeftColor = TexelFetch2DRgbaToRef(xLeft, yBottom, widthPx, heightPx, data, TmpColor1, normalizeFunc);\r\n const upperLeftColor = TexelFetch2DRgbaToRef(xLeft, yTop, widthPx, heightPx, data, TmpColor2, normalizeFunc);\r\n const lowerRightColor = TexelFetch2DRgbaToRef(xRight, yBottom, widthPx, heightPx, data, TmpColor3, normalizeFunc);\r\n const upperRightColor = TexelFetch2DRgbaToRef(xRight, yTop, widthPx, heightPx, data, TmpColor4, normalizeFunc);\r\n\r\n // Compute weights.\r\n const tX = fractionalTexelX - xLeft;\r\n const tY = fractionalTexelY - yBottom;\r\n const oneMinusTX = 1.0 - tX;\r\n const oneMinusTY = 1.0 - tY;\r\n const w0 = oneMinusTX * oneMinusTY;\r\n const w1 = tX * oneMinusTY;\r\n const w2 = oneMinusTX * tY;\r\n const w3 = tX * tY;\r\n\r\n // Compute the result.\r\n result.r = lowerLeftColor.r * w0 + lowerRightColor.r * w1 + upperLeftColor.r * w2 + upperRightColor.r * w3;\r\n result.g = lowerLeftColor.g * w0 + lowerRightColor.g * w1 + upperLeftColor.g * w2 + upperRightColor.g * w3;\r\n result.b = lowerLeftColor.b * w0 + lowerRightColor.b * w1 + upperLeftColor.b * w2 + upperRightColor.b * w3;\r\n result.a = lowerLeftColor.a * w0 + lowerRightColor.a * w1 + upperLeftColor.a * w2 + upperRightColor.a * w3;\r\n return result;\r\n}\r\n\r\n/**\r\n * Fetches a texel from a 2D texture and stores the result in the given color.\r\n * @param x - The x coordinate in texels.\r\n * @param y - The y coordinate in texels.\r\n * @param width - The width of the texture in texels.\r\n * @param height - The height of the texture in texels.\r\n * @param data - The texture data to sample from.\r\n * @param result - The color to store the sampled color in.\r\n * @param normalizeFunc - The function to normalize the texel values. Default is to divide by 255.\r\n * @returns The result color.\r\n */\r\nconst TexelFetch2DRgbaToRef = <T extends IColor4Like>(\r\n x: number,\r\n y: number,\r\n width: number,\r\n height: number,\r\n data: Uint8Array | Uint16Array | Float32Array,\r\n result: T,\r\n normalizeFunc = (value: number) => value / 255.0\r\n): T => {\r\n const clampedTexelX = Clamp(x, 0, width - 1);\r\n const clampedTexelY = Clamp(y, 0, height - 1);\r\n const index = 4 * (clampedTexelY * width + clampedTexelX);\r\n result.r = normalizeFunc(data[index]);\r\n result.g = normalizeFunc(data[index + 1]);\r\n result.b = normalizeFunc(data[index + 2]);\r\n result.a = normalizeFunc(data[index + 3]);\r\n return result;\r\n};\r\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// MIT License
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
3
|
import { Clamp, SmoothStep } from "@onerjs/core/Maths/math.scalar.functions.js";
|
|
4
4
|
import { Constants } from "@onerjs/core/Engines/constants.js";
|
|
5
5
|
import { EffectRenderer, EffectWrapper } from "@onerjs/core/Materials/effectRenderer.js";
|
|
@@ -97,15 +97,16 @@ export class TransmittanceLut {
|
|
|
97
97
|
renderTarget.wrapV = Constants.TEXTURE_CLAMP_ADDRESSMODE;
|
|
98
98
|
renderTarget.anisotropicFilteringLevel = 1;
|
|
99
99
|
renderTarget.skipInitialClear = true;
|
|
100
|
-
const
|
|
100
|
+
const atmosphereUbo = atmosphere.uniformBuffer;
|
|
101
|
+
const useUbo = atmosphereUbo.useUbo;
|
|
101
102
|
this._effectWrapper = new EffectWrapper({
|
|
102
103
|
engine,
|
|
103
104
|
name,
|
|
104
105
|
vertexShader: "fullscreenTriangle",
|
|
105
106
|
fragmentShader: "transmittance",
|
|
106
107
|
attributeNames: ["position"],
|
|
107
|
-
uniformNames: ["depth", ...(useUbo ? [] :
|
|
108
|
-
uniformBuffers: useUbo ? [
|
|
108
|
+
uniformNames: ["depth", ...(useUbo ? [] : atmosphereUbo.getUniformNames())],
|
|
109
|
+
uniformBuffers: useUbo ? [atmosphereUbo.name] : [],
|
|
109
110
|
defines: ["#define POSITION_VEC2"],
|
|
110
111
|
useShaderStore: true,
|
|
111
112
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transmittanceLut.js","sourceRoot":"","sources":["../../../../dev/addons/src/atmosphere/transmittanceLut.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,cAAc;AAId,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,oDAAyC;AACrE,OAAO,EAAE,SAAS,EAAE,0CAA+B;AAEnD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,iDAAsC;AAC9E,OAAO,EAAE,aAAa,EAAE,0CAA+B;AAGvD,OAAO,EAAE,UAAU,EAAE,wCAA6B;AAClD,OAAO,EAAE,mBAAmB,EAAE,+DAAoD;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,oDAAyC;AAC9D,OAAO,qCAAqC,CAAC;AAC7C,OAAO,kCAAkC,CAAC;AAE1C,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,wBAAwB,GAAG,EAAE,CAAC,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,CAAC,WAAW,GAAG,GAAG,CAAC,GAAG,WAAW,EAAE,CAAC;AAC9G,MAAM,aAAa,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,UAAU,EAAE,CAAC,EAAE,GAAG,GAAG,WAAW,EAAE,CAAC;AACpE,MAAM,yBAAyB,GAAG,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC;AACxD,MAAM,2BAA2B,GAAG,GAAG,GAAG,GAAG,GAAG,yBAAyB,CAAC;AAE1E,MAAM,YAAY,GAAG,KAAK,CAAC;AAE3B,qBAAqB;AACrB,MAAM,EAAE,GAAG,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IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,0CAA0C;QAC1C,KAAK,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,sBAAsB,CAAC,EAAE,IAAI,CAAC,CAAC,KAAsB,EAAE,EAAE;YAChI,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACnB,OAAO;YACX,CAAC;YACD,IAAI,CAAC,QAAQ,GAAG,KAAiC,CAAC;YAClD,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,SAAS;QACZ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,cAAc,EAAE,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;CACJ","sourcesContent":["// Copyright (c) Microsoft Corporation.\r\n// MIT License\r\n\r\nimport type { Atmosphere } from \"./atmosphere\";\r\nimport type { AtmospherePhysicalProperties } from \"./atmospherePhysicalProperties\";\r\nimport { Clamp, SmoothStep } from \"core/Maths/math.scalar.functions\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport { EffectRenderer, EffectWrapper } from \"core/Materials/effectRenderer\";\r\nimport { FromHalfFloat } from \"core/Misc/textureTools\";\r\nimport type { IColor3Like, IColor4Like, IVector2Like, IVector3Like } from \"core/Maths/math.like\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport { Sample2DRgbaToRef } from \"./sampling\";\r\nimport { Vector3Dot } from \"core/Maths/math.vector.functions\";\r\nimport \"./Shaders/fullscreenTriangle.vertex\";\r\nimport \"./Shaders/transmittance.fragment\";\r\n\r\nconst LutWidthPx = 256;\r\nconst LutHeightPx = 64;\r\nconst EffectiveDomainInUVSpace = { x: (LutWidthPx - 1.0) / LutWidthPx, y: (LutHeightPx - 1.0) / LutHeightPx };\r\nconst HalfTexelSize = { x: 0.5 / LutWidthPx, y: 0.5 / LutHeightPx };\r\nconst TransmittanceHorizonRange = 2.0 * HalfTexelSize.x;\r\nconst TransmittanceMaxUnoccludedU = 1.0 - 0.5 * TransmittanceHorizonRange;\r\n\r\nconst UseHalfFloat = false;\r\n\r\n// Temporary storage.\r\nconst Uv = { x: Number.NaN, y: Number.NaN } as IVector2Like;\r\nconst LightColorTemp = { r: Number.NaN, g: Number.NaN, b: Number.NaN } as IColor3Like;\r\nconst DirectionToLightTemp = { x: Number.NaN, y: Number.NaN, z: Number.NaN } as IVector3Like;\r\nconst Color4Temp = { r: Number.NaN, g: Number.NaN, b: Number.NaN, a: Number.NaN } as IColor4Like;\r\n\r\nconst ComputeLutUVToRef = (properties: AtmospherePhysicalProperties, radius: number, cosAngleLightToZenith: number, uv: IVector2Like): void => {\r\n const radiusSquared = radius * radius;\r\n const distanceToHorizon = Math.sqrt(Math.max(0.0, radiusSquared - properties.planetRadiusSquared));\r\n\r\n const cosAngleLightToZenithSq = cosAngleLightToZenith * cosAngleLightToZenith;\r\n const discriminant = radiusSquared * (cosAngleLightToZenithSq - 1.0) + properties.atmosphereRadiusSquared;\r\n const distanceToAtmosphereEdge = Math.max(0.0, -radius * cosAngleLightToZenith + Math.sqrt(Math.max(0.0, discriminant)));\r\n\r\n const minDistanceToAtmosphereEdge = Math.max(0.0, properties.atmosphereRadius - radius);\r\n const maxDistanceToAtmosphereEdge = distanceToHorizon + properties.horizonDistanceToAtmosphereEdge;\r\n const cosAngleLightToZenithCoordinate =\r\n (distanceToAtmosphereEdge - minDistanceToAtmosphereEdge) / Math.max(0.000001, maxDistanceToAtmosphereEdge - minDistanceToAtmosphereEdge);\r\n const distanceToHorizonCoordinate = distanceToHorizon / Math.max(0.000001, properties.horizonDistanceToAtmosphereEdge);\r\n\r\n // Unit to UV.\r\n uv.x = EffectiveDomainInUVSpace.x * cosAngleLightToZenithCoordinate + HalfTexelSize.x;\r\n uv.y = EffectiveDomainInUVSpace.y * distanceToHorizonCoordinate + HalfTexelSize.y;\r\n};\r\n\r\nconst SampleLutToRef = (\r\n properties: AtmospherePhysicalProperties,\r\n lutData: Uint8Array | Uint16Array,\r\n positionDistanceToOrigin: number,\r\n cosAngleLightToZenith: number,\r\n result: IColor4Like\r\n): void => {\r\n if (positionDistanceToOrigin > properties.atmosphereRadius) {\r\n result.r = result.g = result.b = result.a = 1.0;\r\n return;\r\n }\r\n\r\n ComputeLutUVToRef(properties, positionDistanceToOrigin, cosAngleLightToZenith, Uv);\r\n Sample2DRgbaToRef(Uv.x, Uv.y, LutWidthPx, LutHeightPx, lutData, result, UseHalfFloat ? FromHalfFloat : (value) => value / 255.0);\r\n\r\n const weight = Clamp(SmoothStep(1.0, 0.0, Clamp((Uv.x - TransmittanceMaxUnoccludedU) / TransmittanceHorizonRange)));\r\n result.r *= weight;\r\n result.g *= weight;\r\n result.b *= weight;\r\n result.a *= weight;\r\n};\r\n\r\n/**\r\n * The transmittance LUT can be used to get the radiance from an external light source arriving a given point, accounting for atmospheric scattering.\r\n */\r\nexport class TransmittanceLut {\r\n /**\r\n * Listen to this observer to know when the LUT data has been updated.\r\n * This is typically infrequent (once at startup), but also happens whenever the atmosphere's properties change.\r\n */\r\n public readonly onUpdatedObservable = new Observable<void>();\r\n\r\n private readonly _atmosphere: Atmosphere;\r\n private _lutData: Uint8Array | Uint16Array = new Uint8Array(0);\r\n private _renderTarget: Nullable<RenderTargetTexture>;\r\n private _effectWrapper: Nullable<EffectWrapper>;\r\n private _effectRenderer: Nullable<EffectRenderer>;\r\n private _isDirty = true;\r\n private _isDisposed = false;\r\n\r\n /**\r\n * True if the LUT has been rendered.\r\n */\r\n public get isDirty(): boolean {\r\n return this._isDirty;\r\n }\r\n\r\n /**\r\n * The render target that contains the transmittance LUT.\r\n * @throws if the LUT has been disposed.\r\n */\r\n public get renderTarget(): RenderTargetTexture {\r\n if (this._isDisposed || this._renderTarget === null) {\r\n throw new Error();\r\n }\r\n return this._renderTarget;\r\n }\r\n\r\n /**\r\n * Constructs the {@link TransmittanceLut}.\r\n * @param atmosphere - The atmosphere that owns this LUT.\r\n */\r\n constructor(atmosphere: Atmosphere) {\r\n this._atmosphere = atmosphere;\r\n\r\n const scene = this._atmosphere.scene;\r\n const engine = scene.getEngine();\r\n const useHalfFloat = UseHalfFloat && engine.getCaps().textureHalfFloatRender;\r\n\r\n const name = \"atmo-transmittance\";\r\n const renderTarget = (this._renderTarget = new RenderTargetTexture(name, { width: LutWidthPx, height: LutHeightPx }, scene, {\r\n type: useHalfFloat ? Constants.TEXTURETYPE_HALF_FLOAT : Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n samplingMode: Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n generateDepthBuffer: false,\r\n gammaSpace: false,\r\n }));\r\n renderTarget.wrapU = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n renderTarget.wrapV = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n renderTarget.anisotropicFilteringLevel = 1;\r\n renderTarget.skipInitialClear = true;\r\n\r\n const useUbo = this._atmosphere.uniformBuffer.useUbo;\r\n this._effectWrapper = new EffectWrapper({\r\n engine,\r\n name,\r\n vertexShader: \"fullscreenTriangle\",\r\n fragmentShader: \"transmittance\",\r\n attributeNames: [\"position\"],\r\n uniformNames: [\"depth\", ...(useUbo ? [] : this._atmosphere.uniformBuffer.getUniformNames())],\r\n uniformBuffers: useUbo ? [this._atmosphere.uniformBuffer.name] : [],\r\n defines: [\"#define POSITION_VEC2\"],\r\n useShaderStore: true,\r\n });\r\n\r\n this._effectRenderer = new EffectRenderer(engine, {\r\n // Full screen triangle.\r\n indices: [0, 2, 1],\r\n positions: [-1, -1, -1, 3, 3, -1],\r\n });\r\n }\r\n\r\n /**\r\n * Gets the transmittance of an external light through the atmosphere to a point specified by its distance to the planet center and its geocentric normal.\r\n * The result is always a linear space color.\r\n * @param directionToLight - The direction to the light source.\r\n * @param pointRadius - The distance from the origin to the point.\r\n * @param pointGeocentricNormal - The normal of the point.\r\n * @param result - The color to write the result to.\r\n * @returns The result color.\r\n */\r\n public getTransmittedColorToRef<T extends IColor3Like>(directionToLight: IVector3Like, pointRadius: number, pointGeocentricNormal: IVector3Like, result: T): T {\r\n if (this._lutData[0] !== undefined) {\r\n const cosAngleLightToZenith = Vector3Dot(directionToLight, pointGeocentricNormal);\r\n SampleLutToRef(this._atmosphere.physicalProperties, this._lutData, pointRadius, cosAngleLightToZenith, Color4Temp);\r\n result.r = Color4Temp.r;\r\n result.g = Color4Temp.g;\r\n result.b = Color4Temp.b;\r\n } else {\r\n // Fallback.\r\n result.r = result.g = result.b = 1.0;\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Derives light color from the transmittance at a point specified by its distance to the planet center and its geocentric normal.\r\n * @param light - The light to update.\r\n * @param pointRadius - The distance from the origin to the point.\r\n * @param pointGeocentricNormal - The normal of the point.\r\n */\r\n public updateLightParameters(light: DirectionalLight, pointRadius: number, pointGeocentricNormal: IVector3Like): void {\r\n const lightDirection = light.direction;\r\n DirectionToLightTemp.x = -lightDirection.x;\r\n DirectionToLightTemp.y = -lightDirection.y;\r\n DirectionToLightTemp.z = -lightDirection.z;\r\n this.getTransmittedColorToRef(DirectionToLightTemp, pointRadius, pointGeocentricNormal, LightColorTemp);\r\n\r\n light.diffuse.copyFromFloats(LightColorTemp.r, LightColorTemp.g, LightColorTemp.b);\r\n light.specular.copyFromFloats(LightColorTemp.r, LightColorTemp.g, LightColorTemp.b);\r\n }\r\n\r\n /**\r\n * Renders the LUT if needed.\r\n * @returns true if the LUT was rendered.\r\n */\r\n public render(): boolean {\r\n // Only need to render the LUT once.\r\n const effectWrapper = this._effectWrapper;\r\n if (!this._isDirty || !effectWrapper?.isReady() || !this._renderTarget?.isReady()) {\r\n return false;\r\n }\r\n\r\n const engine = this._atmosphere.scene.getEngine();\r\n\r\n engine.bindFramebuffer(this.renderTarget.renderTarget!, undefined, undefined, undefined, true);\r\n\r\n const effectRenderer = this._effectRenderer!;\r\n effectRenderer.applyEffectWrapper(effectWrapper);\r\n\r\n effectRenderer.saveStates();\r\n effectRenderer.setViewport();\r\n\r\n const effect = effectWrapper.effect;\r\n effectRenderer.bindBuffers(effect);\r\n\r\n this._atmosphere.bindUniformBufferToEffect(effect);\r\n\r\n effect.setFloat(\"depth\", 0);\r\n\r\n effectRenderer.draw();\r\n\r\n effectRenderer.restoreStates();\r\n engine.restoreDefaultFramebuffer();\r\n\r\n this._isDirty = false;\r\n\r\n // eslint-disable-next-line github/no-then\r\n void this.renderTarget.readPixels(0, 0, undefined, undefined, UseHalfFloat /* noDataConversion */)?.then((value: ArrayBufferView) => {\r\n if (this._isDisposed) {\r\n return;\r\n }\r\n this._lutData = value as Uint8Array | Uint16Array;\r\n this.onUpdatedObservable.notifyObservers();\r\n });\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Marks the LUT as needing to be rendered.\r\n */\r\n public markDirty(): void {\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Disposes the LUT and its resources.\r\n */\r\n public dispose(): void {\r\n this._renderTarget?.dispose();\r\n this._renderTarget = null;\r\n this._effectWrapper?.dispose();\r\n this._effectWrapper = null;\r\n this._effectRenderer?.dispose();\r\n this._effectRenderer = null;\r\n this._isDisposed = true;\r\n }\r\n}\r\n"]}
|
|
1
|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AE,IAAI,CAAC,CAAC,KAAsB,EAAE,EAAE;YAChI,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACnB,OAAO;YACX,CAAC;YACD,IAAI,CAAC,QAAQ,GAAG,KAAiC,CAAC;YAClD,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,SAAS;QACZ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,cAAc,EAAE,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;CACJ","sourcesContent":["// Copyright (c) Microsoft Corporation.\r\n// Licensed under the MIT License.\r\n\r\nimport type { Atmosphere } from \"./atmosphere\";\r\nimport type { AtmospherePhysicalProperties } from \"./atmospherePhysicalProperties\";\r\nimport { Clamp, SmoothStep } from \"core/Maths/math.scalar.functions\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport { EffectRenderer, EffectWrapper } from \"core/Materials/effectRenderer\";\r\nimport { FromHalfFloat } from \"core/Misc/textureTools\";\r\nimport type { IColor3Like, IColor4Like, IVector2Like, IVector3Like } from \"core/Maths/math.like\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport { Sample2DRgbaToRef } from \"./sampling\";\r\nimport { Vector3Dot } from \"core/Maths/math.vector.functions\";\r\nimport \"./Shaders/fullscreenTriangle.vertex\";\r\nimport \"./Shaders/transmittance.fragment\";\r\n\r\nconst LutWidthPx = 256;\r\nconst LutHeightPx = 64;\r\nconst EffectiveDomainInUVSpace = { x: (LutWidthPx - 1.0) / LutWidthPx, y: (LutHeightPx - 1.0) / LutHeightPx };\r\nconst HalfTexelSize = { x: 0.5 / LutWidthPx, y: 0.5 / LutHeightPx };\r\nconst TransmittanceHorizonRange = 2.0 * HalfTexelSize.x;\r\nconst TransmittanceMaxUnoccludedU = 1.0 - 0.5 * TransmittanceHorizonRange;\r\n\r\nconst UseHalfFloat = false;\r\n\r\n// Temporary storage.\r\nconst Uv = { x: Number.NaN, y: Number.NaN } as IVector2Like;\r\nconst LightColorTemp = { r: Number.NaN, g: Number.NaN, b: Number.NaN } as IColor3Like;\r\nconst DirectionToLightTemp = { x: Number.NaN, y: Number.NaN, z: Number.NaN } as IVector3Like;\r\nconst Color4Temp = { r: Number.NaN, g: Number.NaN, b: Number.NaN, a: Number.NaN } as IColor4Like;\r\n\r\nconst ComputeLutUVToRef = (properties: AtmospherePhysicalProperties, radius: number, cosAngleLightToZenith: number, uv: IVector2Like): void => {\r\n const radiusSquared = radius * radius;\r\n const distanceToHorizon = Math.sqrt(Math.max(0.0, radiusSquared - properties.planetRadiusSquared));\r\n\r\n const cosAngleLightToZenithSq = cosAngleLightToZenith * cosAngleLightToZenith;\r\n const discriminant = radiusSquared * (cosAngleLightToZenithSq - 1.0) + properties.atmosphereRadiusSquared;\r\n const distanceToAtmosphereEdge = Math.max(0.0, -radius * cosAngleLightToZenith + Math.sqrt(Math.max(0.0, discriminant)));\r\n\r\n const minDistanceToAtmosphereEdge = Math.max(0.0, properties.atmosphereRadius - radius);\r\n const maxDistanceToAtmosphereEdge = distanceToHorizon + properties.horizonDistanceToAtmosphereEdge;\r\n const cosAngleLightToZenithCoordinate =\r\n (distanceToAtmosphereEdge - minDistanceToAtmosphereEdge) / Math.max(0.000001, maxDistanceToAtmosphereEdge - minDistanceToAtmosphereEdge);\r\n const distanceToHorizonCoordinate = distanceToHorizon / Math.max(0.000001, properties.horizonDistanceToAtmosphereEdge);\r\n\r\n // Unit to UV.\r\n uv.x = EffectiveDomainInUVSpace.x * cosAngleLightToZenithCoordinate + HalfTexelSize.x;\r\n uv.y = EffectiveDomainInUVSpace.y * distanceToHorizonCoordinate + HalfTexelSize.y;\r\n};\r\n\r\nconst SampleLutToRef = (\r\n properties: AtmospherePhysicalProperties,\r\n lutData: Uint8Array | Uint16Array,\r\n positionDistanceToOrigin: number,\r\n cosAngleLightToZenith: number,\r\n result: IColor4Like\r\n): void => {\r\n if (positionDistanceToOrigin > properties.atmosphereRadius) {\r\n result.r = result.g = result.b = result.a = 1.0;\r\n return;\r\n }\r\n\r\n ComputeLutUVToRef(properties, positionDistanceToOrigin, cosAngleLightToZenith, Uv);\r\n Sample2DRgbaToRef(Uv.x, Uv.y, LutWidthPx, LutHeightPx, lutData, result, UseHalfFloat ? FromHalfFloat : (value) => value / 255.0);\r\n\r\n const weight = Clamp(SmoothStep(1.0, 0.0, Clamp((Uv.x - TransmittanceMaxUnoccludedU) / TransmittanceHorizonRange)));\r\n result.r *= weight;\r\n result.g *= weight;\r\n result.b *= weight;\r\n result.a *= weight;\r\n};\r\n\r\n/**\r\n * The transmittance LUT can be used to get the radiance from an external light source arriving a given point, accounting for atmospheric scattering.\r\n */\r\nexport class TransmittanceLut {\r\n /**\r\n * Listen to this observer to know when the LUT data has been updated.\r\n * This is typically infrequent (once at startup), but also happens whenever the atmosphere's properties change.\r\n */\r\n public readonly onUpdatedObservable = new Observable<void>();\r\n\r\n private readonly _atmosphere: Atmosphere;\r\n private _lutData: Uint8Array | Uint16Array = new Uint8Array(0);\r\n private _renderTarget: Nullable<RenderTargetTexture>;\r\n private _effectWrapper: Nullable<EffectWrapper>;\r\n private _effectRenderer: Nullable<EffectRenderer>;\r\n private _isDirty = true;\r\n private _isDisposed = false;\r\n\r\n /**\r\n * True if the LUT has been rendered.\r\n */\r\n public get isDirty(): boolean {\r\n return this._isDirty;\r\n }\r\n\r\n /**\r\n * The render target that contains the transmittance LUT.\r\n * @throws if the LUT has been disposed.\r\n */\r\n public get renderTarget(): RenderTargetTexture {\r\n if (this._isDisposed || this._renderTarget === null) {\r\n throw new Error();\r\n }\r\n return this._renderTarget;\r\n }\r\n\r\n /**\r\n * Constructs the {@link TransmittanceLut}.\r\n * @param atmosphere - The atmosphere that owns this LUT.\r\n */\r\n constructor(atmosphere: Atmosphere) {\r\n this._atmosphere = atmosphere;\r\n\r\n const scene = this._atmosphere.scene;\r\n const engine = scene.getEngine();\r\n const useHalfFloat = UseHalfFloat && engine.getCaps().textureHalfFloatRender;\r\n\r\n const name = \"atmo-transmittance\";\r\n const renderTarget = (this._renderTarget = new RenderTargetTexture(name, { width: LutWidthPx, height: LutHeightPx }, scene, {\r\n type: useHalfFloat ? Constants.TEXTURETYPE_HALF_FLOAT : Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n samplingMode: Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n generateDepthBuffer: false,\r\n gammaSpace: false,\r\n }));\r\n renderTarget.wrapU = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n renderTarget.wrapV = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n renderTarget.anisotropicFilteringLevel = 1;\r\n renderTarget.skipInitialClear = true;\r\n\r\n const atmosphereUbo = atmosphere.uniformBuffer;\r\n const useUbo = atmosphereUbo.useUbo;\r\n this._effectWrapper = new EffectWrapper({\r\n engine,\r\n name,\r\n vertexShader: \"fullscreenTriangle\",\r\n fragmentShader: \"transmittance\",\r\n attributeNames: [\"position\"],\r\n uniformNames: [\"depth\", ...(useUbo ? [] : atmosphereUbo.getUniformNames())],\r\n uniformBuffers: useUbo ? [atmosphereUbo.name] : [],\r\n defines: [\"#define POSITION_VEC2\"],\r\n useShaderStore: true,\r\n });\r\n\r\n this._effectRenderer = new EffectRenderer(engine, {\r\n // Full screen triangle.\r\n indices: [0, 2, 1],\r\n positions: [-1, -1, -1, 3, 3, -1],\r\n });\r\n }\r\n\r\n /**\r\n * Gets the transmittance of an external light through the atmosphere to a point specified by its distance to the planet center and its geocentric normal.\r\n * The result is always a linear space color.\r\n * @param directionToLight - The direction to the light source.\r\n * @param pointRadius - The distance from the origin to the point.\r\n * @param pointGeocentricNormal - The normal of the point.\r\n * @param result - The color to write the result to.\r\n * @returns The result color.\r\n */\r\n public getTransmittedColorToRef<T extends IColor3Like>(directionToLight: IVector3Like, pointRadius: number, pointGeocentricNormal: IVector3Like, result: T): T {\r\n if (this._lutData[0] !== undefined) {\r\n const cosAngleLightToZenith = Vector3Dot(directionToLight, pointGeocentricNormal);\r\n SampleLutToRef(this._atmosphere.physicalProperties, this._lutData, pointRadius, cosAngleLightToZenith, Color4Temp);\r\n result.r = Color4Temp.r;\r\n result.g = Color4Temp.g;\r\n result.b = Color4Temp.b;\r\n } else {\r\n // Fallback.\r\n result.r = result.g = result.b = 1.0;\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Derives light color from the transmittance at a point specified by its distance to the planet center and its geocentric normal.\r\n * @param light - The light to update.\r\n * @param pointRadius - The distance from the origin to the point.\r\n * @param pointGeocentricNormal - The normal of the point.\r\n */\r\n public updateLightParameters(light: DirectionalLight, pointRadius: number, pointGeocentricNormal: IVector3Like): void {\r\n const lightDirection = light.direction;\r\n DirectionToLightTemp.x = -lightDirection.x;\r\n DirectionToLightTemp.y = -lightDirection.y;\r\n DirectionToLightTemp.z = -lightDirection.z;\r\n this.getTransmittedColorToRef(DirectionToLightTemp, pointRadius, pointGeocentricNormal, LightColorTemp);\r\n\r\n light.diffuse.copyFromFloats(LightColorTemp.r, LightColorTemp.g, LightColorTemp.b);\r\n light.specular.copyFromFloats(LightColorTemp.r, LightColorTemp.g, LightColorTemp.b);\r\n }\r\n\r\n /**\r\n * Renders the LUT if needed.\r\n * @returns true if the LUT was rendered.\r\n */\r\n public render(): boolean {\r\n // Only need to render the LUT once.\r\n const effectWrapper = this._effectWrapper;\r\n if (!this._isDirty || !effectWrapper?.isReady() || !this._renderTarget?.isReady()) {\r\n return false;\r\n }\r\n\r\n const engine = this._atmosphere.scene.getEngine();\r\n\r\n engine.bindFramebuffer(this.renderTarget.renderTarget!, undefined, undefined, undefined, true);\r\n\r\n const effectRenderer = this._effectRenderer!;\r\n effectRenderer.applyEffectWrapper(effectWrapper);\r\n\r\n effectRenderer.saveStates();\r\n effectRenderer.setViewport();\r\n\r\n const effect = effectWrapper.effect;\r\n effectRenderer.bindBuffers(effect);\r\n\r\n this._atmosphere.bindUniformBufferToEffect(effect);\r\n\r\n effect.setFloat(\"depth\", 0);\r\n\r\n effectRenderer.draw();\r\n\r\n effectRenderer.restoreStates();\r\n engine.restoreDefaultFramebuffer();\r\n\r\n this._isDirty = false;\r\n\r\n // eslint-disable-next-line github/no-then\r\n void this.renderTarget.readPixels(0, 0, undefined, undefined, UseHalfFloat /* noDataConversion */)?.then((value: ArrayBufferView) => {\r\n if (this._isDisposed) {\r\n return;\r\n }\r\n this._lutData = value as Uint8Array | Uint16Array;\r\n this.onUpdatedObservable.notifyObservers();\r\n });\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Marks the LUT as needing to be rendered.\r\n */\r\n public markDirty(): void {\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Disposes the LUT and its resources.\r\n */\r\n public dispose(): void {\r\n this._renderTarget?.dispose();\r\n this._renderTarget = null;\r\n this._effectWrapper?.dispose();\r\n this._effectWrapper = null;\r\n this._effectRenderer?.dispose();\r\n this._effectRenderer = null;\r\n this._isDisposed = true;\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onerjs/addons",
|
|
3
|
-
"version": "8.32.
|
|
3
|
+
"version": "8.32.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"postcompile": "build-tools -c add-js-to-es6"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@onerjs/core": "^8.32.
|
|
21
|
+
"@onerjs/core": "^8.32.1",
|
|
22
22
|
"@dev/addons": "^1.0.0",
|
|
23
23
|
"@dev/build-tools": "^1.0.0"
|
|
24
24
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// MIT License
|
|
3
|
-
import { Sample2DRgbaToRef } from "../../sampling.js";
|
|
4
|
-
const Black = { r: 0, g: 0, b: 0, a: 1.0 };
|
|
5
|
-
const DarkGrey = { r: 0.25, g: 0.25, b: 0.25, a: 1.0 };
|
|
6
|
-
const Grey = { r: 0.5, g: 0.5, b: 0.5, a: 1.0 };
|
|
7
|
-
const White = { r: 1.0, g: 1.0, b: 1.0, a: 1.0 };
|
|
8
|
-
const Red = { r: 1.0, g: 0.0, b: 0.0, a: 1.0 };
|
|
9
|
-
const Green = { r: 0.0, g: 1.0, b: 0.0, a: 1.0 };
|
|
10
|
-
const Blue = { r: 0.0, g: 0.0, b: 1.0, a: 1.0 };
|
|
11
|
-
expect.extend({
|
|
12
|
-
toBeApproxColor4Like(received, expected) {
|
|
13
|
-
const isEqual = Math.abs(received.r - expected.r) < 0.0001 &&
|
|
14
|
-
Math.abs(received.g - expected.g) < 0.0001 &&
|
|
15
|
-
Math.abs(received.b - expected.b) < 0.0001 &&
|
|
16
|
-
Math.abs(received.a - expected.a) < 0.0001;
|
|
17
|
-
return {
|
|
18
|
-
message: () => `expected ${JSON.stringify(received)} to be close to ${JSON.stringify(expected)}`,
|
|
19
|
-
pass: isEqual,
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
describe("textureSampler", () => {
|
|
24
|
-
test("testVertical2x2", () => {
|
|
25
|
-
const testData2x2 = new Float32Array([Black, Black, White, White].flatMap((x) => [x.r, x.g, x.b, x.a]));
|
|
26
|
-
const result = { r: 0, g: 0, b: 0, a: 0 };
|
|
27
|
-
Sample2DRgbaToRef(0.0, 0.0, 2, 2, testData2x2, result, (value) => value);
|
|
28
|
-
expect(result).toBeApproxColor4Like(Black);
|
|
29
|
-
Sample2DRgbaToRef(1.0, 0.25, 2, 2, testData2x2, result, (value) => value);
|
|
30
|
-
expect(result).toBeApproxColor4Like(Black);
|
|
31
|
-
Sample2DRgbaToRef(1.0, 0.375, 2, 2, testData2x2, result, (value) => value);
|
|
32
|
-
expect(result).toBeApproxColor4Like(DarkGrey);
|
|
33
|
-
Sample2DRgbaToRef(1.0, 0.5, 2, 2, testData2x2, result, (value) => value);
|
|
34
|
-
expect(result).toBeApproxColor4Like(Grey);
|
|
35
|
-
Sample2DRgbaToRef(0.5, 0.5, 2, 2, testData2x2, result, (value) => value);
|
|
36
|
-
expect(result).toBeApproxColor4Like(Grey);
|
|
37
|
-
Sample2DRgbaToRef(1.0, 1.0, 2, 2, testData2x2, result, (value) => value);
|
|
38
|
-
expect(result).toBeApproxColor4Like(White);
|
|
39
|
-
});
|
|
40
|
-
test("testVertical3x3", () => {
|
|
41
|
-
const testData2x2 = new Float32Array([Black, Black, White, White, White, White, White, White, White].flatMap((x) => [x.r, x.g, x.b, x.a]));
|
|
42
|
-
const result = { r: 0, g: 0, b: 0, a: 0 };
|
|
43
|
-
Sample2DRgbaToRef(0.33333333333, 0.33333333333, 3, 3, testData2x2, result, (value) => value);
|
|
44
|
-
expect(result).toBeApproxColor4Like(Grey);
|
|
45
|
-
});
|
|
46
|
-
test("testHorizontal2x2", () => {
|
|
47
|
-
const testData2x2 = new Float32Array([Black, White, Black, White].flatMap((x) => [x.r, x.g, x.b, x.a]));
|
|
48
|
-
const result = { r: 0, g: 0, b: 0, a: 0 };
|
|
49
|
-
Sample2DRgbaToRef(0.0, 0.0, 2, 2, testData2x2, result, (value) => value);
|
|
50
|
-
expect(result).toBeApproxColor4Like(Black);
|
|
51
|
-
Sample2DRgbaToRef(0.5, 1.0, 2, 2, testData2x2, result, (value) => value);
|
|
52
|
-
expect(result).toBeApproxColor4Like(Grey);
|
|
53
|
-
Sample2DRgbaToRef(0.5, 0.5, 2, 2, testData2x2, result, (value) => value);
|
|
54
|
-
expect(result).toBeApproxColor4Like(Grey);
|
|
55
|
-
Sample2DRgbaToRef(1.0, 1.0, 2, 2, testData2x2, result, (value) => value);
|
|
56
|
-
expect(result).toBeApproxColor4Like(White);
|
|
57
|
-
});
|
|
58
|
-
test("testDistinct2x2", () => {
|
|
59
|
-
const data = new Float32Array([Red, Green, Blue, White].flatMap((x) => [x.r, x.g, x.b, x.a]));
|
|
60
|
-
const result = { r: 0, g: 0, b: 0, a: 0 };
|
|
61
|
-
Sample2DRgbaToRef(0.25, 0.25, 2, 2, data, result, (v) => v);
|
|
62
|
-
expect(result).toBeApproxColor4Like({ r: 1.0, g: 0.0, b: 0.0, a: 1 });
|
|
63
|
-
Sample2DRgbaToRef(0.25, 0.75, 2, 2, data, result, (v) => v);
|
|
64
|
-
expect(result).toBeApproxColor4Like({ r: 0.0, g: 0.0, b: 1.0, a: 1 });
|
|
65
|
-
Sample2DRgbaToRef(0.75, 0.25, 2, 2, data, result, (v) => v);
|
|
66
|
-
expect(result).toBeApproxColor4Like({ r: 0.0, g: 1.0, b: 0.0, a: 1 });
|
|
67
|
-
Sample2DRgbaToRef(0.75, 0.75, 2, 2, data, result, (v) => v);
|
|
68
|
-
expect(result).toBeApproxColor4Like({ r: 1.0, g: 1.0, b: 1.0, a: 1 });
|
|
69
|
-
Sample2DRgbaToRef(0.5, 0.5, 2, 2, data, result, (v) => v);
|
|
70
|
-
expect(result).toBeApproxColor4Like({ r: 0.5, g: 0.5, b: 0.5, a: 1 });
|
|
71
|
-
Sample2DRgbaToRef(0.5, 0.0, 2, 2, data, result, (v) => v);
|
|
72
|
-
expect(result).toBeApproxColor4Like({ r: 0.5, g: 0.5, b: 0.0, a: 1 });
|
|
73
|
-
Sample2DRgbaToRef(0.0, 0.5, 2, 2, data, result, (v) => v);
|
|
74
|
-
expect(result).toBeApproxColor4Like({ r: 0.5, g: 0.0, b: 0.5, a: 1 });
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
//# sourceMappingURL=sampling.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sampling.test.js","sourceRoot":"","sources":["../../../../../../dev/addons/src/atmosphere/test/unit/sampling.test.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,cAAc;AAEd,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AAC3C,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AACvD,MAAM,IAAI,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AAChD,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AACjD,MAAM,GAAG,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AAC/C,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC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IColor4Like } from \"core/Maths/math.like\";\r\n\r\nconst Black = { r: 0, g: 0, b: 0, a: 1.0 };\r\nconst DarkGrey = { r: 0.25, g: 0.25, b: 0.25, a: 1.0 };\r\nconst Grey = { r: 0.5, g: 0.5, b: 0.5, a: 1.0 };\r\nconst White = { r: 1.0, g: 1.0, b: 1.0, a: 1.0 };\r\nconst Red = { r: 1.0, g: 0.0, b: 0.0, a: 1.0 };\r\nconst Green = { r: 0.0, g: 1.0, b: 0.0, a: 1.0 };\r\nconst Blue = { r: 0.0, g: 0.0, b: 1.0, a: 1.0 };\r\n\r\nexpect.extend({\r\n toBeApproxColor4Like(received: IColor4Like, expected: IColor4Like) {\r\n const isEqual =\r\n Math.abs(received.r - expected.r) < 0.0001 &&\r\n Math.abs(received.g - expected.g) < 0.0001 &&\r\n Math.abs(received.b - expected.b) < 0.0001 &&\r\n Math.abs(received.a - expected.a) < 0.0001;\r\n return {\r\n message: () => `expected ${JSON.stringify(received)} to be close to ${JSON.stringify(expected)}`,\r\n pass: isEqual,\r\n };\r\n },\r\n});\r\n\r\ndescribe(\"textureSampler\", () => {\r\n test(\"testVertical2x2\", () => {\r\n const testData2x2 = new Float32Array([Black, Black, White, White].flatMap((x) => [x.r, x.g, x.b, x.a]));\r\n\r\n const result = { r: 0, g: 0, b: 0, a: 0 };\r\n Sample2DRgbaToRef(0.0, 0.0, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(Black);\r\n\r\n Sample2DRgbaToRef(1.0, 0.25, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(Black);\r\n\r\n Sample2DRgbaToRef(1.0, 0.375, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(DarkGrey);\r\n\r\n Sample2DRgbaToRef(1.0, 0.5, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(Grey);\r\n\r\n Sample2DRgbaToRef(0.5, 0.5, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(Grey);\r\n\r\n Sample2DRgbaToRef(1.0, 1.0, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(White);\r\n });\r\n test(\"testVertical3x3\", () => {\r\n const testData2x2 = new Float32Array([Black, Black, White, White, White, White, White, White, White].flatMap((x) => [x.r, x.g, x.b, x.a]));\r\n\r\n const result = { r: 0, g: 0, b: 0, a: 0 };\r\n Sample2DRgbaToRef(0.33333333333, 0.33333333333, 3, 3, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(Grey);\r\n });\r\n test(\"testHorizontal2x2\", () => {\r\n const testData2x2 = new Float32Array([Black, White, Black, White].flatMap((x) => [x.r, x.g, x.b, x.a]));\r\n\r\n const result = { r: 0, g: 0, b: 0, a: 0 };\r\n Sample2DRgbaToRef(0.0, 0.0, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(Black);\r\n\r\n Sample2DRgbaToRef(0.5, 1.0, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(Grey);\r\n\r\n Sample2DRgbaToRef(0.5, 0.5, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(Grey);\r\n\r\n Sample2DRgbaToRef(1.0, 1.0, 2, 2, testData2x2, result, (value) => value);\r\n (expect(result) as any).toBeApproxColor4Like(White);\r\n });\r\n test(\"testDistinct2x2\", () => {\r\n const data = new Float32Array([Red, Green, Blue, White].flatMap((x) => [x.r, x.g, x.b, x.a]));\r\n\r\n const result = { r: 0, g: 0, b: 0, a: 0 };\r\n Sample2DRgbaToRef(0.25, 0.25, 2, 2, data, result, (v) => v);\r\n (expect(result) as any).toBeApproxColor4Like({ r: 1.0, g: 0.0, b: 0.0, a: 1 });\r\n\r\n Sample2DRgbaToRef(0.25, 0.75, 2, 2, data, result, (v) => v);\r\n (expect(result) as any).toBeApproxColor4Like({ r: 0.0, g: 0.0, b: 1.0, a: 1 });\r\n\r\n Sample2DRgbaToRef(0.75, 0.25, 2, 2, data, result, (v) => v);\r\n (expect(result) as any).toBeApproxColor4Like({ r: 0.0, g: 1.0, b: 0.0, a: 1 });\r\n\r\n Sample2DRgbaToRef(0.75, 0.75, 2, 2, data, result, (v) => v);\r\n (expect(result) as any).toBeApproxColor4Like({ r: 1.0, g: 1.0, b: 1.0, a: 1 });\r\n\r\n Sample2DRgbaToRef(0.5, 0.5, 2, 2, data, result, (v) => v);\r\n (expect(result) as any).toBeApproxColor4Like({ r: 0.5, g: 0.5, b: 0.5, a: 1 });\r\n\r\n Sample2DRgbaToRef(0.5, 0.0, 2, 2, data, result, (v) => v);\r\n (expect(result) as any).toBeApproxColor4Like({ r: 0.5, g: 0.5, b: 0.0, a: 1 });\r\n\r\n Sample2DRgbaToRef(0.0, 0.5, 2, 2, data, result, (v) => v);\r\n (expect(result) as any).toBeApproxColor4Like({ r: 0.5, g: 0.0, b: 0.5, a: 1 });\r\n });\r\n});\r\n"]}
|