Substance Painter Shader Guide part 3. – Adding to Gaussian Blur9

Summary.

What you’re practicing in this post may be helpful when implementing a skin shader in the next.
The goal is to understand the depth of each content by first implementing it individually rather than connecting all the function implementations. .
Again, use pbr-metal-roughness.glsl, open the shader code and add the bool variable as shown below.

//-------- BLur --------------------------------------------//
//: param custom { "default": false, "label": "Blur" }
uniform bool b_blur;

The b_blur variable will work in pairs with //: param custom {“default”: false, “label”: “blur”}.

For the Blur function to be used in this exercise, refer to the link below.

https://github.com/Jam3/glsl-fast-gaussian-blur?fbclid=IwAR3sqv_wuC4TLNHTdcEnI88WylOIIpFZIyYGtTizmN90oqeiwQDaR3wlu9Y

vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
  vec4 color = vec4(0.0);
  vec2 off1 = vec2(1.3846153846) * direction;
  vec2 off2 = vec2(3.2307692308) * direction;
  color += texture2D(image, uv) * 0.2270270270;
  color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;
  color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;
  color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;
  color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
  return color;
}

Let’s modify the above reference code to fit the Substance Painter API. Let’s take a look at the documentation to reference the internal API.

1. Sparse API
file:///C:/Program%20Files/Allegorithmic/Substance%20Painter/resources/shader-doc/lib-sparse.html

2. Sampler API
file:///C:/Program%20Files/Allegorithmic/Substance%20Painter/resources/shader-doc/lib-sampler.html

//blur9 function here
vec4 blur9( SamplerSparse image , SparseCoord uv, vec2 resolution, vec2 direction) 
{
  vec4 color = vec4(0.0);
  vec2 off1 = vec2(1.3846153846) * direction;
  vec2 off2 = vec2(3.2307692308) * direction;

  color += getBaseColor(image, uv) * 0.2270270270;
  uv +=(off1 / resolution);
  color += getBaseColor(image, uv) * 0.3162162162;
  uv -=(off1 / resolution);
  color += getBaseColor(image, uv) * 0.3162162162;
  uv +=(off2 / resolution);
  color += getBaseColor(image, uv) * 0.0702702703;
  uv-=(off2 / resolution);
  color += getBaseColor(image, uv) * 0.0702702703;
  return color;
}

Now that we have the proper function, let’s apply it to Albedo.

Categories: tutorials

Tagged as: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s