Fix dilate pass for vulkan
This commit is contained in:
@@ -61,6 +61,31 @@ fun dilate_pass_vert(input: vert_in): vert_out {
|
||||
return output;
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
fun nested_if_if(cur_uv: float2, i: int, j: int, texel_size: float2, offset_col: float4): float4 {
|
||||
var color: float4;
|
||||
var project_uv: float2 = cur_uv + get_offset(j) * texel_size * float2(float(i), float(i)) * float2(0.25, 0.25);
|
||||
var direction: float4 = sample_lod(tex, sampler_linear, project_uv, 0.0);
|
||||
if (direction.x != 0.0 || direction.y != 0.0 || direction.z != 0.0) {
|
||||
var delta: float4 = offset_col - direction;
|
||||
color = offset_col + delta * float4(4.0, 4.0, 4.0, 4.0);
|
||||
}
|
||||
else {
|
||||
color = offset_col;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
fun nested_if(color: float4, cur_dist: float, min_dist: float, cur_uv: float2, i: int, j: int, texel_size: float2, offset_col: float4): float4 {
|
||||
if (cur_dist == min_dist) {
|
||||
color = nested_if_if(cur_uv, i, j, texel_size, offset_col);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
fun dilate_pass_frag(input: vert_out): float4 {
|
||||
// Based on https://shaderbits.com/blog/uv-dilation by Ryan Brucks
|
||||
var texel_size: float2 = float2(1.0, 1.0) / constants.tex_size;
|
||||
@@ -77,8 +102,7 @@ fun dilate_pass_frag(input: vert_out): float4 {
|
||||
|
||||
var color: float4 = tex[coord];
|
||||
|
||||
////
|
||||
|
||||
/*
|
||||
var i: int = 0;
|
||||
while (i < int(constants.dilate_radius)) {
|
||||
i += 1;
|
||||
@@ -107,6 +131,29 @@ fun dilate_pass_frag(input: vert_out): float4 {
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
////
|
||||
|
||||
var i: int = 0;
|
||||
while (i < int(constants.dilate_radius)) {
|
||||
i += 1;
|
||||
var j: int = 0;
|
||||
while (j < 8) {
|
||||
var cur_uv: float2 = input.tex + get_offset(j) * texel_size * float2(float(i), float(i));
|
||||
coordf = cur_uv * constants.tex_size;
|
||||
coord = uint2(uint(coordf.x), uint(coordf.y));
|
||||
var offset_mask4: float4 = texdilate[coord];
|
||||
var offset_mask: float = offset_mask4.r;
|
||||
var offset_col: float4 = tex[coord];
|
||||
if (offset_mask != 0.0) {
|
||||
var cur_dist: float = length(input.tex - cur_uv);
|
||||
min_dist = min(cur_dist, min_dist);
|
||||
color = nested_if(color, cur_dist, min_dist, cur_uv, i, j, texel_size, offset_col);
|
||||
}
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user