Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from "astro/config";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import glsl from "vite-plugin-glsl";

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand All @@ -14,6 +15,7 @@ export default defineConfig({
usegl: resolve(__dirname, "./src/index.ts"),
},
},
plugins: [glsl({ minify: true })],
},
devToolbar: {
enabled: false,
Expand Down
17 changes: 8 additions & 9 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
}
".": "./dist/index.js",
"./package.json": "./package.json"
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"build": "tsdown",
"dev": "astro dev --port 3000",
"format": "prettier src --check",
"format:fix": "prettier src --write",
Expand All @@ -42,13 +40,14 @@
"eslint": "9.32.0",
"eslint-config-unjs": "0.5.0",
"prettier": "3.6.2",
"tsdown": "0.14.1",
"typescript": "5.8.3",
"unbuild": "3.6.0"
"vite-plugin-glsl": "1.5.1"
},
"changelog": {
"excludeAuthors": [
""
]
},
"packageManager": "pnpm@10.13.1"
"packageManager": "pnpm@10.14.0"
}
1 change: 1 addition & 0 deletions lib/playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"include": ["../src", "src"],
"compilerOptions": {
"strict": true,
"types": ["vite-plugin-glsl/ext"],
"paths": {
"usegl": ["../src/index.ts"]
}
Expand Down
13 changes: 13 additions & 0 deletions lib/src/effects/bloom/glsl/combine.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
uniform sampler2D uImage;
uniform sampler2D uBloomTexture;
uniform float uMix;

in vec2 vUv;
out vec4 outColor;

void main() {
vec4 baseColor = texture(uImage, vUv);
vec4 bloomColor = texture(uBloomTexture, vUv);

outColor = max(baseColor, mix(baseColor, bloomColor, uMix));
}
15 changes: 0 additions & 15 deletions lib/src/effects/bloom/glsl/combine.frag.ts

This file was deleted.

34 changes: 34 additions & 0 deletions lib/src/effects/bloom/glsl/downsample.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
uniform sampler2D uInputTexture;

in vec2 vUv;
in vec2 vTexelSize;
out vec4 fragColor;

void main() {
vec2 offsets[13] = vec2[](
vec2(-1.0, 1.0), vec2( 1.0, 1.0),
vec2(-1.0, -1.0), vec2( 1.0, -1.0),
vec2(-2.0, 2.0), vec2( 0.0, 2.0), vec2( 2.0, 2.0),
vec2(-2.0, 0.0), vec2( 0.0, 0.0), vec2( 2.0, 0.0),
vec2(-2.0, -2.0), vec2( 0.0, -2.0), vec2( 2.0, -2.0)
);

float weights[13] = float[](
// 4 corners
0.125, 0.125,
0.125, 0.125,
// 9 center
0.0555555, 0.0555555, 0.0555555,
0.0555555, 0.0555555, 0.0555555,
0.0555555, 0.0555555, 0.0555555
);

vec4 color = vec4(0.0);

for (int i = 0; i < 13; i++) {
vec2 sampleUv = vUv + offsets[i] * vTexelSize;
color += weights[i] * texture(uInputTexture, sampleUv);
}

fragColor = color;
}
36 changes: 0 additions & 36 deletions lib/src/effects/bloom/glsl/downsample.frag.ts

This file was deleted.

12 changes: 12 additions & 0 deletions lib/src/effects/bloom/glsl/sample.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
uniform sampler2D uInputTexture;
uniform float uTexelSizeMultiplier;

in vec2 aPosition;
out vec2 vTexelSize;
out vec2 vUv;

void main() {
vTexelSize = uTexelSizeMultiplier / vec2(textureSize(uInputTexture, 0).xy);
vUv = aPosition.xy * 0.5 + 0.5;
gl_Position = vec4(aPosition.xy, 1.0, 1.0);
}
14 changes: 0 additions & 14 deletions lib/src/effects/bloom/glsl/sample.vert.ts

This file was deleted.

34 changes: 34 additions & 0 deletions lib/src/effects/bloom/glsl/upsample.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
uniform sampler2D uCurrentTexture; // Texture at the current (higher) resolution
uniform sampler2D uPreviousTexture; // Texture at the lower (blurrier) resolution
uniform float uRadius; // Interpolation factor

in vec2 vTexelSize;
in vec2 vUv;
out vec4 fragColor;

float clampToBorder(const in vec2 uv) {
return (uv.s >= 0.0 && uv.s <= 1.0 && uv.t >= 0.0 && uv.t <= 1.0) ? 1.0 : 0.5;
}

void main() {
vec2 offsets[9] = vec2[](
vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0),
vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0),
vec2(-1.0, -1.0), vec2( 0.0, -1.0), vec2( 1.0, -1.0)
);
float weights[9] = float[](
0.0625, 0.125, 0.0625,
0.125, 0.25, 0.125,
0.0625, 0.125, 0.0625
);

vec4 prevColor = vec4(0.0);
for (int i = 0; i < 9; i++) {
vec2 sampleUv = vUv + offsets[i] * vTexelSize;
prevColor += weights[i] * clampToBorder(sampleUv) * texture(uPreviousTexture, sampleUv);
}

vec4 currColor = texture(uCurrentTexture, vUv);

fragColor = max(currColor, mix(currColor, prevColor, uRadius));
}
36 changes: 0 additions & 36 deletions lib/src/effects/bloom/glsl/upsample.frag.ts

This file was deleted.

9 changes: 4 additions & 5 deletions lib/src/effects/bloom/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useCompositeEffectPass } from "../../hooks/useCompositeEffectPass";
import { useEffectPass } from "../../hooks/useEffectPass";
import type { EffectPass } from "../../types";

import type { RenderTargetParams } from "../../core/renderTarget";
import { downSampleFragment } from "./glsl/downsample.frag";
import { combineFragment } from "./glsl/combine.frag";
import { sampleVertex } from "./glsl/sample.vert";
import { upsampleFragment } from "./glsl/upsample.frag";
import downSampleFragment from "./glsl/downsample.frag";
import combineFragment from "./glsl/combine.frag";
import sampleVertex from "./glsl/sample.vert";
import upsampleFragment from "./glsl/upsample.frag";

export type BloomParams = {
levels?: number;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/effects/linearToSRGB/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffectPass } from "../../hooks/useEffectPass";
import { linearToSRGBFragment } from "./linearToSRGB.frag";
import linearToSRGBFragment from "./linearToSRGB.frag";

export function linearToSRGB() {
return useEffectPass({
Expand Down
14 changes: 14 additions & 0 deletions lib/src/effects/linearToSRGB/linearToSRGB.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uniform sampler2D uTexture;
varying vec2 vUv;

void main() {
vec4 color = texture(uTexture, vUv);
gl_FragColor = vec4(
mix(
color.rgb * 12.92,
pow(color.rgb, vec3(1.0 / 2.4)) * 1.055 - 0.055,
step(vec3(0.0031308), color.rgb)
),
color.a
);
}
16 changes: 0 additions & 16 deletions lib/src/effects/linearToSRGB/linearToSRGB.frag.ts

This file was deleted.

3 changes: 2 additions & 1 deletion lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"esModuleInterop": true,
"isolatedModules": true,
"strict": true,
"skipLibCheck": true
"skipLibCheck": true,
"types": ["vite-plugin-glsl/ext", "node"]
},
"include": ["src", "playwright.config.ts"]
}
9 changes: 9 additions & 0 deletions lib/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "tsdown";
import glsl from "vite-plugin-glsl";

export default defineConfig({
entry: ["./src/index.ts"],
platform: "browser",
exports: true,
plugins: [glsl({ minify: true })],
});
Loading