Skip to content

Instantly share code, notes, and snippets.

View cecilemuller's full-sized avatar

Cecile Muller cecilemuller

View GitHub Profile
@cecilemuller
cecilemuller / plugin.ts
Last active January 28, 2025 16:21
Vite Plugin: apply Prettier to HTML output using `transformIndexHtml`
import type { PluginOption } from "vite";
import { format } from "prettier";
export function plugin(): PluginOption {
return {
name: "example",
transformIndexHtml: async (html) => format(html, {
// https://prettier.io/docs/en/options.html
parser: "html",
htmlWhitespaceSensitivity: "ignore"
@cecilemuller
cecilemuller / plugin.ts
Last active January 28, 2025 16:37
Vite Plugin: emit an asset using `emitFile` and `configureServer`
import type { PluginOption } from "vite";
export function plugin(): PluginOption {
return [
{
apply: "serve",
name: "example-serve",
configureServer(server) {
server.middlewares.use("/subfolder/example.txt", (_req, res) => {
res.appendHeader("Content-Type", "text/plain");
@cecilemuller
cecilemuller / plugin.ts
Last active January 28, 2025 14:46
Vite Plugin: configureServer
import type { PluginOption } from "vite";
export function plugin(): PluginOption {
return {
name: "example",
configureServer(server) {
// Log all requests
server.middlewares.use((req, _res, next) => {
console.log(req.url); // full path
next();
@cecilemuller
cecilemuller / tsconfig.json
Last active January 25, 2025 14:19
Typescript Config
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "esnext",
"module": "nodenext",
"moduleDetection": "force",
"newLine": "LF",
"strict": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
@cecilemuller
cecilemuller / index.html
Created June 17, 2024 16:25
ESM Import Map for NPM-installed packages
<script type="importmap">
{
"imports": {
"lil-gui": "./node_modules/lil-gui/dist/lil-gui.esm.js",
"three": "./node_modules/three/src/Three.js",
"three/addons/": "./node_modules/three/examples/jsm/",
"three/nodes": "./node_modules/three/examples/jsm/nodes/Nodes.js"
}
}
</script>
@cecilemuller
cecilemuller / fresnel.frag
Created June 10, 2024 10:07
Albedo Alpha from Rim for Marmoset Toolbag 4
#include "data/shader/mat/state.frag"
uniform float uOpacity; //name "Opacity" default 1.0 min 0.0 max 2.0
uniform float uExponent; //name "Exponent" default 1.0 min 0.0 max 4.0
void RimOpacity( inout FragmentState s )
{
#ifdef Emissive
Emissive(s);
#endif
@cecilemuller
cecilemuller / imageComplete.mjs
Created June 5, 2024 01:34
Async image complete
function imageComplete(img) {
return new Promise((resolve) => {
if (img.complete) {
resolve();
} else {
img.onerror = img.onload = () => { resolve() };
}
});
}
@cecilemuller
cecilemuller / triplanar.frag
Last active June 3, 2024 23:44
Triplanar Mapping shader for Marmoset Toolbag 4
#include "data/shader/mat/state.frag"
uniform float uScale; //name "Scale" default 1.0 min 0.0 max 5.0
USE_TEXTURE2D(tTexture0);
void TriplanarEmissive( inout FragmentState s )
{
vec3 uvw = fract(s.vertexPosition / 100.0 * uScale);
vec3 blend = abs(s.normal);
@cecilemuller
cecilemuller / neuro.frag
Last active June 10, 2024 09:28
Neuro shader for Marmoset Toolbag 4
#include "data/shader/mat/state.frag"
#include "data/shader/mat/other/customExtras.sh"
uniform int uIterations; //name "Iterations" default 15 min 5 max 30
uniform float uSpeed; //name "Speed" default 1.0 min 0.0 max 10.0
uniform float uFactor; //name "Factor" default 8.0 min 4.0 max 10.0
// Based on https://codepen.io/wildpeaks/pen/gOJmzdo
float neuro(float ratio, vec2 uv, float t) {
mat2 rotate = mat2(0.540302, 0.841470, -0.841470, 0.540302);
@cecilemuller
cecilemuller / crosshatching.frag
Last active June 3, 2024 15:20
Cross-hatching shader for Marmoset Toolbag 4
// Based on http://research.microsoft.com/en-us/um/people/hoppe/hatching.pdf
// and https://github.com/spite/cross-hatching
#include "data/shader/mat/state.frag"
USE_TEXTURE2D(tHatch0);
USE_TEXTURE2D(tHatch1);
USE_TEXTURE2D(tHatch2);
USE_TEXTURE2D(tHatch3);
USE_TEXTURE2D(tHatch4);
USE_TEXTURE2D(tHatch5);