Skip to content

Commit 862f455

Browse files
MiiBondMike Bond
andauthored
Load dominant direction from .env (#16765)
This adds logic to read the dominant direction of an IBL from the .env file, if it exists. Co-authored-by: Mike Bond <[email protected]>
1 parent 7a65def commit 862f455

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/dev/core/src/Misc/environmentTextureTools.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,11 @@ export function UploadEnvLevelsAsync(texture: InternalTexture, data: ArrayBuffer
580580
const irradianceTexture = info.irradiance?.irradianceTexture;
581581
if (irradianceTexture) {
582582
const irradianceImageData = CreateIrradianceImageDataArrayBufferViews(data, info);
583-
promises.push(UploadIrradianceLevelsAsync(texture, irradianceImageData, irradianceTexture.size, info.imageType));
583+
let dominantDirection = null;
584+
if (info.irradiance?.irradianceTexture?.dominantDirection) {
585+
dominantDirection = Vector3.FromArray(info.irradiance.irradianceTexture.dominantDirection);
586+
}
587+
promises.push(UploadIrradianceLevelsAsync(texture, irradianceImageData, irradianceTexture.size, info.imageType, dominantDirection));
584588
}
585589

586590
return Promise.all(promises);
@@ -679,20 +683,22 @@ export async function UploadRadianceLevelsAsync(texture: InternalTexture, imageD
679683
* @param imageData defines the array buffer views of image data [mipmap][face]
680684
* @param size defines the size of the texture faces
681685
* @param imageType the mime type of the image data
686+
* @param dominantDirection the dominant direction of light in the environment texture, if available
682687
* @returns a promise
683688
*/
684689
export async function UploadIrradianceLevelsAsync(
685690
mainTexture: InternalTexture,
686691
imageData: ArrayBufferView[],
687692
size: number,
688-
imageType: string = DefaultEnvironmentTextureImageType
693+
imageType: string = DefaultEnvironmentTextureImageType,
694+
dominantDirection: Nullable<Vector3> = null
689695
): Promise<void> {
690696
// Gets everything ready.
691697
const engine = mainTexture.getEngine() as Engine;
692698
const texture = new InternalTexture(engine, InternalTextureSource.RenderTarget);
693699
const baseTexture = new BaseTexture(engine, texture);
694700
mainTexture._irradianceTexture = baseTexture;
695-
701+
baseTexture._dominantDirection = dominantDirection;
696702
texture.isCube = true;
697703
texture.format = Constants.TEXTUREFORMAT_RGBA;
698704
texture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;
@@ -1076,6 +1082,7 @@ export const EnvironmentTextureTools = {
10761082
* @param texture defines the internal texture to upload to
10771083
* @param imageData defines the array buffer views of image data [mipmap][face]
10781084
* @param imageType the mime type of the image data
1085+
* @param dominantDirection the dominant direction of light in the environment texture, if available
10791086
* @returns a promise
10801087
*/
10811088
UploadIrradianceLevelsAsync,

0 commit comments

Comments
 (0)