Skip to content

Commit b0c734d

Browse files
authored
Doc fixes (#88)
* misc updates to docs and error msgs etc * chore: formatting markdowns
1 parent ba71396 commit b0c734d

9 files changed

+116
-15
lines changed

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ _deprecated
66
*.gltf
77
*.glb
88
*.ktx2
9+
shaderbook
10+
bevy
11+
bevy_shaders
912

1013
# Generated by Cargo
1114
# will have compiled files and executables
@@ -23,9 +26,6 @@ target/
2326
.vscode
2427
.ruff_cache
2528
.pyc
26-
shaderbook
27-
bevy
28-
bevy_shaders
2929
.DS_Store# Byte-compiled / optimized / DLL files
3030
__pycache__/
3131
*.py[cod]

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
## Our [bevy-shader-cheatsheet](bevy-shaders-cheatsheet.md#Contents)
1919

20-
Shadplay is an app designed to help you learn `wgsl` with minimal friction, specifically for those wanting to learn `wgsl` to write shaders for bevy.
21-
The idea is to give one the minimal amount of bevy boilerplate etc., possible to get started writing \`wgsl\` ASAP, and provide a library of examples showing how some things are done, can be done etc.
20+
Shadplay is an app designed to help you learn `wgsl` with minimal friction, specifically for those wanting to learn `wgsl` to write shaders for [Bevy](https://bevyengine.org/).
2221

2322
A secondary goal is to flesh out a relatively comprehensive 'port' of existing cool shader work from places like shadertoy etc -- because there's a few 'gotchas' around the differences in `glsl` and `wgsl` syntax, their respective builtins.
2423

2524
A tertiary goal is to surface the builtins/existing library code that bevy's codebase provides.
2625

26+
You will notice a large swath of the `wgsl` code from the Bevy codebase here, _we_ want it to be available to you and searchable (within your IDE) as, the `lsp` story for `wgsl` is not a great one... _yet_!.
27+
2728
______________________________________________________________________
2829

2930
### Why?
@@ -34,16 +35,16 @@ ______________________________________________________________________
3435

3536
## Features
3637

37-
- A large collection of example shaders illustrating creative and educational uses. `assets/shaders/yourshadergoeshere.wgsl` specifically focusing on `wgsl`.
38+
- A large collection of example shaders illustrating creative and educational uses. `assets/shaders/yourshadergoeshere.wgsl`.
3839
- Live preview of shader code on bevy mesh geometry.
3940
- Textures, see `assets/shaders/howto-texture.wgsl`.
4041
- Drag and drop `.png` or `.jpg` files onto the window to use as said textures.
4142
- Mouse coords over a `uniform`, see `assets/shaders/howto-mouse.wgsl`.
4243
- Colour picker with system copy so that you get an immediate `vecf3(r, g, b)` immediately available for quick pasta action.
43-
- Drag and drop (valid `wgsl`) shaders onto the app.
44-
- Scripts to format your `wgsl` work, so it looks more rusty.
45-
- Scripts to pull _all_ the functions from the bevy codebase's shader code so you can easily lookup what's available for import.
46-
- Scripts to search the bevy source code (opening your browser) for specific keywords.
44+
- Drag and drop (valid `wgsl`) shaders onto the app window to see them working.
45+
- Tips and Tools to format your `wgsl` work, so it looks more rusty (which will help you quickly get up to speed with the existing `wgsl` in the Bevy codebase).
46+
- Scripts to pull _all_ the functions from the Bevy codebase's shader code so you can easily lookup what's available for import. (See `scripts/README.md`)
47+
- Scripts to search the Bevy source code (opening your browser) for specific keywords. (See `scripts/README.md`)
4748
- Continious image capture to create .gifs! (Currently only supporting a maximum framerate of 20FPS for capture.)
4849
- Automatic recompilation and update of shaders upon saving changes in your editor.
4950
- Quick iteration and experimentation with `wgsl` shader code.

build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1414
.expect("Failed to execute git clone command")
1515
.success()
1616
{
17-
eprintln!("Failed to clone Bevy repository");
17+
eprintln!("Failed to clone Bevy repository.\nShadplay makes a copy of the bevy codebase here to help generate documentation for you, if you don't want that modify _this_ file `./shadplay/build.rs`");
18+
1819
exit(1);
1920
}
2021

scripts/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# shadplay scripts
2+
3+
```sh
4+
/scripts
5+
├── file-and-func.py
6+
├── make-gif-example.sh
7+
├── make-bevy-shaderdoc.py
8+
├── reset-2d.py
9+
├── reset-3d.py
10+
├── screenshots-to-gallery.py
11+
├── search-bevy-codebase-for.sh
12+
├── update-gallery.py
13+
└── wgsl-case-changer.py
14+
15+
```
16+
17+
| Script Name | Description |
18+
|-------------|-------------|
19+
| file_and_func.py | This is a script that pulls the filenames/function pairings from the bevy sourcecode.
20+
| `file_and_func.py` | This is a script that pulls the filenames/function pairings from the bevy sourcecode.
21+
|
22+
| `make-gif-example.sh` | Shows how one _may_ make a `.gif` from the output of gif-capture-mode, see main `../README.md` |
23+
| `make_bevy_shaderdoc.py` | creates a single markdown document with _**all**_ the Bevy codebase's `wgsl` |
24+
| `reset-2d.py` | Resets the 2d shader (useful if you want to try again from the default). |
25+
| `reset-3d.py` | Resets the 3d shader (useful if you want to try again from the default). |
26+
| `screenshots-to-gallery.py` | Moves shader screenshots you've created into markdown documents that pairs the code that generated them and said screenshot. |
27+
| `search-bevy-codebase-for.sh` | An example of something that may help you search the bevy codebase faster (if the shader doc generated by `make_bevy_shaderdoc.py` isn't helpful) |
28+
| `update-gallery.py` | updates the gallery's `README.md` |
29+
| `wgsl-case-changer.py` | go between `snake_case` and `CamelCase`, rusty
File renamed without changes.

scripts/make_bevy_shaderdoc.py scripts/make-bevy-shaderdoc.py

+73-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,49 @@
55
"""
66

77
import argparse
8+
import os
9+
import shutil
10+
import subprocess
811
from pathlib import Path
912

1013

14+
def move_to_shadplay():
15+
current_dir = Path.cwd()
16+
shadplay_dir = None
17+
18+
# Check if the current directory is already 'shadplay'
19+
if current_dir.name == "shadplay":
20+
print("Already in the 'shadplay' directory.")
21+
return
22+
23+
# Search up the directory tree for 'shadplay'
24+
for parent in current_dir.parents:
25+
shadplay_dir = parent / "shadplay"
26+
if shadplay_dir.exists():
27+
print(f"Found 'shadplay' directory at: {shadplay_dir}")
28+
break
29+
30+
# If not found, search down from the current directory
31+
if not shadplay_dir or not shadplay_dir.exists():
32+
for child in current_dir.iterdir():
33+
if child.is_dir() and child.name == "shadplay":
34+
shadplay_dir = child
35+
print(f"Found 'shadplay' directory at: {shadplay_dir}")
36+
break
37+
38+
# If 'shadplay' directory is found, change the current working directory to it
39+
if shadplay_dir and shadplay_dir.exists():
40+
os.chdir(shadplay_dir)
41+
print(f"Moved to 'shadplay' directory: {shadplay_dir}")
42+
else:
43+
print("'shadplay' directory not found.")
44+
45+
1146
def collect_wgsl_contents(directory):
1247
wgsl_contents = {}
1348

1449
# Recursively search for .wgsl files
15-
for wgsl_file in directory.glob("**/*.wgsl"):
50+
for wgsl_file in directory.rglob("*.wgsl"):
1651
# Extract the relative path without the file extension
1752
relative_path = wgsl_file.relative_to(directory).with_suffix("")
1853
with open(wgsl_file, "r") as file:
@@ -48,6 +83,32 @@ def write_to_markdown(wgsl_contents, output_path):
4883
write_wgsl_contents(markdown_file, wgsl_contents)
4984

5085

86+
def clone_bevy_codebase():
87+
# Define the URL of the Bevy repository
88+
repo_url = "https://github.com/bevyengine/bevy.git"
89+
90+
# Define the directory where you want to clone the repository
91+
# This is set to a directory named 'bevy' in the current working directory
92+
clone_dir = os.path.join(os.getcwd(), "bevy")
93+
94+
# Check if the directory already exists
95+
if os.path.exists(clone_dir):
96+
print(
97+
f"The directory '{clone_dir}' already exists. To be certain you get the latest, we'll remove it and reclone the source.."
98+
)
99+
shutil.rmtree(clone_dir)
100+
print(f"Directory '{clone_dir}' removed.")
101+
102+
clone_bevy_codebase()
103+
104+
# Use subprocess to run the git clone command
105+
try:
106+
subprocess.run(["git", "clone", repo_url, clone_dir], check=True)
107+
print(f"Bevy codebase cloned successfully into '{clone_dir}'.")
108+
except subprocess.CalledProcessError as e:
109+
print(f"Failed to clone the Bevy codebase. Error: {e}")
110+
111+
51112
def main():
52113
parser = argparse.ArgumentParser(
53114
description="Convert .wgsl files to a markdown document."
@@ -61,12 +122,21 @@ def main():
61122
parser.add_argument(
62123
"--output",
63124
type=str,
64-
default="bevy_shader_book.md",
65-
help="Output markdown file (default: bevy_shader_book.md)",
125+
default="bevy-shader-book.md",
126+
help="Output markdown file (default: bevy-shader-book.md)",
127+
)
128+
parser.add_argument(
129+
"--skip-clone", action="store_true", help="Skip cloning the Bevy codebase."
66130
)
67131

68132
args = parser.parse_args()
69133

134+
move_to_shadplay()
135+
136+
# Skip cloning if the --skip-clone flag is set
137+
if not args.skip_clone:
138+
clone_bevy_codebase()
139+
70140
input_directory = Path(args.input)
71141
output_path = Path(args.output)
72142

scripts/search-bevy-codebase-for.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
search_query="$1"
2222
github_url="https://github.com/search?q=repo%3Abevyengine%2Fbevy+$search_query+language%3AWGSL&type=code&l=WGSL"
2323

24-
# Open the URL in the default web browser
24+
# Open the URL in the default web browser (sorry, assumes linux/gnome users..)
2525
xdg-open "$github_url"
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)