From bf7948f4d24bf64c0b15dd05c78aafcd09abb51b Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Wed, 29 May 2024 09:47:59 -0700 Subject: [PATCH] Fix orientation of cubemap sample, add clearer attribution (#419) --- public/assets/img/cubemap/credit.txt | 1 + sample/cubemap/meta.ts | 2 +- sample/cubemap/sampleCubemap.frag.wgsl | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 public/assets/img/cubemap/credit.txt diff --git a/public/assets/img/cubemap/credit.txt b/public/assets/img/cubemap/credit.txt new file mode 100644 index 00000000..de98f1c6 --- /dev/null +++ b/public/assets/img/cubemap/credit.txt @@ -0,0 +1 @@ +Cubemap image available under a Creative Commons Attribution 3.0 Unported License at https://www.humus.name/index.php?page=Textures&ID=58 diff --git a/sample/cubemap/meta.ts b/sample/cubemap/meta.ts index 91f5b56a..ab2dcdda 100644 --- a/sample/cubemap/meta.ts +++ b/sample/cubemap/meta.ts @@ -1,7 +1,7 @@ export default { name: 'Cubemap', description: - 'This example shows how to render and sample from a cubemap texture.', + 'This example shows how to render and sample from a cubemap texture. Cubemap image available under a Creative Commons Attribution 3.0 Unported License at https://www.humus.name/index.php?page=Textures&ID=58', filename: __DIRNAME__, sources: [ { path: 'main.ts' }, diff --git a/sample/cubemap/sampleCubemap.frag.wgsl b/sample/cubemap/sampleCubemap.frag.wgsl index 757b42d0..1e04597c 100644 --- a/sample/cubemap/sampleCubemap.frag.wgsl +++ b/sample/cubemap/sampleCubemap.frag.wgsl @@ -7,8 +7,12 @@ fn main( @location(1) fragPosition: vec4f ) -> @location(0) vec4f { // Our camera and the skybox cube are both centered at (0, 0, 0) - // so we can use the cube geomtry position to get viewing vector to sample the cube texture. - // The magnitude of the vector doesn't matter. + // so we can use the cube geometry position to get viewing vector to sample + // the cube texture. The magnitude of the vector doesn't matter. var cubemapVec = fragPosition.xyz - vec3(0.5); + // When viewed from the inside, cubemaps are left-handed (z away from viewer), + // but common camera matrix convention results in a right-handed world space + // (z toward viewer), so we have to flip it. + cubemapVec.z *= -1; return textureSample(myTexture, mySampler, cubemapVec); }