-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Displacement Maps | ||
|
||
People asked me for a quicky about how displacement maps work so uhhh... | ||
|
||
Ok so in [PR #26709](https://github.com/space-wizards/space-station-14/pull/26709) I added displacement maps. Yippee. This allows you to deform a sprite based on another, specially-crafted sprite. How do we make these specially crafted sprites? | ||
|
||
## Displacement map format | ||
|
||
Displacement maps should work the same as [BYOND's](http://www.byond.com/docs/ref/index.html#/{notes}/filters/displace). I did not at all test BYOND's so there's a nonzero chance I misread their docs and they're like interpreted inversely or something. Whatever. | ||
|
||
The basic idea is that each pixel of the displacement map specifies how much to "shift" the pixels at a position. It should be noted that, due to how GPUs work, this may not work as you may anticipate. Instead of specifying "Pixel X displaces to position Y", it actually specifies "Pixel X reads from position Y". i.e. if you specify a displacement of +1 pixel horizontally, the sprite will visually shift to the **left**, because they get their color from the texture pixel +1 to the right. | ||
|
||
The red channel controls horizontal deviation, the green channels controls vertical deviation. A red and green value of 128 is "neutral", i.e. no difference. Greater red or green values cause displacements to be sampled to the bottom right, effectively meaning the sprite moves to the "top left". | ||
|
||
The actual displacement value can be changed with a "size" parameter on the shader. Basically this size parameter is "how many pixels are shifted at the maximal pixel value". With a "size" of 4, a value of 255 would shift by 4 pixels. With a size of 127, each value on the channel is a one pixel shift (129 -> +1, 130 -> +2). | ||
|
||
## Actual shader | ||
|
||
The actual displacement map shader in SS14 is located at `/Textures/Shaders/displacement.swsl`. It has three parameters: `displacementSize` is the size described above, and `displacementMap` and `displacementUV` are intended to be filled out with the `CopyToShaderParameters` system of a sprite component. See the PR I linked above as example. | ||
|
||
## Displacement RSI load parameters | ||
|
||
Remember to set the following in your RSI's `meta.json` because otherwise sRGB will eat your face and none of the math will make sense: | ||
|
||
```json | ||
"load": { | ||
"srgb": false | ||
} | ||
``` | ||
|
||
## Aseprite scripts | ||
|
||
I wrote some Aseprite scripts to help with authoring displacement maps. You can find them in the `Tools/` folder of SS14's repo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters