MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / _renderHalftone

Method _renderHalftone

src/tools/texture-lab/renderer.js:533–584  ·  view source on GitHub ↗
(params, inputTexture, width, height, flipY = 1.0, renderScale = 1.0)

Source from the content-addressed store, hash-verified

531 }
532
533 _renderHalftone(params, inputTexture, width, height, flipY = 1.0, renderScale = 1.0) {
534 const gl = this.gl;
535 const program = this.programs.halftone;
536
537 this._useProgram(program, flipY);
538
539 gl.activeTexture(gl.TEXTURE0);
540 gl.bindTexture(gl.TEXTURE_2D, inputTexture);
541
542 const dotColor = this._hexToRgb(params.dotColor || '#000000');
543 const bgColor = this._hexToRgb(params.backgroundColor || '#ffffff');
544
545 // Map shape to int
546 const shapeMap = {
547 circle: 0,
548 square: 1,
549 diamond: 2,
550 line: 3,
551 ellipse: 4,
552 cross: 5,
553 ring: 6
554 };
555 const shapeInt = shapeMap[params.shape] || 0;
556
557 // Map color mode to int
558 const colorModeMap = {
559 original: 0,
560 monochrome: 1,
561 duotone: 2,
562 cmyk: 3
563 };
564 const colorModeInt = colorModeMap[params.colorMode] || 0;
565
566 // Scale gridSize proportionally to render resolution so export matches preview
567 const scaledGridSize = (params.gridSize || 8) * renderScale;
568
569 gl.uniform1i(program.uniforms.u_image, 0);
570 gl.uniform1f(program.uniforms.u_gridSize, scaledGridSize);
571 gl.uniform1f(program.uniforms.u_dotScale, params.dotScale || 1.0);
572 gl.uniform1f(program.uniforms.u_angle, params.angle || 45);
573 gl.uniform1i(program.uniforms.u_shape, shapeInt);
574 gl.uniform1f(program.uniforms.u_softness, params.softness || 0.5);
575 gl.uniform1f(program.uniforms.u_contrast, params.contrast || 0);
576 gl.uniform1i(program.uniforms.u_invert, params.invert ? 1 : 0);
577 gl.uniform1i(program.uniforms.u_colorMode, colorModeInt);
578 gl.uniform3f(program.uniforms.u_dotColor, dotColor[0], dotColor[1], dotColor[2]);
579 gl.uniform3f(program.uniforms.u_backgroundColor, bgColor[0], bgColor[1], bgColor[2]);
580 gl.uniform1f(program.uniforms.u_mixOriginal, params.mixOriginal || 0);
581 gl.uniform2f(program.uniforms.u_resolution, width, height);
582
583 gl.drawArrays(gl.TRIANGLES, 0, 6);
584 }
585
586 _renderAscii(params, inputTexture, width, height, flipY = 1.0, renderScale = 1.0) {
587 const gl = this.gl;

Callers 1

_renderEffectMethod · 0.95

Calls 2

_useProgramMethod · 0.95
_hexToRgbMethod · 0.95

Tested by

no test coverage detected