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.

카테고리:tutorials

Tagged as: ,

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Google photo

Google의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Twitter 사진

Twitter의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

%s에 연결하는 중