Skip to content

Commit 64a25dd

Browse files
authored
added realistic shading support for image rendering (#28448)
1 parent d34df93 commit 64a25dd

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

editor/js/Sidebar.Project.Image.js

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as THREE from 'three';
22

33
import { UIBreak, UIButton, UIInteger, UIPanel, UIRow, UISelect, UIText } from './libs/ui.js';
44

5-
// import { ViewportPathtracer } from './Viewport.Pathtracer.js';
5+
import { ViewportPathtracer } from './Viewport.Pathtracer.js';
66

77
function SidebarProjectImage( editor ) {
88

@@ -19,17 +19,34 @@ function SidebarProjectImage( editor ) {
1919
// Shading
2020

2121
const shadingRow = new UIRow();
22-
// container.add( shadingRow );
22+
container.add( shadingRow );
2323

2424
shadingRow.add( new UIText( strings.getKey( 'sidebar/project/shading' ) ).setClass( 'Label' ) );
2525

2626
const shadingTypeSelect = new UISelect().setOptions( {
27-
0: 'Solid',
28-
1: 'Realistic'
29-
} ).setWidth( '125px' );
30-
shadingTypeSelect.setValue( 0 );
27+
0: 'SOLID / WebGLRenderer',
28+
1: 'REALISTIC / WebGLPathTracer'
29+
} ).setWidth( '170px' ).setTextTransform( 'unset' ).onChange( refreshShadingRow ).setValue( 0 );
3130
shadingRow.add( shadingTypeSelect );
3231

32+
const pathTracerMinSamples = 3;
33+
const pathTracerMaxSamples = 65536;
34+
const samplesNumber = new UIInteger( 16 ).setRange( pathTracerMinSamples, pathTracerMaxSamples );
35+
36+
const samplesRow = new UIRow();
37+
samplesRow.add( new UIText( 'Sample Count' ).setClass( 'Label' ) ); // TODO: l10n
38+
samplesRow.add( samplesNumber );
39+
40+
container.add( samplesRow );
41+
42+
function refreshShadingRow() {
43+
44+
samplesRow.setHidden( shadingTypeSelect.getValue() !== '1' );
45+
46+
}
47+
48+
refreshShadingRow();
49+
3350
// Resolution
3451

3552
const resolutionRow = new UIRow();
@@ -108,7 +125,7 @@ function SidebarProjectImage( editor ) {
108125
renderer.dispose();
109126

110127
break;
111-
/*
128+
112129
case 1: // REALISTIC
113130

114131
const status = document.createElement( 'div' );
@@ -120,26 +137,41 @@ function SidebarProjectImage( editor ) {
120137
status.style.fontSize = '12px';
121138
output.document.body.appendChild( status );
122139

123-
const pathtracer = new ViewportPathtracer( renderer );
124-
pathtracer.init( scene, camera );
125-
pathtracer.setSize( imageWidth.getValue(), imageHeight.getValue());
140+
const pathTracer = new ViewportPathtracer( renderer );
141+
pathTracer.init( scene, camera );
142+
pathTracer.setSize( imageWidth.getValue(), imageHeight.getValue() );
143+
144+
const maxSamples = Math.max( pathTracerMinSamples, Math.min( pathTracerMaxSamples, samplesNumber.getValue() ) );
126145

127146
function animate() {
128147

129148
if ( output.closed === true ) return;
130149

131-
requestAnimationFrame( animate );
150+
const samples = Math.floor( pathTracer.getSamples() ) + 1;
151+
152+
if ( samples < maxSamples ) {
153+
154+
requestAnimationFrame( animate );
155+
156+
}
157+
158+
pathTracer.update();
159+
160+
const progress = Math.floor( samples / maxSamples * 100 );
161+
162+
status.textContent = `${ samples } / ${ maxSamples } ( ${ progress }% )`;
163+
164+
if ( progress === 100 ) {
132165

133-
pathtracer.update();
166+
status.textContent += ' ✓';
134167

135-
// status.textContent = Math.floor( samples );
168+
}
136169

137170
}
138171

139172
animate();
140173

141174
break;
142-
*/
143175

144176
}
145177

editor/js/Viewport.Pathtracer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,23 @@ function ViewportPathtracer( renderer ) {
6767

6868
}
6969

70+
function getSamples() {
71+
72+
if ( pathTracer === null ) return;
73+
74+
return pathTracer.samples;
75+
76+
}
77+
7078
return {
7179
init: init,
7280
setSize: setSize,
7381
setBackground: setBackground,
7482
setEnvironment: setEnvironment,
7583
updateMaterials: updateMaterials,
7684
update: update,
77-
reset: reset
85+
reset: reset,
86+
getSamples: getSamples
7887
};
7988

8089
}

0 commit comments

Comments
 (0)