Godot Version
Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated AMD Radeon RX 5700 XT (Advanced Micro Devices, Inc.; 32.0.11029.1008) - AMD Ryzen 9 3900X 12-Core Processor (24 Threads)
Question
I’m trying to convert VisualTechArt’s Outline Styalize Material (and part 2) from Unreal into Godot shader. The shader creates outline with different brush strokes.
I’m lost in translation. The background turns black. By playing around with the numbers I can see some shapes, but they seem to be inverted, they move opposite direction of the camera.
I think I’ve chosen the wrong UVs. Might be an issue with Unreal and Godot measurement as well. I attached two screenshots from part 2 of his video.
shader_type spatial;
//render_mode unshaded;
uniform float KERNEL_SIZE: hint_range(1.0, 15.0, 1.0) = 15.0;
uniform float ROTATION_ALPHA = 2.5;
uniform float SHAPE_RATIO = 1.6;
uniform sampler2D DEPTH_TEXTURE : hint_depth_texture, filter_linear, repeat_disable;
uniform sampler2D NORMR_TEXTURE : hint_normal_roughness_texture, filter_linear, repeat_disable;
void vertex() {
POSITION = vec4(VERTEX, 1.0);
}
void fragment() {
vec2 KernelUVs = UV; // don't know if it's UV;
vec2 TexelSize = SCREEN_UV; // don't know if it's SCREEN_UV
vec2 PixelUVs;
vec2 RotationVector = vec2(cos(ROTATION_ALPHA), sin(ROTATION_ALPHA));
vec3 LaplacianFilter_Normal = vec3(0.0);
float LaplacianFilter_Depth = 0.0;
float CenterWeight = 0.0;
float HALF_KERNEL_SIZE = floor(KERNEL_SIZE / 2.0);
float HALF_KERNEL_SIZE_SQ = KERNEL_SIZE * KERNEL_SIZE / 4.0;
for(float y = -HALF_KERNEL_SIZE; y <= HALF_KERNEL_SIZE; y++)
{
for(float x = -HALF_KERNEL_SIZE; x <= HALF_KERNEL_SIZE; x++)
{
vec2 MarkerPoint = vec2(dot(RotationVector, vec2(x,y)), dot(RotationVector, vec2(y,-x)));
if(dot(MarkerPoint, MarkerPoint) > HALF_KERNEL_SIZE_SQ)
{
continue;
}
CenterWeight++;
PixelUVs = KernelUVs + TexelSize * vec2(x, y);
LaplacianFilter_Normal -= texture(NORMR_TEXTURE, PixelUVs).rgb;
LaplacianFilter_Depth -= texture(DEPTH_TEXTURE, PixelUVs).r;
}
}
LaplacianFilter_Normal += texture(NORMR_TEXTURE, KernelUVs).rgb * CenterWeight;
LaplacianFilter_Depth += texture(DEPTH_TEXTURE, KernelUVs).r * CenterWeight;
CenterWeight--;
CenterWeight = 1.0 / CenterWeight;
LaplacianFilter_Normal *= CenterWeight;
LaplacianFilter_Depth *= CenterWeight;
float normal_alpha = max(LaplacianFilter_Normal.r, max(LaplacianFilter_Normal.g, LaplacianFilter_Normal.b));
float normal_outline = mix(0.15, 0.2, normal_alpha);
float depth_outline = mix(2.0,10.0,LaplacianFilter_Depth);
float combined_outline = 1.0 - max(normal_outline, depth_outline);
EMISSION = vec3(combined_outline);
//ALBEDO = vec3(combined_outline);
}
VisualTechArt original Unreal code: