Commit 6230d39e authored by Laureline Nevin's avatar Laureline Nevin ⌨️
Browse files

First version of the export window renderer

parent 9904fb87
Loading
Loading
Loading
Loading
+1 −1
Changes for index.html: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@
            <label for="button-reset-controls" v-t="controls.reset"></label>
        </span>
        <span v-show="phase === 'render'">
            <button id="button-export" class="btn-dark btn-icon" @click="fn.exportImage" v-icon="export"></button>
            <button id="button-export" class="btn-dark btn-icon" @click="fn.setExportMode" v-icon="export"></button>
            <label for="button-export" v-t="export.button"></label>
        </span>
        <div class="description-container">
+9 −1
Changes for src/app.ts: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import {
    RelightProgram,
    RenderData,
    resizeCanvasToDisplaySize,
    ExportRectProgram,
    WebGLCanvasRenderingContext,
} from './gl-program.ts';
import { ControlUpdateEvent, getStateDefaults, LIGHT_ANGLE_DEFAULTS, State } from './control.ts';
@@ -32,6 +33,7 @@ export class App {
    private readonly programs: {
        readonly relight: RelightProgram;
        readonly lightball: LightballProgram;
        readonly export: ExportRectProgram;
    };
    public readonly state: State;
    public readonly i18n: I18n;
@@ -75,6 +77,7 @@ export class App {
        this.programs = {
            relight: new RelightProgram(this.gls.relight),
            lightball: new LightballProgram(this.gls.lightball),
            export: new ExportRectProgram(this.gls.relight),
        };

        this.rx = reactive(this.DEFAULT_RX_STATE);
@@ -404,11 +407,12 @@ export class App {
        this.renderRequested = false;
        let output = `Rendered at ${Date.now()}\n`;

        if (this.source && this.rx.phase === 'render') {
        if (this.source && (this.rx.phase === 'render' || this.rx.phase === 'export')) {
            const exportedState = exportValues(this.state);
            let data: RenderData = {
                ...exportedState,
                lightSource: getLightSourceVec(exportedState),
                exportParams: this.rx.phase === 'export' ? this.rx.raw().exportParams : null
            };

            let join = [...data.lightSource].map((v) => roundTo(v)).join(', ');
@@ -420,6 +424,8 @@ export class App {

            output += '\n' + this.programs.relight.renderSource(this.source, data);
            output += '\n' + this.programs.lightball.render(data);
            if (data.exportParams)
                output += '\n' + this.programs.export.render(data);
        } else {
            this.programs.relight.clearCanvas();
        }
@@ -634,6 +640,7 @@ export class App {
        if (this.rx.exportParams.size[0] === 0 || this.rx.exportParams.size[1] === 0) {
            this.setExportParams();
        }
        this.requestRender();
    }

    private setExportParams(from?: 'view' | 'full' | 'auto') {
@@ -682,6 +689,7 @@ export class App {
                    const data: ExportWorkerData = {
                        ...exportedState,
                        lightSource: getLightSourceVec(exportedState),
                        exportParams: null,
                        dataset,
                    };
                    worker.onmessage = (m: MessageEvent<ExportWorkerResult>) => {
+170 −102

File changed.

Preview size limit exceeded, changes collapsed.

+27 −0
Changes for src/shaders/exportRect.frag: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
precision mediump float;

uniform mediump vec4 uColor;
uniform mediump vec2 uParameters;
uniform mediump vec4 uExportRect;

varying mediump vec2 vPosition;
varying mediump vec2 vVertexCoord;

void main(void) {
    float cornerRadius = uParameters.x, lineWidth = uParameters.y;
    vec2 pos = vPosition; // Shorthand for readability
    vec2 recP = uExportRect.xy;
    vec2 recS = uExportRect.zw;
    float left = recP.x - pos.x, right = pos.x - recP.x - recS.x,
    top = recP.y - pos.y, bottom = pos.y - recP.y - recS.y;
    if ((left > 0. && left < lineWidth) ||
    (right > 0. && right < lineWidth) ||
    (top > 0. && top < lineWidth) ||
    (bottom > 0. && bottom < lineWidth)) {
        gl_FragColor = uColor;
    } else if (pos.x > recP.x && pos.y > recP.y && pos.x < recP.x + recS.x && pos.y < recP.y + recS.y) {
        discard;
    } else {
        gl_FragColor = vec4(0., 0., 0., mod((pos.x + pos.y) / lineWidth / 2., 2.) > 1. ? .2 : .1);
    }
}
 No newline at end of file
+12 −0
Changes for src/shaders/exportRect.vert: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
uniform mat4 uProjectionMatrix;

attribute vec4 aVertexPosition;

varying mediump vec2 vPosition;
varying mediump vec2 vVertexCoord;

void main(void) {
    gl_Position = uProjectionMatrix * aVertexPosition;
    vPosition = aVertexPosition.xy;
    vVertexCoord = aVertexPosition.xy;
}
 No newline at end of file
Loading