Skip to content

Commit

Permalink
feat(examples): add pixel-normal-map demo
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 8, 2022
1 parent e67c110 commit 72c604a
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 0 deletions.
Binary file added assets/examples/pixel-normal-map.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions examples/pixel-normal-map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# pixel-normal-map

![screenshot](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-normal-map.png)

[Live demo](http://demo.thi.ng/umbrella/pixel-normal-map/)

Please refer to the [example build instructions](https://github.com/thi-ng/umbrella/wiki/Example-build-instructions) on the wiki.

## Authors

- Karsten Schmidt

## License

© 2022 Karsten Schmidt // Apache Software License 2.0
34 changes: 34 additions & 0 deletions examples/pixel-normal-map/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link
rel="icon"
href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">⛱️</text></svg>'
/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>pixel-normal-map · @thi.ng/umbrella</title>
<link
href="https://unpkg.com/tachyons@4/css/tachyons.min.css"
rel="stylesheet"
/>
<style>
img,
canvas {
display: block;
}
</style>
</head>
<body class="sans-serif">
<div id="app"></div>
<div>
<a
class="link"
href="https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-normal-map"
>Source code</a
>
</div>
<script type="module" src="/src/index.ts"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions examples/pixel-normal-map/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@example/pixel-normal-map",
"version": "0.0.1",
"private": true,
"description": "Normal map creation/conversion basics",
"repository": "https://github.com/thi-ng/umbrella",
"author": "Karsten Schmidt <k+npm@thi.ng>",
"license": "Apache-2.0",
"scripts": {
"start": "vite --open",
"build": "tsc && vite build --base='./'",
"preview": "vite preview --host --open"
},
"devDependencies": {
"typescript": "^4.8.3",
"vite": "^3.1.3"
},
"dependencies": {
"@thi.ng/pixel": "workspace:^"
},
"browser": {
"process": false
},
"thi.ng": {
"readme": true,
"screenshot": "examples/pixel-normal-map.jpg"
}
}
27 changes: 27 additions & 0 deletions examples/pixel-normal-map/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
canvas2d,
floatBufferFromImage,
FLOAT_GRAY,
imagePromise,
normalMap,
} from "@thi.ng/pixel";
import TEX from "./tex.png";

(async () => {
// load texture image
const img = await imagePromise(TEX);
document.body.appendChild(img);
// convert image to grayscale float buffer
const buf = floatBufferFromImage(img, FLOAT_GRAY);
// compute normalmap w/ given options
const nmap = normalMap(buf, { scale: 8, step: 2 });
// create canvas and convert/copy normal map into it
nmap.blitCanvas(canvas2d(img.width, img.height, document.body).canvas);
// another normal map with sign of `scale` flipped to "invert" normal direction
const nmap2 = normalMap(buf, { scale: -8, step: 2 });
nmap2.blitCanvas(canvas2d(img.width, img.height, document.body).canvas);

// if a result canvas isn't needed, converting to JS native ImageData
// might be sufficient (e.g. for WebGL textures):
// const idata = nmap.toImageData()
})();
Binary file added examples/pixel-normal-map/src/tex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/pixel-normal-map/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
6 changes: 6 additions & 0 deletions examples/pixel-normal-map/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"include": ["src/**/*"],
"compilerOptions": {
}
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,16 @@ __metadata:
languageName: unknown
linkType: soft

"@example/pixel-normal-map@workspace:examples/pixel-normal-map":
version: 0.0.0-use.local
resolution: "@example/pixel-normal-map@workspace:examples/pixel-normal-map"
dependencies:
"@thi.ng/pixel": "workspace:^"
typescript: ^4.8.3
vite: ^3.1.3
languageName: unknown
linkType: soft

"@example/pixel-sorting@workspace:examples/pixel-sorting":
version: 0.0.0-use.local
resolution: "@example/pixel-sorting@workspace:examples/pixel-sorting"
Expand Down

0 comments on commit 72c604a

Please sign in to comment.