Separate painter shaders
This commit is contained in:
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.
@@ -0,0 +1,6 @@
|
||||
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, col.a);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
uniform float4x4 VP;
|
||||
uniform float4x4 invVP;
|
||||
uniform float2 mouse;
|
||||
uniform float2 step;
|
||||
uniform float radius;
|
||||
Texture2D<float4> texa; // direct3d12 unit align
|
||||
SamplerState _texa_sampler; // direct3d12 unit align
|
||||
Texture2D<float4> gbufferD;
|
||||
SamplerState _gbufferD_sampler;
|
||||
Texture2D<float4> gbuffer0;
|
||||
SamplerState _gbuffer0_sampler;
|
||||
float2 octahedronWrap(float2 v) { return (1.0 - abs(v.yx)) * (float2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0)); }
|
||||
float3x3 rotAxis(float3 axis, float a) {
|
||||
float c = cos(a);
|
||||
float3 as = axis * sin(a).xxx;
|
||||
float3x3 p = float3x3(axis.xxx * axis, axis.yyy * axis, axis.zzz * axis);
|
||||
float3x3 q = float3x3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c);
|
||||
return p * (1.0 - c) + q;
|
||||
}
|
||||
float3 getNormal(float2 uv) {
|
||||
float2 g0 = gbuffer0.SampleLevel(_gbuffer0_sampler, uv, 0.0).rg;
|
||||
float3 n;
|
||||
n.z = 1.0 - abs(g0.x) - abs(g0.y);
|
||||
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
|
||||
return n;
|
||||
}
|
||||
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) {
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.texCoord = tex;
|
||||
float2 mouseinv = float2(mouse.x, 1.0 - mouse.y);
|
||||
float depth = gbufferD.SampleLevel(_gbufferD_sampler, mouseinv, 0).r;
|
||||
float keep = texa.SampleLevel(_texa_sampler, mouseinv, 0).r; // direct3d12 unit align
|
||||
depth += keep * 0.0; // direct3d12 unit align
|
||||
float4 wpos = float4(mouse * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
||||
wpos = mul(wpos, invVP);
|
||||
wpos.xyz /= wpos.w;
|
||||
float3 n = normalize(
|
||||
getNormal(mouseinv + float2(step.x, step.y)) +
|
||||
getNormal(mouseinv + float2(-step.x, step.y)) +
|
||||
getNormal(mouseinv + float2(-step.x, -step.y)) +
|
||||
getNormal(mouseinv + float2(step.x, -step.y)) +
|
||||
getNormal(mouseinv)
|
||||
);
|
||||
float ax = acos(dot(float3(1,0,0), float3(n.x,0,0)));
|
||||
float az = acos(dot(float3(0,0,1), float3(0,0,n.z)));
|
||||
float sy = -sign(n.y);
|
||||
wpos.xyz += mul(mul(pos.xyz * radius.xxx, rotAxis(float3(0,0,1), ax + 3.14/2)),
|
||||
rotAxis(float3(1,0,0), -az * sy + 3.14/2));
|
||||
stage_output.gl_Position = mul(float4(wpos.xyz, 1.0), VP);
|
||||
stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5;
|
||||
return stage_output;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
Texture2D<float4> tex0;
|
||||
SamplerState _tex0_sampler;
|
||||
Texture2D<float4> tex1;
|
||||
SamplerState _tex1_sampler;
|
||||
Texture2D<float4> tex2;
|
||||
SamplerState _tex2_sampler;
|
||||
Texture2D<float4> texa;
|
||||
SamplerState _texa_sampler;
|
||||
Texture2D<float4> texb;
|
||||
SamplerState _texb_sampler;
|
||||
Texture2D<float4> texc;
|
||||
SamplerState _texc_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; float4 color1 : SV_Target1; float4 color2 : SV_Target2; };
|
||||
SPIRV_Cross_Output main(float2 texCoord : TEXCOORD0) {
|
||||
float4 col0 = tex0.SampleLevel(_tex0_sampler, texCoord, 0);
|
||||
float4 col1 = tex1.SampleLevel(_tex1_sampler, texCoord, 0);
|
||||
float4 col2 = tex2.SampleLevel(_tex2_sampler, texCoord, 0);
|
||||
float4 cola = texa.SampleLevel(_texa_sampler, texCoord, 0);
|
||||
float4 colb = texb.SampleLevel(_texb_sampler, texCoord, 0);
|
||||
float4 colc = texc.SampleLevel(_texc_sampler, texCoord, 0);
|
||||
float str = col0.a * opac;
|
||||
SPIRV_Cross_Output stage_output;
|
||||
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));
|
||||
}
|
||||
stage_output.color1 = float4(lerp(colb, col1, str));
|
||||
stage_output.color2 = float4(lerp(colc, col2, str));
|
||||
return stage_output;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
Texture2D<float4> tex;
|
||||
SamplerState _tex_sampler;
|
||||
float4 main(float4 color : TEXCOORD0, float2 texCoord : TEXCOORD1) : SV_Target0 {
|
||||
return tex.SampleLevel(_tex_sampler, texCoord, 0) * color;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user