Merge shaders

This commit is contained in:
luboslenco
2020-05-07 18:37:05 +02:00
parent 90a34d8ce5
commit f970dc4e4d
26 changed files with 11 additions and 233 deletions
@@ -6,6 +6,9 @@ uniform vec2 texStep;
uniform float radius;
uniform vec3 cameraRight;
uniform sampler2D gbufferD;
#ifdef HLSL
uniform sampler2D texa; // direct3d12 unit align
#endif
in vec4 pos;
in vec2 nor;
in vec2 tex;
@@ -18,7 +21,12 @@ out vec2 texCoord;
// return p * (1.0 - c) + q;
// }
vec3 getPos(vec2 uv) {
#ifdef HLSL
float keep = textureLod(texa, vec2(0.0, 0.0), 0.0).r + pos.x + nor.x; // direct3d12 unit align
float depth = textureLod(gbufferD, vec2(uv.x, 1.0 - uv.y), 0.0).r;
#else
float depth = textureLod(gbufferD, uv, 0.0).r;
#endif
vec4 wpos = vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
wpos = invVP * wpos;
return wpos.xyz / wpos.w;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-8
View File
@@ -1,8 +0,0 @@
..\..\..\bin\hlslbin.exe cursor.vert.hlsl ..\cursor.vert.glsl vs_5_0 -i nor -i pos -i tex
..\..\..\bin\hlslbin.exe cursor.frag.hlsl ..\cursor.frag.glsl ps_5_0
..\..\..\bin\hlslbin.exe layer_view.vert.hlsl ..\layer_view.vert.glsl vs_5_0 -i col -i pos -i tex
..\..\..\bin\hlslbin.exe layer_view.frag.hlsl ..\layer_view.frag.glsl ps_5_0
..\..\..\bin\hlslbin.exe layer_copy.frag.hlsl ..\layer_copy.frag.glsl ps_5_0
..\..\..\bin\hlslbin.exe layer_merge.vert.hlsl ..\layer_merge.vert.glsl vs_5_0 -i pos
..\..\..\bin\hlslbin.exe layer_merge.frag.hlsl ..\layer_merge.frag.glsl ps_5_0
..\..\..\bin\hlslbin.exe mask_merge.frag.hlsl ..\mask_merge.frag.glsl ps_5_0
@@ -1,7 +0,0 @@
uniform float3 tint;
Texture2D<float4> tex;
SamplerState _tex_sampler;
float4 main(float2 texCoord : TEXCOORD0) : SV_Target0 {
float4 col = tex.Sample(_tex_sampler, texCoord);
return float4((col.rgb / col.a) * tint, col.a);
}
-60
View File
@@ -1,60 +0,0 @@
uniform float4x4 VP;
uniform float4x4 invVP;
uniform float2 mouse;
uniform float2 texStep;
uniform float radius;
uniform float3 cameraRight;
Texture2D<float4> texa; // direct3d12 unit align
SamplerState _texa_sampler; // direct3d12 unit align
Texture2D<float4> gbufferD;
SamplerState _gbufferD_sampler;
float3 getPos(float2 uv) {
float2 uvinv = float2(uv.x, 1.0 - uv.y);
float depth = gbufferD.SampleLevel(_gbufferD_sampler, uvinv, 0).r;
float4 wpos = float4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
wpos = mul(wpos, invVP);
return wpos.xyz / wpos.w;
}
float3 getNormal(float3 p0, float2 uv) {
float3 p1 = getPos(uv + float2(texStep.x, 0));
float3 p2 = getPos(uv + float2(0, texStep.y));
return normalize(cross(p2 - p0, p1 - p0));
}
void createBasis(float3 normal, out float3 tangent, out float3 binormal) {
// Project vector onto plane
tangent = normalize(cameraRight - normal * dot(cameraRight, normal));
binormal = cross(tangent, normal);
}
struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV_Position; };
SPIRV_Cross_Output main(float2 nor : TEXCOORD0, float4 pos : TEXCOORD1, float2 tex : TEXCOORD2, uint gl_VertexID : SV_VertexID) {
SPIRV_Cross_Output stage_output;
stage_output.texCoord = tex;
float3 wpos = getPos(mouse);
float2 uv1 = mouse + texStep * 4;
float2 uv2 = mouse - texStep * 4;
float3 wpos1 = getPos(uv1);
float3 wpos2 = getPos(uv2);
float keep = texa.SampleLevel(_texa_sampler, mouse, 0).r; // direct3d12 unit align
wpos.x += keep * 0.0000001; // direct3d12 unit align;
float3 n = normalize(
getNormal(wpos, mouse) +
getNormal(wpos1, uv1) +
getNormal(wpos2, uv2)
);
float3 n_tan;
float3 n_bin;
createBasis(n, n_tan, n_bin);
if (gl_VertexID == 0) wpos += normalize(-n_tan - n_bin) * 0.7 * radius;
else if (gl_VertexID == 1) wpos += normalize( n_tan - n_bin) * 0.7 * radius;
else if (gl_VertexID == 2) wpos += normalize( n_tan + n_bin) * 0.7 * radius;
else if (gl_VertexID == 3) wpos += normalize(-n_tan + n_bin) * 0.7 * radius;
stage_output.gl_Position = mul(float4(wpos, 1.0), VP);
stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5;
return stage_output;
}
@@ -1,5 +0,0 @@
Texture2D<float4> tex;
SamplerState _tex_sampler;
float4 main(float4 color : TEXCOORD0, float2 texCoord : TEXCOORD1) : SV_Target0 {
return tex.SampleLevel(_tex_sampler, texCoord, 0).rgba * color;
}
@@ -1,90 +0,0 @@
Texture2D<float4> tex0;
SamplerState _tex0_sampler;
Texture2D<float4> tex1;
SamplerState _tex1_sampler;
Texture2D<float4> texmask;
SamplerState _texmask_sampler;
Texture2D<float4> texa;
SamplerState _texa_sampler;
uniform float opac;
uniform int blending;
float3 hsv_to_rgb(const float3 c) {
const float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
float3 rgb_to_hsv(const float3 c) {
const float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
struct SPIRV_Cross_Output { float4 color0 : SV_Target0; };
SPIRV_Cross_Output main(float2 texCoord : TEXCOORD0) {
float4 col0 = tex0.SampleLevel(_tex0_sampler, texCoord, 0);
float4 cola = texa.SampleLevel(_texa_sampler, texCoord, 0);
float str = col0.a * opac;
str *= texmask.SampleLevel(_texmask_sampler, texCoord, 0).r;
SPIRV_Cross_Output stage_output;
if (blending == -1) { // Merging _nor and _pack
float4 col1 = tex1.SampleLevel(_tex1_sampler, texCoord, 0);
stage_output.color0 = float4(lerp(cola, col1, str));
}
else if (blending == 0) { // Mix
stage_output.color0 = float4(lerp(cola.rgb, col0.rgb, str), max(col0.a, cola.a));
}
else if (blending == 1) { // Darken
stage_output.color0 = float4(lerp(cola.rgb, min(cola.rgb, col0.rgb), str), max(col0.a, cola.a));
}
else if (blending == 2) { // Multiply
stage_output.color0 = float4(lerp(cola.rgb, cola.rgb * col0.rgb, str), max(col0.a, cola.a));
}
else if (blending == 3) { // Burn
stage_output.color0 = float4(lerp(cola.rgb, float3(1.0, 1.0, 1.0) - (float3(1.0, 1.0, 1.0) - cola.rgb) / col0.rgb, str), max(col0.a, cola.a));
}
else if (blending == 4) { // Lighten
stage_output.color0 = float4(max(cola.rgb, col0.rgb * str), max(col0.a, cola.a));
}
else if (blending == 5) { // Screen
stage_output.color0 = float4((float3(1.0, 1.0, 1.0) - (float3(1.0 - str, 1.0 - str, 1.0 - str) + str * (float3(1.0, 1.0, 1.0) - col0.rgb)) * (float3(1.0, 1.0, 1.0) - cola.rgb)), max(col0.a, cola.a));
}
else if (blending == 6) { // Dodge
stage_output.color0 = float4(lerp(cola.rgb, cola.rgb / (float3(1.0, 1.0, 1.0) - col0.rgb), str), max(col0.a, cola.a));
}
else if (blending == 7) { // Add
stage_output.color0 = float4(lerp(cola.rgb, cola.rgb + col0.rgb, str), max(col0.a, cola.a));
}
else if (blending == 8) { // Overlay
stage_output.color0 = float4(lerp(cola.rgb, (cola.rgb < float3(0.5, 0.5, 0.5) ? float3(2.0, 2.0, 2.0) * cola.rgb * col0.rgb : float3(1.0, 1.0, 1.0) - float3(2.0, 2.0, 2.0) * (float3(1.0, 1.0, 1.0) - col0.rgb) * (float3(1.0, 1.0, 1.0) - cola.rgb)), str), max(col0.a, cola.a));
}
else if (blending == 9) { // Soft Light
stage_output.color0 = float4(((1.0 - str) * cola.rgb + str * ((float3(1.0, 1.0, 1.0) - cola.rgb) * col0.rgb * cola.rgb + cola.rgb * (float3(1.0, 1.0, 1.0) - (float3(1.0, 1.0, 1.0) - col0.rgb) * (float3(1.0, 1.0, 1.0) - cola.rgb)))), max(col0.a, cola.a));
}
else if (blending == 10) { // Linear Light
stage_output.color0 = float4((cola.rgb + str * (float3(2.0, 2.0, 2.0) * (col0.rgb - float3(0.5, 0.5, 0.5)))), max(col0.a, cola.a));
}
else if (blending == 11) { // Difference
stage_output.color0 = float4(lerp(cola.rgb, abs(cola.rgb - col0.rgb), str), max(col0.a, cola.a));
}
else if (blending == 12) { // Subtract
stage_output.color0 = float4(lerp(cola.rgb, cola.rgb - col0.rgb, str), max(col0.a, cola.a));
}
else if (blending == 13) { // Divide
stage_output.color0 = float4(float3(1.0 - str, 1.0 - str, 1.0 - str) * cola.rgb + float3(str, str, str) * cola.rgb / col0.rgb, max(col0.a, cola.a));
}
else if (blending == 14) { // Hue
stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a));
}
else if (blending == 15) { // Saturation
stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a));
}
else if (blending == 16) { // Color
stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a));
}
else { // Value
stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(col0.rgb).b)), str), max(col0.a, cola.a));
}
return stage_output;
}
@@ -1,10 +0,0 @@
struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV_Position; };
SPIRV_Cross_Output main(float2 pos : TEXCOORD0) {
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = float4(pos.xy, 0.0, 1.0);
stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5;
const float2 madd = float2(0.5, 0.5);
stage_output.texCoord = pos.xy * madd + madd;
stage_output.texCoord.y = 1.0 - stage_output.texCoord.y;
return stage_output;
}
@@ -1,25 +0,0 @@
Texture2D<float4> tex;
SamplerState _tex_sampler;
uniform int channel;
float4 main(float4 color : TEXCOORD0, float2 texCoord : TEXCOORD1) : SV_Target0 {
if (channel == 1) {
return tex.SampleLevel(_tex_sampler, texCoord, 0).rrra * color;
}
else if (channel == 2) {
return tex.SampleLevel(_tex_sampler, texCoord, 0).ggga * color;
}
else if (channel == 3) {
return tex.SampleLevel(_tex_sampler, texCoord, 0).bbba * color;
}
else if (channel == 4) {
return tex.SampleLevel(_tex_sampler, texCoord, 0).aaaa * color;
}
else if (channel == 5) {
return tex.SampleLevel(_tex_sampler, texCoord, 0).rgba * color;
}
else {
float4 sample = tex.SampleLevel(_tex_sampler, texCoord, 0).rgba;
sample.rgb *= sample.a;
return sample.rgba * color;
}
}
@@ -1,10 +0,0 @@
uniform float4x4 projectionMatrix;
struct SPIRV_Cross_Output { float4 color : TEXCOORD0; float2 texCoord : TEXCOORD1; float4 gl_Position : SV_Position; };
SPIRV_Cross_Output main(float4 col : TEXCOORD0, float3 pos : TEXCOORD1, float2 tex : TEXCOORD2) {
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = mul(float4(pos, 1.0f), projectionMatrix);
stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5;
stage_output.texCoord = tex;
stage_output.color = col;
return stage_output;
}
@@ -1,12 +0,0 @@
Texture2D<float4> tex0;
SamplerState _tex0_sampler;
Texture2D<float4> texa;
SamplerState _texa_sampler;
struct SPIRV_Cross_Output { float4 color0 : SV_Target0; };
SPIRV_Cross_Output main(float2 texCoord : TEXCOORD0) {
float4 col0 = tex0.SampleLevel(_tex0_sampler, texCoord, 0);
float mask = texa.SampleLevel(_texa_sampler, texCoord, 0).r;
SPIRV_Cross_Output stage_output;
stage_output.color0 = float4(col0.rgb, col0.a * mask);
return stage_output;
}
@@ -5,4 +5,7 @@ void main() {
gl_Position = vec4(pos.xy, 0.0, 1.0);
const vec2 madd = vec2(0.5, 0.5);
texCoord = pos.xy * madd + madd;
#ifdef HLSL
texCoord.y = 1.0 - texCoord.y;
#endif
}