mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
add NormalsDisplacement shader and preset
This commit is contained in:
parent
9b12a840f8
commit
e09307f799
6
reshade/NormalsDisplacement.slangp
Normal file
6
reshade/NormalsDisplacement.slangp
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
shaders = 1
|
||||||
|
|
||||||
|
shader0 = shaders/NormalsDisplacement/NormalsDisplacement.slang
|
||||||
|
|
||||||
|
textures = "displacementMap"
|
||||||
|
displacementMap = shaders/NormalsDisplacement/CurveNormals.png
|
BIN
reshade/shaders/NormalsDisplacement/CurveNormals.png
Normal file
BIN
reshade/shaders/NormalsDisplacement/CurveNormals.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
|
@ -0,0 +1,53 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
float Displacement;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
#pragma parameter Displacement "Displacement Factor" 20.0 0.0 60.0 1.0
|
||||||
|
|
||||||
|
layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
|
{
|
||||||
|
mat4 MVP;
|
||||||
|
} global;
|
||||||
|
|
||||||
|
#pragma stage vertex
|
||||||
|
layout(location = 0) in vec4 Position;
|
||||||
|
layout(location = 1) in vec2 TexCoord;
|
||||||
|
layout(location = 0) out vec2 vTexCoord;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = global.MVP * Position;
|
||||||
|
vTexCoord = TexCoord;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma stage fragment
|
||||||
|
layout(location = 0) in vec2 vTexCoord;
|
||||||
|
layout(location = 0) out vec4 FragColor;
|
||||||
|
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||||
|
layout(set = 0, binding = 3) uniform sampler2D displacementMap;
|
||||||
|
|
||||||
|
vec2 DisplacementLevel()
|
||||||
|
{
|
||||||
|
return (params.OutputSize.zw*params.Displacement);//Displacement's value is measured in half of a pixel. Don't need to waste resources on multiplying by two.
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 CoordDisplacement(vec2 coord)
|
||||||
|
{
|
||||||
|
return (coord-((texture(displacementMap, coord).xy-0.5)*DisplacementLevel()))*1.1-0.05;
|
||||||
|
//This reads the displacement texture and sets 0.5 to be 0, 1 to be 1, and 0 to be -1,
|
||||||
|
//and then it scales it to the displacement level previously defined.
|
||||||
|
//The multiplication and subtraction at the end is to scale it down so it doesn't exceed the window.
|
||||||
|
//I think it's slightly faster if I do it here and not at the end in the fragColor = line in void main().
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(texture(Source, CoordDisplacement(vTexCoord)).rgb, 1.0);
|
||||||
|
}
|
Loading…
Reference in a new issue