Skip to content

Commit

Permalink
Fix orientation of cubemap sample, add clearer attribution
Browse files Browse the repository at this point in the history
Fixes 341
  • Loading branch information
kainino0x committed May 25, 2024
1 parent dab5cb6 commit 029573d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions public/assets/img/cubemap/credit.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion sample/cubemap/meta.ts
Original file line number Diff line number Diff line change
@@ -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' },
Expand Down
8 changes: 6 additions & 2 deletions sample/cubemap/sampleCubemap.frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 029573d

Please sign in to comment.