mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
Add files via upload
Initial version for trying to split up the shader to multi-pass in order to allow further adjustments of the outlines. Higher outline blur and weight settings will thicken up the lines for higher internal resolutions.
This commit is contained in:
parent
0dc873e73f
commit
ed7e1452bb
65
cel/shaders/MMJ_Cel_Shader_MP_Blur_H.slang
Normal file
65
cel/shaders/MMJ_Cel_Shader_MP_Blur_H.slang
Normal file
|
@ -0,0 +1,65 @@
|
|||
#version 450
|
||||
|
||||
#pragma name MMJ_BlurPass_H
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------
|
||||
MMJ's Cel Shader v2.0 - Multi-Pass
|
||||
----------------------------------------------------------------
|
||||
Based on the original blur-gauss-h shader code.
|
||||
|
||||
Used to blur the outlines, which is helpful at higher internal
|
||||
resolution settings to increase the line thickness.
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
Blur Weight - Horizontal = Adjusts horizontal blur factor.
|
||||
----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
float BlurWeightH;
|
||||
} params;
|
||||
|
||||
#pragma parameter BlurWeightH "Blur Weight - Horizontal" 0.0 0.0 16.0 1.0
|
||||
|
||||
#define SourceSize params.SourceSize
|
||||
#define BlurWeightH params.BlurWeightH
|
||||
|
||||
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;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 PIXEL_SIZE = SourceSize.zw;
|
||||
vec4 C = texture(Source, vTexCoord);
|
||||
float L = 0.0, J = 0.0;
|
||||
for(int i = 1; i <= BlurWeightH; ++i) {
|
||||
L = 1.0 / i;
|
||||
J = 0.5 * i * PIXEL_SIZE.x;
|
||||
C = mix(C, mix(texture(Source, vTexCoord + vec2(J, 0.0)), texture(Source, vTexCoord - vec2(J, 0.0)), 0.5), L);
|
||||
}
|
||||
FragColor = C;
|
||||
}
|
67
cel/shaders/MMJ_Cel_Shader_MP_Blur_V.slang
Normal file
67
cel/shaders/MMJ_Cel_Shader_MP_Blur_V.slang
Normal file
|
@ -0,0 +1,67 @@
|
|||
#version 450
|
||||
|
||||
#pragma name MMJ_BlurPass_V
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------
|
||||
MMJ's Cel Shader v2.0 - Multi-Pass
|
||||
----------------------------------------------------------------
|
||||
Based on the original blur-gauss-v shader code.
|
||||
|
||||
Used to blur the outlines, which is helpful at higher internal
|
||||
resolution settings to increase the line thickness.
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
Blur Weight - Vertical = Adjusts vertical blur factor.
|
||||
----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 MMJ_BlurPass_HSize;
|
||||
vec4 OriginalSize;
|
||||
float BlurWeightV;
|
||||
} params;
|
||||
|
||||
#pragma parameter BlurWeightV "Blur Weight - Vertical" 0.0 0.0 16.0 1.0
|
||||
|
||||
#define MMJ_BlurPass_HSize params.MMJ_BlurPass_HSize
|
||||
#define OriginalSize params.OriginalSize
|
||||
#define BlurWeightV params.BlurWeightV
|
||||
|
||||
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 MMJ_BlurPass_H;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 PIXEL_SIZE = OriginalSize.zw;
|
||||
vec4 C = texture(MMJ_BlurPass_H, vTexCoord);
|
||||
float L = 0.0, J = 0.0;
|
||||
for(int i = 1; i <= BlurWeightV; ++i) {
|
||||
L = 1.0 / i;
|
||||
J = 0.5 * i * PIXEL_SIZE.y;
|
||||
C = mix(C, mix(texture(MMJ_BlurPass_H, vTexCoord + vec2(0.0, J)), texture(MMJ_BlurPass_H, vTexCoord - vec2(0.0, J)), 0.5), L);
|
||||
}
|
||||
FragColor = C;
|
||||
}
|
152
cel/shaders/MMJ_Cel_Shader_MP_Color.slang
Normal file
152
cel/shaders/MMJ_Cel_Shader_MP_Color.slang
Normal file
|
@ -0,0 +1,152 @@
|
|||
#version 450
|
||||
|
||||
#pragma name MMJ_ColorPass
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------
|
||||
MMJ's Cel Shader v2.0 - Multi-Pass
|
||||
----------------------------------------------------------------
|
||||
Parameters:
|
||||
-----------
|
||||
Color Saturation = Increase or decrease color saturation.
|
||||
|
||||
Color Levels = Determines number of color "bands".
|
||||
|
||||
Color Weight = Changes the strength of the color adjustments.
|
||||
----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 MMJ_OutlineSize;
|
||||
vec4 OriginalSize;
|
||||
float ColorLevels;
|
||||
float ColorSaturation;
|
||||
float ColorWeight;
|
||||
} params;
|
||||
|
||||
#pragma parameter ColorLevels "Color Levels" 12.0 1.0 32.0 1.0
|
||||
#pragma parameter ColorSaturation "Color Saturation" 1.15 0.00 2.00 0.05
|
||||
#pragma parameter ColorWeight "Color Weight" 0.50 0.00 1.00 0.05
|
||||
|
||||
#define MMJ_OutlineSize params.MMJ_OutlineSize
|
||||
#define OriginalSize params.OriginalSize
|
||||
#define ColorLevels params.ColorLevels
|
||||
#define ColorSaturation params.ColorSaturation
|
||||
#define ColorWeight params.ColorWeight
|
||||
|
||||
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 Original;
|
||||
layout(set = 0, binding = 3) uniform sampler2D MMJ_OutlinePass;
|
||||
|
||||
vec3 RGB2HSL(vec3 cRGB)
|
||||
{
|
||||
float cR = cRGB[0], cG = cRGB[1], cB = cRGB[2];
|
||||
float vMin = min(min(cR, cG), cB), vMax = max(max(cR, cG), cB);
|
||||
float dMax = vMax - vMin, vS = 0.0, vH = 0.0, vL = (vMax + vMin) / 2.0;
|
||||
|
||||
// gray, no chroma
|
||||
if(dMax == 0.0) {
|
||||
vH = 0.0; vS = vH;
|
||||
|
||||
// chromatic data
|
||||
} else {
|
||||
if(vL < 0.5) { vS = dMax / (vMax + vMin); }
|
||||
else { vS = dMax / (2.0 - vMax - vMin); }
|
||||
|
||||
float dR = (((vMax - cR) * 0.1667) + (dMax * 0.5)) / dMax;
|
||||
float dG = (((vMax - cG) * 0.1667) + (dMax * 0.5)) / dMax;
|
||||
float dB = (((vMax - cB) * 0.1667) + (dMax * 0.5)) / dMax;
|
||||
|
||||
if (cR >= vMax) { vH = dB - dG; }
|
||||
else if(cG >= vMax) { vH = 0.3333 + dR - dB; }
|
||||
else if(cB >= vMax) { vH = 0.6667 + dG - dR; }
|
||||
|
||||
if (vH < 0.0) { vH += 1.0; }
|
||||
else if(vH > 1.0) { vH -= 1.0; }
|
||||
}
|
||||
return vec3(vH, vS, vL);
|
||||
}
|
||||
|
||||
float Hue2RGB(float v1, float v2, float vH)
|
||||
{
|
||||
float v3 = 0.0;
|
||||
|
||||
if (vH < 0.0) { vH += 1.0; }
|
||||
else if(vH > 1.0) { vH -= 1.0; }
|
||||
|
||||
if ((6.0 * vH) < 1.0) { v3 = v1 + (v2 - v1) * 6.0 * vH; }
|
||||
else if((2.0 * vH) < 1.0) { v3 = v2; }
|
||||
else if((3.0 * vH) < 2.0) { v3 = v1 + (v2 - v1) * (0.6667 - vH) * 6.0; }
|
||||
else { v3 = v1; }
|
||||
|
||||
return v3;
|
||||
}
|
||||
|
||||
vec3 HSL2RGB(vec3 vHSL)
|
||||
{
|
||||
float cR = 0.0, cG = cR, cB = cR;
|
||||
|
||||
if(vHSL[1] == 0.0) {
|
||||
cR = vHSL[2], cG = cR, cB = cR;
|
||||
|
||||
} else {
|
||||
float v1 = 0.0, v2 = v1;
|
||||
|
||||
if(vHSL[2] < 0.5) { v2 = vHSL[2] * (1.0 + vHSL[1] ); }
|
||||
else { v2 = (vHSL[2] + vHSL[1] ) - (vHSL[1] * vHSL[2] ); }
|
||||
|
||||
v1 = 2.0 * vHSL[2] - v2;
|
||||
|
||||
cR = Hue2RGB(v1, v2, vHSL[0] + 0.3333);
|
||||
cG = Hue2RGB(v1, v2, vHSL[0] );
|
||||
cB = Hue2RGB(v1, v2, vHSL[0] - 0.3333);
|
||||
}
|
||||
return vec3(cR, cG, cB);
|
||||
}
|
||||
|
||||
vec3 colorAdjust(vec3 cRGB)
|
||||
{
|
||||
vec3 cHSL = RGB2HSL(cRGB);
|
||||
|
||||
float cr = 1.0 / ColorLevels;
|
||||
|
||||
// brightness modifier
|
||||
float BrtModify = mod(cHSL[2], cr);
|
||||
|
||||
cHSL[1] *= ColorSaturation;
|
||||
cHSL[2] += (cHSL[2] * cr - BrtModify);
|
||||
cRGB = 1.2 * HSL2RGB(cHSL);
|
||||
|
||||
return cRGB;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 cOriginal = texture(Original, vTexCoord).rgb;
|
||||
vec3 cOutline = texture(MMJ_OutlinePass, vTexCoord).rgb;
|
||||
|
||||
vec3 cNew = cOriginal;
|
||||
cNew = min(vec3(1.0), min(cNew, cNew + dot(vec3(1.0), cNew)));
|
||||
FragColor.rgb = mix(cOriginal * cOutline, colorAdjust(cNew * cOutline), ColorWeight);
|
||||
}
|
120
cel/shaders/MMJ_Cel_Shader_MP_Outline.slang
Normal file
120
cel/shaders/MMJ_Cel_Shader_MP_Outline.slang
Normal file
|
@ -0,0 +1,120 @@
|
|||
#version 450
|
||||
|
||||
#pragma name MMJ_OutlinePass
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------
|
||||
MMJ's Cel Shader v2.0 - Multi-Pass
|
||||
----------------------------------------------------------------
|
||||
Parameters:
|
||||
-----------
|
||||
Outline Weight = Adjusts darkness of the outlines.
|
||||
|
||||
At lower internal resolutions, smaller values work better to
|
||||
reduce the appearance of lines around individual areas of some
|
||||
textures. At higher internal resolutions, setting both a higher
|
||||
outline weight value plus increased blur factors will work
|
||||
together to thicken the appearance of the lines.
|
||||
----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 MMJ_BlurPass_VSize;
|
||||
float OutlineWeight;
|
||||
} params;
|
||||
|
||||
#pragma parameter OutlineWeight "Outline Weight" 1.0 0.0 10.0 0.1
|
||||
|
||||
#define MMJ_BlurPass_VSize params.MMJ_BlurPass_VSize
|
||||
#define OutlineWeight params.OutlineWeight
|
||||
|
||||
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;
|
||||
layout(location = 1) out vec4 TEX0;
|
||||
layout(location = 2) out vec4 TEX1;
|
||||
layout(location = 3) out vec4 TEX2;
|
||||
layout(location = 4) out vec4 TEX3;
|
||||
layout(location = 5) out vec4 TEX4;
|
||||
layout(location = 6) out vec4 TEX5;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
|
||||
TEX0 = vTexCoord.xyxy;
|
||||
|
||||
vec4 offset;
|
||||
|
||||
offset.xy = -(offset.zw = vec2(MMJ_BlurPass_VSize.z, 0.0));
|
||||
TEX1 = TEX0 + offset;
|
||||
TEX5 = TEX1 + offset;
|
||||
|
||||
offset.xy = -(offset.zw = vec2(0.0, MMJ_BlurPass_VSize.w));
|
||||
TEX2 = TEX0 + offset;
|
||||
TEX3 = TEX1 + offset;
|
||||
TEX4 = TEX2 + offset;
|
||||
}
|
||||
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec4 TEX0;
|
||||
layout(location = 2) in vec4 TEX1;
|
||||
layout(location = 3) in vec4 TEX2;
|
||||
layout(location = 4) in vec4 TEX3;
|
||||
layout(location = 5) in vec4 TEX4;
|
||||
layout(location = 6) in vec4 TEX5;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D MMJ_BlurPass_V;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 c00 = texture(MMJ_BlurPass_V, TEX3.xy).rgb;
|
||||
vec3 c01 = texture(MMJ_BlurPass_V, TEX2.xy).rgb;
|
||||
vec3 c02 = texture(MMJ_BlurPass_V, TEX3.zy).rgb;
|
||||
vec3 c03 = texture(MMJ_BlurPass_V, TEX1.xy).rgb;
|
||||
vec3 c04 = texture(MMJ_BlurPass_V, TEX0.xy).rgb;
|
||||
vec3 c05 = texture(MMJ_BlurPass_V, TEX1.zw).rgb;
|
||||
vec3 c06 = texture(MMJ_BlurPass_V, TEX3.xw).rgb;
|
||||
vec3 c07 = texture(MMJ_BlurPass_V, TEX2.zw).rgb;
|
||||
vec3 c08 = texture(MMJ_BlurPass_V, TEX3.zw).rgb;
|
||||
vec3 c09 = texture(MMJ_BlurPass_V, TEX4.xy).rgb;
|
||||
vec3 c10 = texture(MMJ_BlurPass_V, TEX4.zw).rgb;
|
||||
vec3 c11 = texture(MMJ_BlurPass_V, TEX5.xy).rgb;
|
||||
vec3 c12 = texture(MMJ_BlurPass_V, TEX5.zw).rgb;
|
||||
|
||||
vec3 cNew = (c00 + c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 + c11 + c12) / 13.0;
|
||||
|
||||
vec3 o = vec3(1.0), h = vec3(0.05), hz = h;
|
||||
float k = 0.005, kz = 0.007, i = 0.0;
|
||||
|
||||
vec3 cz = (cNew + h) / (dot(o, cNew) + k);
|
||||
|
||||
hz = (cz - ((c00 + h) / (dot(o, c00) + k))); i = kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c01 + h) / (dot(o, c01) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c02 + h) / (dot(o, c02) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c03 + h) / (dot(o, c03) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c05 + h) / (dot(o, c05) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c06 + h) / (dot(o, c06) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c07 + h) / (dot(o, c07) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c08 + h) / (dot(o, c08) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c09 + h) / (dot(o, c09) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c10 + h) / (dot(o, c10) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c11 + h) / (dot(o, c11) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
hz = (cz - ((c12 + h) / (dot(o, c12) + k))); i += kz / (dot(hz, hz) + kz);
|
||||
|
||||
i /= 12.0;
|
||||
i = pow(i, OutlineWeight);
|
||||
|
||||
FragColor.rgb = vec3(i);
|
||||
}
|
Loading…
Reference in a new issue