@@ -24,20 +24,16 @@ import { GBufferDebug } from "../enums/GBufferDebug.js";
2424export class BufferDebugPass extends Pass < BufferDebugMaterial > {
2525
2626 /**
27- * The size of each texture view relative to the screen size.
28- *
29- * @defaultValue 0.1
27+ * @see {@link viewSize }
3028 */
3129
32- viewSize : number ;
30+ private _viewSize : number ;
3331
3432 /**
35- * Limits the amount of texture views per row.
36- *
37- * @defaultValue 4
33+ * @see {@link columns }
3834 */
3935
40- columns : number ;
36+ private _columns : number ;
4137
4238 /**
4339 * @see {@link bufferFocus }
@@ -66,7 +62,7 @@ export class BufferDebugPass extends Pass<BufferDebugMaterial> {
6662 /**
6763 * Constructs a new buffer debug pass.
6864 *
69- * @param gBufferComponents - G-Buffer components that should be rendered and visualized.
65+ * @param gBufferComponents - G-Buffer components that should be visualized.
7066 */
7167
7268 constructor ( gBufferComponents ?: Set < GBuffer > ) {
@@ -76,10 +72,11 @@ export class BufferDebugPass extends Pass<BufferDebugMaterial> {
7672 this . output . defaultBuffer = this . createFramebuffer ( ) ;
7773 this . fullscreenMaterial = new BufferDebugMaterial ( ) ;
7874
79- this . viewSize = 0.1 ;
80- this . columns = 4 ;
81- this . views = [ ] ;
75+ this . _viewSize = 0.1 ;
76+ this . _columns = 3 ;
8277 this . _bufferFocus = null ;
78+
79+ this . views = [ ] ;
8380 this . debugScene = new Scene ( ) ;
8481 this . debugCamera = new OrthographicCamera ( - 1 , 1 , 1 , - 1 , 0 , 1 ) ;
8582
@@ -95,6 +92,48 @@ export class BufferDebugPass extends Pass<BufferDebugMaterial> {
9592
9693 }
9794
95+ /**
96+ * The size of each texture view relative to the screen size.
97+ *
98+ * Set to `0.0` to disable the buffer preview.
99+ *
100+ * @defaultValue 0.1
101+ */
102+
103+ get viewSize ( ) : number {
104+
105+ return this . _viewSize ;
106+
107+ }
108+
109+ set viewSize ( value : number ) {
110+
111+ this . _viewSize = value ;
112+ this . updateViews ( ) ;
113+
114+ }
115+
116+ /**
117+ * Limits the amount of texture views per row.
118+ *
119+ * Set to `0` to disable the buffer preview.
120+ *
121+ * @defaultValue 3
122+ */
123+
124+ get columns ( ) : number {
125+
126+ return this . _columns ;
127+
128+ }
129+
130+ set columns ( value : number ) {
131+
132+ this . _columns = value ;
133+ this . updateViews ( ) ;
134+
135+ }
136+
98137 /**
99138 * The name of the buffer that should be rendered in fullscreen mode.
100139 *
@@ -103,6 +142,7 @@ export class BufferDebugPass extends Pass<BufferDebugMaterial> {
103142 *
104143 * @see {@link GBuffer } for rendering specific G-Buffer components.
105144 * @see {@link GBufferDebug } for computed G-Buffer components.
145+ * @defaultValue null
106146 */
107147
108148 get bufferFocus ( ) : string | null {
@@ -148,18 +188,26 @@ export class BufferDebugPass extends Pass<BufferDebugMaterial> {
148188 private updateViews ( ) : void {
149189
150190 const { width, height } = this . resolution ;
151- const size = Math . min ( Math . max ( this . viewSize , 0.0 ) , 1.0 ) ;
152- const columns = Math . max ( this . columns , 0 ) ;
153191 const views = this . views ;
154- const rows = Math . ceil ( views . length / columns ) ;
155192
156- if ( views . length * size > 1.0 || ( views . length / rows ) * size > 1.0 ) {
193+ for ( const view of views ) {
194+
195+ view . visible = false ;
196+
197+ }
198+
199+ if ( this . viewSize <= 0.0 || this . columns <= 0 ) {
157200
158- console . warn ( "Unable to fit texture views" ) ;
159201 return ;
160202
161203 }
162204
205+ const columns = Math . min ( this . columns , views . length ) ;
206+ const rows = Math . ceil ( views . length / columns ) ;
207+ const maxViewHeight = 1.0 / rows ;
208+ const maxViewWidth = 1.0 / columns ;
209+ const size = Math . min ( this . viewSize , maxViewHeight , maxViewWidth ) ;
210+
163211 const sizeHalf = size * 0.5 ;
164212 const viewSizeX = size * width ;
165213 const viewSizeY = size * height ;
@@ -176,6 +224,7 @@ export class BufferDebugPass extends Pass<BufferDebugMaterial> {
176224 this . debugScene . add ( view ) ;
177225 view . scale . set ( viewSizeX , viewSizeY , 1 ) ;
178226 view . position . set ( offsetX , offsetY , 0 ) ;
227+ view . visible = true ;
179228 offsetX -= viewSizeX ;
180229
181230 }
0 commit comments