|
|
@@ -24,7 +24,7 @@
|
|
|
<script type="module">
|
|
|
|
|
|
import * as THREE from 'three';
|
|
|
- import { tslFn, texture, uv, uint, positionWorld, modelWorldMatrix, cameraViewMatrix, timerLocal, timerDelta, cameraProjectionMatrix, vec2, instanceIndex, positionGeometry, storage, If } from 'three/tsl';
|
|
|
+ import { tslFn, texture, uv, uint, positionWorld, billboarding, timerLocal, timerDelta, vec2, instanceIndex, positionGeometry, storage, If } from 'three/tsl';
|
|
|
|
|
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
|
|
|
|
@@ -187,34 +187,9 @@
|
|
|
|
|
|
// rain
|
|
|
|
|
|
- const billboarding = tslFn( () => {
|
|
|
-
|
|
|
- const particlePosition = positionBuffer.toAttribute();
|
|
|
-
|
|
|
- const worldMatrix = modelWorldMatrix.toVar();
|
|
|
- worldMatrix[ 3 ][ 0 ] = particlePosition.x;
|
|
|
- worldMatrix[ 3 ][ 1 ] = particlePosition.y;
|
|
|
- worldMatrix[ 3 ][ 2 ] = particlePosition.z;
|
|
|
-
|
|
|
- const modelViewMatrix = cameraViewMatrix.mul( worldMatrix );
|
|
|
- modelViewMatrix[ 0 ][ 0 ] = 1;
|
|
|
- modelViewMatrix[ 0 ][ 1 ] = 0;
|
|
|
- modelViewMatrix[ 0 ][ 2 ] = 0;
|
|
|
-
|
|
|
- //modelViewMatrix[ 0 ][ 0 ] = modelWorldMatrix[ 0 ].length();
|
|
|
- //modelViewMatrix[ 1 ][ 1 ] = modelWorldMatrix[ 1 ].length();
|
|
|
-
|
|
|
- modelViewMatrix[ 2 ][ 0 ] = 0;
|
|
|
- modelViewMatrix[ 2 ][ 1 ] = 0;
|
|
|
- modelViewMatrix[ 2 ][ 2 ] = 1;
|
|
|
-
|
|
|
- return cameraProjectionMatrix.mul( modelViewMatrix ).mul( positionGeometry );
|
|
|
-
|
|
|
- } );
|
|
|
-
|
|
|
const rainMaterial = new THREE.MeshBasicNodeMaterial();
|
|
|
rainMaterial.colorNode = uv().distance( vec2( .5, 0 ) ).oneMinus().mul( 3 ).exp().mul( .1 );
|
|
|
- rainMaterial.vertexNode = billboarding();
|
|
|
+ rainMaterial.vertexNode = billboarding( { position: positionBuffer.toAttribute() } );
|
|
|
rainMaterial.opacity = .2;
|
|
|
rainMaterial.side = THREE.DoubleSide;
|
|
|
rainMaterial.forceSinglePass = true;
|