From bdb29a8ec7aa893b307ac37da29e82e756ba9be3 Mon Sep 17 00:00:00 2001 From: ycw Date: Sun, 19 May 2024 15:18:43 -0500 Subject: [PATCH] shows pathtracer samples in viewport info --- editor/js/Editor.js | 2 ++ editor/js/Strings.js | 10 +++++++++- editor/js/Viewport.Info.js | 31 +++++++++++++++++++++++++++++++ editor/js/Viewport.Pathtracer.js | 11 ++++++++++- editor/js/Viewport.js | 1 + editor/js/libs/ui.js | 2 ++ 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/editor/js/Editor.js b/editor/js/Editor.js index c7092d35135193..a9c125cc233846 100644 --- a/editor/js/Editor.js +++ b/editor/js/Editor.js @@ -93,6 +93,8 @@ function Editor() { intersectionsDetected: new Signal(), + pathTracerUpdated: new Signal(), + }; this.config = new Config(); diff --git a/editor/js/Strings.js b/editor/js/Strings.js index 3bf7528f27712b..37164773ea76a5 100644 --- a/editor/js/Strings.js +++ b/editor/js/Strings.js @@ -384,10 +384,12 @@ function Strings( config ) { 'viewport/info/oneObject': 'Object', 'viewport/info/oneVertex': 'Vertex', 'viewport/info/oneTriangle': 'Triangle', + 'viewport/info/oneSample': 'Sample', 'viewport/info/objects': 'Objects', 'viewport/info/vertices': 'Vertices', 'viewport/info/triangles': 'Triangles', - 'viewport/info/rendertime': 'Render time' + 'viewport/info/samples': 'Samples', + 'viewport/info/rendertime': 'Render time', }, @@ -771,9 +773,11 @@ function Strings( config ) { 'viewport/info/oneObject': 'Objet', 'viewport/info/oneVertex': 'Sommet', 'viewport/info/oneTriangle': 'Triangle', + 'viewport/info/oneSample': 'Échantillon', 'viewport/info/objects': 'Objets', 'viewport/info/vertices': 'Sommets', 'viewport/info/triangles': 'Triangles', + 'viewport/info/samples': 'Échantillons', 'viewport/info/rendertime': 'Temps de rendu' }, @@ -1158,9 +1162,11 @@ function Strings( config ) { 'viewport/info/oneObject': '物体', 'viewport/info/oneVertex': '顶点', 'viewport/info/oneTriangle': '三角形', + 'viewport/info/oneSample': '样本', 'viewport/info/objects': '物体', 'viewport/info/vertices': '顶点', 'viewport/info/triangles': '三角形', + 'viewport/info/samples': '样本', 'viewport/info/rendertime': '渲染时间' }, @@ -1545,9 +1551,11 @@ function Strings( config ) { 'viewport/info/oneObject': 'オブジェクト', 'viewport/info/oneVertex': '頂点', 'viewport/info/oneTriangle': '三角形', + 'viewport/info/oneSample': 'サンプル', 'viewport/info/objects': 'オブジェクト', 'viewport/info/vertices': '頂点', 'viewport/info/triangles': '三角形', + 'viewport/info/samples': 'サンプル', 'viewport/info/rendertime': 'レンダリング時間' } diff --git a/editor/js/Viewport.Info.js b/editor/js/Viewport.Info.js index 29011b5042df8b..79e651274320d0 100644 --- a/editor/js/Viewport.Info.js +++ b/editor/js/Viewport.Info.js @@ -18,15 +18,18 @@ function ViewportInfo( editor ) { const verticesText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' ); const trianglesText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' ); const frametimeText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' ); + const samplesText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' ).setHidden( true ); const objectsUnitText = new UIText( strings.getKey( 'viewport/info/objects' ) ); const verticesUnitText = new UIText( strings.getKey( 'viewport/info/vertices' ) ); const trianglesUnitText = new UIText( strings.getKey( 'viewport/info/triangles' ) ); + const samplesUnitText = new UIText( strings.getKey( 'viewport/info/samples' ) ).setHidden( true ); container.add( objectsText, objectsUnitText, new UIBreak() ); container.add( verticesText, verticesUnitText, new UIBreak() ); container.add( trianglesText, trianglesUnitText, new UIBreak() ); container.add( frametimeText, new UIText( strings.getKey( 'viewport/info/rendertime' ) ), new UIBreak() ); + container.add( samplesText, samplesUnitText, new UIBreak() ); signals.objectAdded.add( update ); signals.objectRemoved.add( update ); @@ -35,6 +38,10 @@ function ViewportInfo( editor ) { // + const pluralRules = new Intl.PluralRules( editor.config.getKey( 'language' ) ); + + // + function update() { const scene = editor.scene; @@ -98,6 +105,30 @@ function ViewportInfo( editor ) { } + // + + editor.signals.pathTracerUpdated.add( function ( samples ) { + + samples = Math.floor( samples ); + + samplesText.setValue( samples ); + + const samplesStringKey = ( pluralRules.select( samples ) === 'one' ) ? 'viewport/info/oneSample' : 'viewport/info/samples'; + samplesUnitText.setValue( strings.getKey( samplesStringKey ) ); + + } ); + + editor.signals.viewportShadingChanged.add( function () { + + const isRealisticShading = ( editor.viewportShading === 'realistic' ); + + samplesText.setHidden( ! isRealisticShading ); + samplesUnitText.setHidden( ! isRealisticShading ); + + container.setBottom( isRealisticShading ? '32px' : '20px' ); + + } ); + return container; } diff --git a/editor/js/Viewport.Pathtracer.js b/editor/js/Viewport.Pathtracer.js index 63a983967a1978..7e78fd38c6525e 100644 --- a/editor/js/Viewport.Pathtracer.js +++ b/editor/js/Viewport.Pathtracer.js @@ -67,6 +67,14 @@ function ViewportPathtracer( renderer ) { } + function getSamples() { + + if ( pathTracer === null ) return; + + return pathTracer.samples; + + } + return { init: init, setSize: setSize, @@ -74,7 +82,8 @@ function ViewportPathtracer( renderer ) { setEnvironment: setEnvironment, updateMaterials: updateMaterials, update: update, - reset: reset + reset: reset, + getSamples: getSamples }; } diff --git a/editor/js/Viewport.js b/editor/js/Viewport.js index b5db4251fe5b78..5e82fdef66be1f 100644 --- a/editor/js/Viewport.js +++ b/editor/js/Viewport.js @@ -798,6 +798,7 @@ function Viewport( editor ) { if ( editor.viewportShading === 'realistic' ) { pathtracer.update(); + editor.signals.pathTracerUpdated.dispatch( pathtracer.getSamples() ); } diff --git a/editor/js/libs/ui.js b/editor/js/libs/ui.js index a845a31501a18f..54c21a62579993 100644 --- a/editor/js/libs/ui.js +++ b/editor/js/libs/ui.js @@ -114,6 +114,8 @@ class UIElement { this.dom.hidden = isHidden; + return this; + } isHidden() {