Skip to content

Commit

Permalink
Update shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Oct 2, 2024
1 parent d5bf710 commit 5afa08f
Show file tree
Hide file tree
Showing 35 changed files with 107 additions and 123 deletions.
1 change: 1 addition & 0 deletions armorpaint/shaders/dilate_map.frag.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#version 450

in float dummy;
out float frag_color;

void main() {
Expand Down
1 change: 1 addition & 0 deletions armorpaint/shaders/dilate_map.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
in vec4 pos;
in vec2 nor;
in vec2 tex;
out float dummy;

void main() {
#if defined(HLSL) || defined(METAL) || defined(SPIRV)
Expand Down
4 changes: 2 additions & 2 deletions armorpaint/shaders/dilate_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ uniform float dilate_radius;
in vec2 tex_coord;
out vec4 frag_color;

const vec2 offsets[8] = vec2[] (
const vec2 offsets[8] = {
vec2(-1, 0),
vec2( 1, 0),
vec2( 0, 1),
Expand All @@ -16,7 +16,7 @@ const vec2 offsets[8] = vec2[] (
vec2( 1, 1),
vec2( 1,-1),
vec2(-1,-1)
);
};

void main() {
// Based on https://shaderbits.com/blog/uv-dilation by Ryan Brucks
Expand Down
2 changes: 1 addition & 1 deletion armorpaint/shaders/layer_invert.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ in vec4 color;
out vec4 frag_color;

void main() {
frag_color = vec4(1.0) - textureLod(tex, tex_coord, 0).rgba * color;
frag_color = vec4(1.0, 1.0, 1.0, 1.0) - textureLod(tex, tex_coord, 0).rgba * color;
}
2 changes: 1 addition & 1 deletion armorpaint/shaders/mask_colorid.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ out vec4 frag_color;
void main() {
vec3 colorid_c1 = texelFetch(texpaint_colorid, ivec2(0, 0), 0).rgb;
vec3 colorid_c2 = textureLod(texcolorid, tex_coord, 0).rgb;
if (colorid_c1 != colorid_c2) discard;
if (colorid_c1.x != colorid_c2.x || colorid_c1.y != colorid_c2.y || colorid_c1.z != colorid_c2.z) discard;
frag_color = vec4(1.0, 1.0, 1.0, 1.0);
}
6 changes: 3 additions & 3 deletions armorpaint/shaders/mesh_posnor.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ out vec4 prevwvpposition;

void main() {
vec4 spos = vec4(pos.xyz, 1.0);
wnormal = normalize(N * vec3(nor.xy, pos.w));
gl_Position = WVP * spos;
wnormal = normalize(mul(vec3(nor.xy, pos.w), N));
gl_Position = mul(spos, WVP);
wvpposition = gl_Position;
prevwvpposition = prevWVP * spos;
prevwvpposition = mul(spos, prevWVP);
}
2 changes: 1 addition & 1 deletion armorsculpt/shaders/layer_invert.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ in vec4 color;
out vec4 frag_color;

void main() {
frag_color = vec4(1.0) - textureLod(tex, tex_coord, 0).rgba * color;
frag_color = vec4(1.0, 1.0, 1.0, 1.0) - textureLod(tex, tex_coord, 0).rgba * color;
}
6 changes: 3 additions & 3 deletions armorsculpt/shaders/mesh_posnor.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ out vec4 prevwvpposition;

void main() {
vec4 spos = vec4(pos.xyz, 1.0);
wnormal = normalize(N * vec3(nor.xy, pos.w));
gl_Position = WVP * spos;
wnormal = normalize(mul(vec3(nor.xy, pos.w), N));
gl_Position = mul(spos, WVP);
wvpposition = gl_Position;
prevwvpposition = prevWVP * spos;
prevwvpposition = mul(spos, prevWVP);
}
2 changes: 1 addition & 1 deletion base/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ if (flags.voxels) {
project.add_define("arm_voxels");

if (os_platform() === "win32") {
project.add_shaders("shaders/voxel_hlsl/*.glsl", { noprocessing: true });
project.add_assets("shaders/voxel_hlsl/*.d3d11", { destination: "data/{name}" });
}
else {
project.add_shaders("shaders/voxel_glsl/*.glsl");
Expand Down
5 changes: 3 additions & 2 deletions base/shaders/compositor_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ out vec4 frag_color;

// Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
vec3 tonemap_filmic(const vec3 color) {
vec3 x = max(vec3(0.0), color - 0.004);
vec3 x = max(vec3(0.0, 0.0, 0.0), color - 0.004);
return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
}

Expand All @@ -19,7 +19,8 @@ void main() {

// Static grain
float x = (tex_coord.x + 4.0) * (tex_coord.y + 4.0) * 10.0;
frag_color.rgb += vec3(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01) - 0.005) * grain_strength;
float g = mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01) - 0.005;
frag_color.rgb += vec3(g, g, g) * grain_strength;

frag_color.rgb *= (1.0 - vignette_strength) + vignette_strength * pow(16.0 * tex_coord.x * tex_coord.y * (1.0 - tex_coord.x) * (1.0 - tex_coord.y), 0.2);

Expand Down
7 changes: 4 additions & 3 deletions base/shaders/cursor.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ uniform float radius;
uniform vec3 camera_right;
uniform sampler2D gbufferD;
#ifdef HLSL
uniform sampler2D texa; // direct3d12 unit align
// direct3d12 unit align
uniform sampler2D texa;
#endif

in vec4 pos;
Expand All @@ -27,7 +28,7 @@ vec3 get_pos(vec2 uv) {
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;
wpos = mul(wpos, invVP);
return wpos.xyz / wpos.w;
}

Expand Down Expand Up @@ -61,5 +62,5 @@ void main() {
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;
gl_Position = VP * vec4(wpos, 1.0);
gl_Position = mul(vec4(wpos, 1.0), VP);
}
2 changes: 1 addition & 1 deletion base/shaders/layer_view.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ out vec2 tex_coord;
out vec4 color;

void main() {
gl_Position = P * vec4(pos, 1.0);
gl_Position = mul(vec4(pos, 1.0), P);
tex_coord = tex;
color = col;
}
2 changes: 1 addition & 1 deletion base/shaders/line.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ out vec3 color;

void main() {
color = col;
gl_Position = VP * vec4(pos, 1.0);
gl_Position = mul(vec4(pos, 1.0), VP);
}
2 changes: 1 addition & 1 deletion base/shaders/mesh_poscol.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ out vec4 frag_color;

void main() {
frag_color = vec4(vcolor, 1.0);
frag_color.rgb = pow(frag_color.rgb, vec3(1.0 / 2.2));
frag_color.rgb = pow(frag_color.rgb, vec3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2));
}
2 changes: 1 addition & 1 deletion base/shaders/mesh_poscol.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ out vec3 vcolor;
void main() {
vec4 spos = vec4(pos.xyz, 1.0);
vcolor = col.rgb;
gl_Position = WVP * spos;
gl_Position = mul(spos, WVP);
}
6 changes: 3 additions & 3 deletions base/shaders/mesh_posnortex.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ out vec4 prevwvpposition;
void main() {
vec4 spos = vec4(pos.xyz, 1.0);
tex_coord = tex * tex_unpack;
wnormal = normalize(N * vec3(nor.xy, pos.w));
gl_Position = WVP * spos;
wnormal = normalize(mul(vec3(nor.xy, pos.w), N));
gl_Position = mul(spos, WVP);
wvpposition = gl_Position;
prevwvpposition = prevWVP * spos;
prevwvpposition = mul(spos, prevWVP);
}
2 changes: 1 addition & 1 deletion base/shaders/pass_viewray.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {

// NDC (at the back of cube)
vec4 v = vec4(pos.x, pos.y, 1.0, 1.0);
v = vec4(invVP * v);
v = vec4(mul(v, invVP));
v.xyz /= v.w;
view_ray = v.xyz - eye;
}
2 changes: 1 addition & 1 deletion base/shaders/pass_viewray2.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ void main() {

// NDC (at the back of cube)
vec4 v = vec4(pos.x, pos.y, 1.0, 1.0);
v = vec4(invP * v);
v = vec4(mul(v, invP));
view_ray = vec3(v.xy / v.z, 1.0);
}
4 changes: 2 additions & 2 deletions base/shaders/prefilter_envmap.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ float rand(vec2 co) {

vec2 equirect(vec3 normal) {
float phi = acos(normal.z);
float theta = atan(-normal.y, normal.x) + PI;
float theta = atan2(normal.x, -normal.y) + PI;
return vec2(theta / PI2, phi / PI);
}

Expand Down Expand Up @@ -50,5 +50,5 @@ void main() {
frag_color.rgb += texture(radiance, equirect(dir)).rgb;
}
frag_color.rgb /= float(samples);
frag_color.rgb = pow(frag_color.rgb, vec3(1.0 / 2.2));
frag_color.rgb = pow(frag_color.rgb, vec3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2));
}
41 changes: 4 additions & 37 deletions base/shaders/smaa_blend_weight.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,19 @@ out vec4 frag_color;
// Blending Weight Calculation Pixel Shader (Second Pass)
vec2 cdw_end;

vec4 textureLod_a(sampler2D tex, vec2 coord, float lod) {
vec4 textureLod_a(sampler2D edges_tex, vec2 coord, float lod) {
#if defined(HLSL) || defined(METAL) || defined(SPIRV)
coord.y = 1.0 - coord.y;
#endif
return textureLod(tex, coord, lod);
return textureLod(edges_tex, coord, lod);
}

#define smaa_sample_level_zero_offset(tex, coord, offset) textureLod_a(tex, coord + offset * screen_size_inv.xy, 0.0)
#define smaa_sample_level_zero_offset(edges_tex, coord, offset) textureLod_a(edges_tex, coord + offset * screen_size_inv.xy, 0.0)

//-----------------------------------------------------------------------------
// Diagonal Search Functions

// #if !defined(SMAA_DISABLE_DIAG_DETECTION)
/**
* Allows to decode two binary values from a bilinear-filtered access.
*/
vec2 smaa_decode_diag_bilinear_access(vec2 e) {
// Bilinear access for fetching 'e' have a 0.25 offset, and we are
// interested in the R and G edges:
Expand All @@ -70,9 +67,6 @@ vec4 smaa_decode_diag_bilinear_access(vec4 e) {
return round(e);
}

/**
* These functions allows to perform diagonal pattern searches.
*/
vec2 smaa_search_diag1(vec2 texcoord, vec2 dir/*, out vec2 e*/) {
vec4 coord = vec4(texcoord, -1.0, 1.0);
vec3 t = vec3(screen_size_inv.xy, 1.0);
Expand Down Expand Up @@ -100,10 +94,6 @@ vec2 smaa_search_diag2(vec2 texcoord, vec2 dir) {
return coord.zw;
}

/**
* Similar to smaa_area, this calculates the area corresponding to a certain
* diagonal distance and crossing edges 'e'.
*/
vec2 smaa_area_diag(vec2 dist, vec2 e, float offset) {
vec2 texcoord = mad(vec2(SMAA_AREATEX_MAX_DISTANCE_DIAG, SMAA_AREATEX_MAX_DISTANCE_DIAG), e, dist);

Expand All @@ -120,9 +110,6 @@ vec2 smaa_area_diag(vec2 dist, vec2 e, float offset) {
return SMAA_AREATEX_SELECT(textureLod(area_tex, texcoord, 0.0));
}

/**
* This searches for diagonal patterns and returns the corresponding weights.
*/
vec2 smaa_calculate_diag_weights(vec2 texcoord, vec2 e, vec4 subsample_indices) {
vec2 weights = vec2(0.0, 0.0);

Expand Down Expand Up @@ -201,12 +188,6 @@ vec2 smaa_calculate_diag_weights(vec2 texcoord, vec2 e, vec4 subsample_indices)
//-----------------------------------------------------------------------------
// Horizontal/Vertical Search Functions

/**
* This allows to determine how much length should we add in the last step
* of the searches. It takes the bilinearly interpolated edge (see
* @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and
* crossing edges are active.
*/
float smaa_search_length(vec2 e, float offset) {
// The texture is flipped vertically, with left and right cases taking half
// of the space horizontally:
Expand All @@ -228,17 +209,7 @@ float smaa_search_length(vec2 e, float offset) {
return SMAA_SEARCHTEX_SELECT(textureLod(search_tex, coord, 0.0));
}

/**
* Horizontal/vertical search functions for the 2nd pass.
*/
float smaa_search_x_left(vec2 texcoord, float end) {
/**
* @PSEUDO_GATHER4
* This texcoord has been offset by (-0.25, -0.125) in the vertex shader to
* sample between edge, thus fetching four edges in a row.
* Sampling with different offsets in each direction allows to disambiguate
* which edges are active from the four fetched ones.
*/
vec2 e = vec2(0.0, 1.0);
while (texcoord.x > end &&
e.g > 0.8281 && // Is there some edge not activated?
Expand Down Expand Up @@ -288,10 +259,6 @@ float smaa_search_y_down(vec2 texcoord, float end) {
return mad(-screen_size_inv.y, offset, texcoord.y);
}

/**
* Ok, we have the distance and both crossing edges. So, what are the areas
* at each side of current edge?
*/
vec2 smaa_area(vec2 dist, float e1, float e2, float offset) {
// Rounding prevents precision errors of bilinear filtering:
vec2 texcoord = mad(vec2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE), round(4.0 * vec2(e1, e2)), dist);
Expand Down Expand Up @@ -447,5 +414,5 @@ vec4 smaa_blending_weight_calculation_ps(vec2 texcoord, vec2 pixcoord, vec4 subs
}

void main() {
frag_color = smaa_blending_weight_calculation_ps(tex_coord, pixcoord, vec4(0.0));
frag_color = smaa_blending_weight_calculation_ps(tex_coord, pixcoord, vec4(0.0, 0.0, 0.0, 0.0));
}
21 changes: 14 additions & 7 deletions base/shaders/smaa_neighborhood_blend.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ out vec4 frag_color;
//-----------------------------------------------------------------------------
// Neighborhood Blending Pixel Shader (Third Pass)

vec4 textureLodA(sampler2D tex, vec2 coords, float lod) {
vec4 textureLodA_color_tex(sampler2D color_tex, vec2 coords, float lod) {
#if defined(HLSL) || defined(METAL) || defined(SPIRV)
coords.y = 1.0 - coords.y;
#endif
return textureLod(tex, coords, lod);
return textureLod(color_tex, coords, lod);
}

vec4 textureLodA_sveloc(sampler2D sveloc, vec2 coords, float lod) {
#if defined(HLSL) || defined(METAL) || defined(SPIRV)
coords.y = 1.0 - coords.y;
#endif
return textureLod(sveloc, coords, lod);
}

vec4 smaa_neighborhood_blending_ps(vec2 texcoord, vec4 offset) {
Expand Down Expand Up @@ -70,20 +77,20 @@ vec4 smaa_neighborhood_blending_ps(vec2 texcoord, vec4 offset) {

// We exploit bilinear filtering to mix current pixel with the chosen
// neighbor:
vec4 color = blending_weight.x * textureLodA(color_tex, blending_coord.xy, 0.0);
color += blending_weight.y * textureLodA(color_tex, blending_coord.zw, 0.0);
vec4 color = blending_weight.x * textureLodA_color_tex(color_tex, blending_coord.xy, 0.0);
color += blending_weight.y * textureLodA_color_tex(color_tex, blending_coord.zw, 0.0);

#ifdef _Veloc
// Antialias velocity for proper reprojection in a later stage:
vec2 velocity = blending_weight.x * textureLodA(sveloc, blending_coord.xy, 0.0).rg;
velocity += blending_weight.y * textureLodA(sveloc, blending_coord.zw, 0.0).rg;
vec2 velocity = blending_weight.x * textureLodA_sveloc(sveloc, blending_coord.xy, 0.0).rg;
velocity += blending_weight.y * textureLodA_sveloc(sveloc, blending_coord.zw, 0.0).rg;

// Pack velocity into the alpha channel:
color.a = sqrt(5.0 * length(velocity));
#endif
return color;
}
return vec4(0.0);
return vec4(0.0, 0.0, 0.0, 0.0);
}

void main() {
Expand Down
2 changes: 1 addition & 1 deletion base/shaders/ssao_blur_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ uniform vec2 dir_inv;
in vec2 tex_coord;
out float frag_color;

const float blur_weights[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535);
const float blur_weights[10] = { 0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535 };
const float discard_threshold = 0.95;

void main() {
Expand Down
Loading

0 comments on commit 5afa08f

Please sign in to comment.