Requires https://github.com/space-wizards/RobustToolbox/pull/5023 This uses the new engine features (above) to add a displacement map shader. This allows deforming a sprite based on another sprite. Primary use case is automatically adapting human clothing sprites to different species, something we want to make species like Vox a reality. A basic example of wiring this up with Vox has been added. The system is however incredibly simple and **will** need more work by a content developer to select and toggle displacement maps when appropriate. I am leaving that to somebody else. For example right now the displacement map is applied even if a species already has custom-fit sprites for a piece of clothing, such as the grey jumpsuit for Vox. Basic Aseprite plugins to help with authoring displacement maps have also been made.
19 lines
595 B
Plaintext
19 lines
595 B
Plaintext
uniform sampler2D displacementMap;
|
|
uniform highp float displacementSize;
|
|
uniform highp vec4 displacementUV;
|
|
|
|
varying highp vec2 displacementUVOut;
|
|
|
|
void vertex() {
|
|
displacementUVOut = mix(displacementUV.xy, displacementUV.zw, tCoord2);
|
|
}
|
|
|
|
void fragment() {
|
|
highp vec4 displacementSample = texture2D(displacementMap, displacementUVOut);
|
|
highp vec2 displacementValue = (displacementSample.xy - vec2(128.0 / 255.0)) / (1.0 - 128.0 / 255.0);
|
|
COLOR = zTexture(UV + displacementValue * TEXTURE_PIXEL_SIZE * displacementSize * vec2(1.0, -1.0));
|
|
COLOR.a *= displacementSample.a;
|
|
}
|
|
|
|
|