Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: Simpler atmosphere approach in webgpu_compute_birds #29366

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/screenshots/webgpu_compute_birds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 25 additions & 15 deletions examples/webgpu_compute_birds.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<script type="module">

import * as THREE from 'three';
import { uniform, varyingProperty, vec4, max, sin, mat3, uint, negate, cameraProjectionMatrix, cameraViewMatrix, positionLocal, modelWorldMatrix, sqrt, attribute, property, float, storage, storageObject, Fn, If, cos, Loop, Continue, normalize, instanceIndex, length } from 'three/tsl';
import { uniform, varying, vec4, add, sub, max, sin, mat3, uint, negate, cameraProjectionMatrix, cameraViewMatrix, positionLocal, modelWorldMatrix, sqrt, attribute, property, float, storage, storageObject, Fn, If, cos, Loop, Continue, normalize, instanceIndex, length } from 'three/tsl';

import Stats from 'three/addons/libs/stats.module.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
Expand Down Expand Up @@ -92,21 +92,21 @@

// Body
verts_push(
0, - 0, - 20,
0, 4, - 20,
0, 0, - 20,
0, - 8, 10,
0, 0, 30
);

// Wings
verts_push(
0, 0, - 15,
- wingsSpan, 0, 0,
- wingsSpan, 0, 5,
0, 0, 15
);

verts_push(
0, 0, 15,
wingsSpan, 0, 0,
wingsSpan, 0, 5,
0, 0, - 15
);

Expand Down Expand Up @@ -134,22 +134,32 @@
container = document.createElement( 'div' );
document.body.appendChild( container );

camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 3000 );
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 5000 );
camera.position.z = 1000;

scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0xffffff, 500, 3000 );
scene.fog = new THREE.Fog( 0xffffff, 700, 3000 );

// Sky

const light = new THREE.HemisphereLight( 0x0000ff, 0xffbb00, 3 );
light.position.x = - 1;
light.position.z = - 1;
scene.add( light );
const geometry = new THREE.IcosahedronGeometry( 1, 6 );
const material = new THREE.MeshBasicNodeMaterial( {
// Use vertex positions to create atmosphere colors
colorNode: varying(
vec4(
sub( 0.25, positionLocal.y ),
sub( - 0.25, positionLocal.y ),
add( 1.5, positionLocal.y ),
1.0
)
),
side: THREE.BackSide
} );

const geometry = new THREE.IcosahedronGeometry( 1000, 6 );
const material = new THREE.MeshStandardMaterial( { side: THREE.BackSide } );
scene.add( new THREE.Mesh( geometry, material ) );
const mesh = new THREE.Mesh( geometry, material );
mesh.rotation.z = 0.75;
mesh.scale.setScalar( 1000 );
scene.add( mesh );

renderer = new THREE.WebGPURenderer( { antialiasing: true } );
renderer.setPixelRatio( window.devicePixelRatio );
Expand Down Expand Up @@ -223,7 +233,7 @@

const birdGeometry = new BirdGeometry();
const birdMaterial = new THREE.NodeMaterial();

// Animate bird mesh within vertex shader, then apply position offset to vertices.

const birdVertexTSL = Fn( () => {
Expand Down