Skip to content

Commit 65abfad

Browse files
s-rigaudSamuel Rigaud
andauthored
AsciiEffect: remove noise from black texture (#31858)
* AsciiEffect: remove noise from black texture * use Math.round instead --------- Co-authored-by: Samuel Rigaud <[email protected]>
1 parent 8c698fb commit 65abfad

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

examples/jsm/effects/AsciiEffect.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AsciiEffect {
1818

1919
// ' .,:;=|iI+hHOE#`$';
2020
// darker bolder character set from https://github.com/saw/Canvas-ASCII-Art/
21-
// ' .\'`^",:;Il!i~+_-?][}{1)(|/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$'.split('');
21+
// ' .\'`^",:;Il!i~+_-?][}{1)(|/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$'
2222

2323
// Some ASCII settings
2424

@@ -218,6 +218,8 @@ class AsciiEffect {
218218
// Coloring loop starts now
219219
let strChars = '';
220220

221+
const maxIdx = aCharList.length - 1;
222+
221223
// console.time('rendering');
222224

223225
for ( let y = 0; y < iHeight; y += 2 ) {
@@ -230,13 +232,11 @@ class AsciiEffect {
230232
const iGreen = oImgData[ iOffset + 1 ];
231233
const iBlue = oImgData[ iOffset + 2 ];
232234
const iAlpha = oImgData[ iOffset + 3 ];
233-
let iCharIdx;
234-
235-
let fBrightness;
236235

237-
fBrightness = ( 0.3 * iRed + 0.59 * iGreen + 0.11 * iBlue ) / 255;
236+
let fBrightness = ( 0.3 * iRed + 0.59 * iGreen + 0.11 * iBlue ) / 255;
238237
// fBrightness = (0.3*iRed + 0.5*iGreen + 0.3*iBlue) / 255;
239238

239+
240240
if ( iAlpha == 0 ) {
241241

242242
// should calculate alpha instead, but quick hack :)
@@ -245,11 +245,11 @@ class AsciiEffect {
245245

246246
}
247247

248-
iCharIdx = Math.floor( ( 1 - fBrightness ) * ( aCharList.length - 1 ) );
248+
let iCharIdx = Math.round( ( 1 - fBrightness ) * maxIdx );
249249

250250
if ( bInvert ) {
251251

252-
iCharIdx = aCharList.length - iCharIdx - 1;
252+
iCharIdx = maxIdx - iCharIdx;
253253

254254
}
255255

0 commit comments

Comments
 (0)