Skip to content

Commit bf7948f

Browse files
authored
Fix orientation of cubemap sample, add clearer attribution (#419)
1 parent dab5cb6 commit bf7948f

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cubemap image available under a Creative Commons Attribution 3.0 Unported License at https://www.humus.name/index.php?page=Textures&ID=58

sample/cubemap/meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default {
22
name: 'Cubemap',
33
description:
4-
'This example shows how to render and sample from a cubemap texture.',
4+
'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',
55
filename: __DIRNAME__,
66
sources: [
77
{ path: 'main.ts' },

sample/cubemap/sampleCubemap.frag.wgsl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ fn main(
77
@location(1) fragPosition: vec4f
88
) -> @location(0) vec4f {
99
// Our camera and the skybox cube are both centered at (0, 0, 0)
10-
// so we can use the cube geomtry position to get viewing vector to sample the cube texture.
11-
// The magnitude of the vector doesn't matter.
10+
// so we can use the cube geometry position to get viewing vector to sample
11+
// the cube texture. The magnitude of the vector doesn't matter.
1212
var cubemapVec = fragPosition.xyz - vec3(0.5);
13+
// When viewed from the inside, cubemaps are left-handed (z away from viewer),
14+
// but common camera matrix convention results in a right-handed world space
15+
// (z toward viewer), so we have to flip it.
16+
cubemapVec.z *= -1;
1317
return textureSample(myTexture, mySampler, cubemapVec);
1418
}

0 commit comments

Comments
 (0)