|
| 1 | +# Phaser 4 TypeScript - Shader Examples |
| 2 | + |
| 3 | +Contains example code of how to use various shaders in Phaser 4. This is the sample code that I shared in my tutorial video hosted on YouTube here were we walk through migrating some existing Phaser 3 shaders to the Phaser 4: |
| 4 | + |
| 5 | +[<img src="https://i.ytimg.com/vi/4Dj5PSKwjak/hqdefault.jpg">](https://youtu.be/4Dj5PSKwjak "Phaser 3 Tutorial: Getting Started with Shaders!") |
| 6 | + |
| 7 | +You can see a live demo of the examples here: <a href="https://devshareacademy.github.io/phaser-4-typescript-games-and-examples/examples/rc5/shader-pipeline-migration/index.html" target="_blank">Shader Examples</a>. |
| 8 | + |
| 9 | +While viewing the examples, if you press the `space` key, you can navigate between various examples. Below is a list of the examples shaders that can be seen and the corresponding files to that example: |
| 10 | + |
| 11 | +| Example | Description | Location | |
| 12 | +|---------|-------------|----------| |
| 13 | +| Grey Scale | Example of how to apply a grey scale affect to all pixels. | `./src/shaders/grey-scale-shader.ts` | |
| 14 | +| Screen Wipe | Example of how to use custom variables in a shader to create animations, like a scene transition. | `./src/shaders/wipe-shader.ts` | |
| 15 | +| Noise Mix | Example of how to pass an addition texture to a shader and mix this texture with the original texture. Used to create a grainy effect. | `./src/shaders/noise-shader.ts` | |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +## Local Development |
| 22 | + |
| 23 | +### Requirements |
| 24 | + |
| 25 | +<a href="https://nodejs.org" target="_blank">Node.js</a> and <a href="https://pnpm.io/" target="_blank">PnPm</a> are required to install dependencies and run scripts via `pnpm`. |
| 26 | + |
| 27 | +<a href="https://vitejs.dev/" target="_blank">Vite</a> is required to bundle and serve the web application. This is included as part of the projects dev dependencies. |
| 28 | + |
| 29 | +### Available Commands |
| 30 | + |
| 31 | +| Command | Description | |
| 32 | +|---------|-------------| |
| 33 | +| `pnpm install --frozen-lockfile` | Install project dependencies | |
| 34 | +| `pnpm start` | Build project and open web server running project | |
| 35 | +| `pnpm build` | Builds code bundle for production | |
| 36 | +| `pnpm lint` | Uses ESLint to lint code | |
| 37 | + |
| 38 | +### Writing Code |
| 39 | + |
| 40 | +After cloning the repo, run `pnpm install --frozen-lockfile` from your project directory. Then, you can start the local development |
| 41 | +server by running `pnpm start`. |
| 42 | + |
| 43 | +After starting the development server with `pnpm start`, you can edit any files in the `src` folder |
| 44 | +and parcel will automatically recompile and reload your server (available at `http://localhost:8080` |
| 45 | +by default). |
| 46 | + |
| 47 | +### Deploying Code |
| 48 | + |
| 49 | +After you run the `pnpm build` command, your code will be built into a single bundle located at |
| 50 | +`dist/*` along with any other assets you project depended. |
| 51 | + |
| 52 | +If you put the contents of the `dist` folder in a publicly-accessible location (say something like `http://myserver.com`), |
| 53 | +you should be able to open `http://myserver.com/index.html` and play your game. |
| 54 | + |
| 55 | +### Static Assets |
| 56 | + |
| 57 | +Any static assets like images or audio files should be placed in the `public` folder. It'll then be served at `http://localhost:8080/path-to-file-your-file/file-name.file-type`. |
| 58 | + |
| 59 | +## Credits |
| 60 | + |
| 61 | +The assets used in this demo were made from free assets that were created from the following artists: <a href="https://axulart.itch.io/" target="_blank">ansimuz</a>. |
| 62 | + |
| 63 | +List of assets: |
| 64 | + |
| 65 | +* <a href="https://axulart.itch.io/axularts-basicplains-tileset-ver2" target="_blank">Basic Plains Set</a> |
| 66 | +* <a href="https://axulart.itch.io/small-8-direction-characters" target="_blank">Character</a> |
0 commit comments