This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

character / tests / cubism-probe / addons / gd_cubism / res / shader / cubism_mask.gdshaderinc
1.1 kB 47 lines
1// masking 2instance uniform bool has_mask = false; 3instance uniform bool invert; 4uniform sampler2D tex_mask : filter_linear_mipmap, repeat_disable; 5uniform float mask_scale = 1.0; 6uniform vec2 canvas_size = vec2(2,2); 7uniform vec2 mesh_offset = vec2(0,0); 8 9varying vec2 MASK_UV; 10varying vec4 modulate; 11 12bool discard_mask() { 13 if(has_mask) { 14 if (MASK_UV.x > 1.0 || MASK_UV.y > 1.0 || MASK_UV.x < 0.0 || MASK_UV.y < 0.0) { 15 return true; 16 } 17 } 18 return false; 19} 20 21vec2 mask_uv(vec2 vtx) { 22 if (!has_mask) { 23 return vec2(0,0); 24 } 25 26 vec2 mask_size = vec2(textureSize(tex_mask, 0)) / mask_scale; 27 vec2 mask_vtx = vtx - mesh_offset; 28 return mask_vtx / mask_size; 29} 30 31vec4 sample_mask(vec4 color_tex, vec4 base) { 32 vec4 color_for_mask = color_tex * base; 33 color_for_mask.rgb = color_for_mask.rgb * color_for_mask.a; 34 35 vec4 clip_mask = texture(tex_mask, MASK_UV) * vec4(0,0,0,1); 36 37 float mask_val = clip_mask.r + clip_mask.g + clip_mask.b + clip_mask.a; 38 if (invert) { 39 mask_val = 1.0 - mask_val; 40 } 41 return color_for_mask * mask_val; 42} 43 44void vertex() { 45 MASK_UV = mask_uv(VERTEX.xy); 46 modulate = COLOR; 47}