Skip to content

Commit

Permalink
rewok and extend
Browse files Browse the repository at this point in the history
  • Loading branch information
aardgoose committed Oct 28, 2023
1 parent 4781365 commit 94a572c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 28 deletions.
3 changes: 2 additions & 1 deletion build/three.module.min.js

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class Renderer {

//

const startTime = performance.now();
this.backend.beginRender( renderContext );

// process render lists
Expand All @@ -342,6 +343,9 @@ class Renderer {

sceneRef.onAfterRender( this, scene, camera, renderTarget );

console.log( this.info.render.drawCalls, 'elapsed:', performance.now() - startTime );
this.sortObjects = scene.static === false;

}

getActiveCubeFace() {
Expand Down Expand Up @@ -904,6 +908,7 @@ class Renderer {

_renderObjectDirect( object, material, scene, camera, lightsNode, passId ) {

const renderContext = this._currentRenderContext;
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, passId );

//
Expand All @@ -912,15 +917,18 @@ class Renderer {

//

const updateGeometery = renderContext.static === false ? true : renderContext.static.skipGeometry !== true;
const updateNodes = renderContext.static === false ? true : renderContext.static.skipNodes !== true;

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable updateNodes.

object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
object.normalMatrix.getNormalMatrix( object.modelViewMatrix );

//

this._nodes.updateForRender( renderObject );
this._geometries.updateForRender( renderObject );
if ( updateGeometery ) this._geometries.updateForRender( renderObject );
this._bindings.updateForRender( renderObject );
this._pipelines.updateForRender( renderObject );
if ( renderContext.static === false ) this._pipelines.updateForRender( renderObject );

//

Expand Down
55 changes: 35 additions & 20 deletions examples/jsm/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class WebGPUBackend extends Backend {
this.textureUtils = new WebGPUTextureUtils( this );
this.occludedResolveCache = new Map();

this.createSnapshotBundle = false;
this.snapshotRenderBundles = null;

}

async init( renderer ) {
Expand Down Expand Up @@ -138,13 +135,27 @@ class WebGPUBackend extends Backend {

beginRender( renderContext ) {

if ( this.createSnapshotBundle ) {
const renderContextData = this.get( renderContext );

return this._beginCreateSnapshot( renderContext );
if ( renderContext.static ) {

}
if ( ! renderContextData.staticRenderBundlesCreated ) {

const renderContextData = this.get( renderContext );
return this._beginCreateRenderBundles( renderContext );

}

} else {

if ( renderContextData.staticRenderBundlesCreated ) {

renderContextData.staticRenderBundlesCreated = false;
renderContextData.renderBundles = null;
renderContextData.bundleDescriptor = null;

}

}

const device = this.device;
const occlusionQueryCount = renderContext.occlusionQueryCount;
Expand Down Expand Up @@ -378,11 +389,10 @@ class WebGPUBackend extends Backend {

}

if ( this.createSnapshotBundle ) {

this.createSnapshotBundle = false;
if ( renderContext.static && ! renderContextData.staticRenderBundlesCreated ) {

this.snapshotRenderBundles = [ renderContextData.currentPass.finish() ];
renderContextData.renderBundles = [ renderContextData.currentPass.finish() ];
renderContextData.staticRenderBundlesCreated = true;

// start real pass

Expand All @@ -391,9 +401,9 @@ class WebGPUBackend extends Backend {

}

if ( this.snapshotRenderBundles !== null ) {
if ( renderContextData.staticRenderBundlesCreated ) {

renderContextData.currentPass.executeBundles( this.snapshotRenderBundles );
renderContextData.currentPass.executeBundles( renderContextData.renderBundles );

}

Expand Down Expand Up @@ -634,12 +644,12 @@ class WebGPUBackend extends Backend {

draw( renderObject, info ) {

if ( this.snapshotRenderBundles !== null ) return;

const { object, geometry, context, pipeline } = renderObject;
const contextData = this.get( context );

if ( contextData.staticRenderBundlesCreated ) return;

const bindingsData = this.get( renderObject.getBindings() );
const contextData = this.get( context );
const pipelineGPU = this.get( pipeline ).pipeline;
const currentSets = contextData.currentSets;

Expand Down Expand Up @@ -1110,15 +1120,20 @@ class WebGPUBackend extends Backend {

}

_beginCreateSnapshot( renderContext ) {
_beginCreateRenderBundles( renderContext ) {

const renderContextData = this.get( renderContext );

renderContextData.currentPass = this.device.createRenderBundleEncoder( {
const descriptor = {
colorFormats: [ GPUTextureFormat.BGRA8Unorm ],
depthStencilFormat: this._getDepthBufferGPU( renderContext ).format,
sampleCount: this.parameters.sampleCount
} );
sampleCount: this.parameters.sampleCount,
// depthReadOnly: false,
// stencilReadOnly: false
};

renderContextData.currentPass = this.device.createRenderBundleEncoder( descriptor );
renderContextData.bundleDescriptor = descriptor;

renderContextData.currentSets = { attributes: {} };

Expand Down
39 changes: 34 additions & 5 deletions examples/webgpu_sprites.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import * as THREE from 'three';
import { texture, uv, userData, rangeFog, color, SpriteNodeMaterial } from 'three/nodes';

import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import WebGPU from 'three/addons/capabilities/WebGPU.js';
import WebGL from 'three/addons/capabilities/WebGL.js';

Expand All @@ -39,6 +40,8 @@

let imageWidth = 1, imageHeight = 1;

let amount = 8000;

init();

function init() {
Expand All @@ -60,9 +63,11 @@
scene = new THREE.Scene();
scene.fogNode = rangeFog( color( 0x0000ff ), 1500, 2100 );

// enable static mode
scene.false = true;

// create sprites

const amount = 200;
const radius = 500;

const textureLoader = new THREE.TextureLoader();
Expand Down Expand Up @@ -115,6 +120,8 @@

window.addEventListener( 'resize', onWindowResize );

initGui();

}

function onWindowResize() {
Expand All @@ -138,19 +145,41 @@
const sprite = group.children[ i ];
const scale = Math.sin( time + sprite.position.x * 0.01 ) * 0.3 + 1.0;

sprite.userData.rotation += 0.1 * ( i / l );
sprite.userData.rotation += 0.01 * ( i / l );
sprite.scale.set( scale * imageWidth, scale * imageHeight, 1.0 );

}

group.rotation.x = time * 0.5;
group.rotation.y = time * 0.75;
group.rotation.z = time * 1.0;
group.rotation.x = time * 0.05;
group.rotation.y = time * 0.075;
group.rotation.z = time * 0.1;

renderer.render( scene, camera );

}

function initGui() {

const gui = new GUI();

const param = {
'static': false,
};


const staticConfig = {
skipGeometry: true,
skipNodes: true
};

gui.add( param, 'static' ).onChange( function ( val ) {

scene.static = val ? staticConfig : false;

} );

}

</script>
</body>
</html>

0 comments on commit 94a572c

Please sign in to comment.