Edit in GitHubLog an issue

Basic pixelating shader


Import from libraries.

Copied to your clipboard
import lib-sampler.glsl

We define the global light position

Copied to your clipboard
const vec3 light_pos = vec3(10.0, 10.0, 10.0);

We bind the auto param world eye position to our uniform camera_pos.

Copied to your clipboard
//: param auto world_eye_position
uniform vec3 camera_pos;

We bind the document's channel base color to our uniform basecolor_tex.

Copied to your clipboard
//: param auto channel_basecolor
uniform SamplerSparse basecolor_tex;

We define a new custom tweak for this shader, along with its default value. This one is used to tweak the thickness of outline, when shadowed.

Copied to your clipboard
//: param custom {
//: "default": 0.4,
//: "min": 0.0,
//: "max": 1.0,
//: "label": "Unlit outline thickness"
//: }
uniform float unlit_outline_thickness;

We define a new custom tweak for this shader, along with its default value. This one is used to tweak the thickness of outline, when lit.

Copied to your clipboard
//: param custom {
//: "default": 0.1,
//: "min": 0.0,
//: "max": 1.0,
//: "label": "Lit outline thickness"
//: }
uniform float lit_outline_thickness;

Entry point of the shader.

Copied to your clipboard
void shade(V2F inputs)
{

We compute a few useful values.

Copied to your clipboard
vec3 V = normalize(camera_pos - inputs.position);
vec3 N = normalize(inputs.normal);
vec3 L = normalize(light_pos - inputs.position);
float NdV = dot(N, V);
float NdL = max(0.0, dot(N, L));

Priority is to performs the outline detection. If outline condition is reach, exit with black color.

Copied to your clipboard
if (NdV < mix(unlit_outline_thickness, lit_outline_thickness, NdL)) {
return;
}
vec3 baseColor = getBaseColor(basecolor_tex, inputs.sparse_coord);

Introduce some jitter to mask size, based on base color luminance

Copied to your clipboard
float maskRadiusJitter = pow(dot(baseColor, vec3(0.3333)), 0.1);

Compute a mask value, based on screen space position of fragment. This will create a grid like pattern.

Copied to your clipboard
float mask = pow(1.0 - length(fract(gl_FragCoord.xy / 7.0) - vec2(0.5)), maskRadiusJitter * 5.0) * 5.0;

Here, we sample the base color and apply a simple diffuse attenuation

Copied to your clipboard
vec3 color = baseColor * NdL;
diffuseShadingOutput(mask * color);
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.